Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaykv committed Jan 23, 2025
1 parent b78dc14 commit b48bb64
Show file tree
Hide file tree
Showing 12 changed files with 1,283 additions and 21 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ sync:
uv sync --all-extras --group dev --group docs

test:
uv run coverage run -m pytest -vv --capture=tee-sys -n auto
@uv run coverage report
uv run pytest --cov -vv --capture=tee-sys -n auto

clean:
rm -rf build/ dist/ *.egg-info .*_cache test-builds test-manifest-builds
Expand Down
1 change: 1 addition & 0 deletions cliffy/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def delete_temp_files() -> None:
with contextlib.suppress(Exception):
file.close()
os.unlink(file.name)
TEMP_FILES.clear()


def indent_block(block: str, spaces: int = 4) -> str:
Expand Down
2 changes: 1 addition & 1 deletion cliffy/homer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_metadata_bypath(path: Path) -> CLIMetadata:
except Exception as e:
return CLIMetadata(
cli_name=path.name,
runner_path=path.absolute().name,
runner_path=str(path.absolute()),
version="error",
loaded=datetime.now(),
manifest=f"could not load: {e}",
Expand Down
18 changes: 11 additions & 7 deletions cliffy/reloader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .transformer import Transformer
from .loader import Loader
from .homer import save_metadata
from .helper import out
from .helper import out, out_err
from .builder import run_cli as cli_runner

import time
Expand All @@ -13,7 +13,7 @@


class Reloader(FileSystemEventHandler):
def __init__(self, manifest_path: str, run_cli: bool, run_cli_args: tuple[str]) -> None:
def __init__(self, manifest_path: str, run_cli: bool, run_cli_args: tuple) -> None:
self.manifest_path = manifest_path
self.run_cli = run_cli
self.run_cli_args = run_cli_args
Expand All @@ -34,11 +34,15 @@ def on_modified(self, event: FileSystemEvent) -> None:
self.last_modified = datetime.now()

t = threading.Thread(target=self.reload, args=(self.manifest_path, self.run_cli, self.run_cli_args))
t.daemon = True
t.start()
t.setDaemon(True)
try:
t.start()
except RuntimeError as e:
# Log the error or handle it as needed
out_err(f"Failed to start thread: {e}")

@classmethod
def watch(cls, manifest_path: str, run_cli: bool, run_cli_args: tuple[str]) -> None:
def watch(cls, manifest_path: str, run_cli: bool, run_cli_args: tuple) -> None:
event_handler = cls(manifest_path, run_cli, run_cli_args)
observer = Observer()
observer.schedule(event_handler, path=str(Path(manifest_path).parent), recursive=False)
Expand All @@ -52,12 +56,12 @@ def watch(cls, manifest_path: str, run_cli: bool, run_cli_args: tuple[str]) -> N
observer.join()

@staticmethod
def reload(manifest_path: str, run_cli: bool, run_cli_args: tuple[str]) -> None:
def reload(manifest_path: str, run_cli: bool, run_cli_args: tuple) -> None:
manifest_io = open(manifest_path, "r")

T = Transformer(manifest_io)
Loader.load_from_cli(T.cli)
save_metadata(manifest_io.name, T.cli)
save_metadata(manifest_path, T.cli)
out(f"✨ Reloaded {T.cli.name} CLI v{T.cli.version} ✨", fg="green")

if run_cli:
Expand Down
8 changes: 4 additions & 4 deletions cliffy/rich.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ def print(self, text: Any, **kwargs: Any) -> None:
print(text)

class Table: # type: ignore[no-redef]
__slots__ = ("cols", "rows", "styles")
__slots__ = ("columns", "rows", "styles")

def __init__(self) -> None:
self.cols: list[str] = []
self.columns: list[str] = []
self.rows: list[list[str]] = []
self.styles: list[str] = []

def add_column(self, col: str, style: str = "") -> None:
self.cols.append(col)
self.columns.append(col)
self.styles.append(style)

def add_row(self, *row: Any) -> None:
self.rows.append([*row])

def __str__(self) -> str:
text = "".join([click.style(f"{col:10}", fg=self.styles.pop(0)) for col in self.cols]) + "\n"
text = "".join([click.style(f"{col:10}", fg=self.styles.pop(0)) for col in self.columns]) + "\n"
for row in self.rows:
for col in row:
text += f"{col:10}"
Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dev = [
"pytest-xdist>=3.6.1",
"ruff>=0.9.1",
"tabulate>=0.9.0",
"coverage[toml]>=7.6.2"
"pytest-cov>=6.0.0"
]


Expand All @@ -58,7 +58,8 @@ dev = [
"pytest-xdist>=3.6.1",
"ruff>=0.9.1",
"tabulate>=0.9.0",
"coverage[toml]>=7.6.2"
"pytest-cov>=6.0.0",
"pytest-mock>=3.14.0",
]
docs = [
"mkdocs-git-committers-plugin-2>=2.4.1",
Expand Down Expand Up @@ -107,7 +108,7 @@ ignore_missing_imports = true
# https://coverage.readthedocs.io/en/latest/config.html#run
[tool.coverage.run]
include = ["cliffy/**/*.py"]
omit = []
omit = ["cliffy/clis/**"]
branch = true

# https://coverage.readthedocs.io/en/latest/config.html#report
Expand All @@ -131,4 +132,4 @@ exclude_lines = [
]

[tool.uv]
default-groups = ["dev", "docs", "extras"]
default-groups = ["dev", "docs", "extras"]
Loading

0 comments on commit b48bb64

Please sign in to comment.