Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
- name: Black format check
run: black --check .

- name: basedPyright check
run: python -m basedpyright --pythonpath "$(python -c 'import sys; print(sys.executable)')"

test:
name: Test (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dev = [
"black>=23.0.0",
"ruff>=0.0.280",
"build>=1.0.0",
"basedpyright>=1.39.3",
]
rag = [
"chromadb>=0.4.0",
Expand Down Expand Up @@ -78,6 +79,13 @@ python_files = ["test_*.py"]
python_functions = ["test_*"]
addopts = "-v --tb=short"

[tool.basedpyright]
pythonVersion = "3.13"
include = [
"src/pt_snap_cli/cli.py",
"src/pt_snap_cli/__init__.py",
]

[tool.coverage.run]
source = ["pt_snap_cli"]
branch = true
Expand Down
2 changes: 1 addition & 1 deletion src/pt_snap_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

from pt_snap_cli.version import __version__

__all__ = ["__version__", "query"]
__all__ = ["__version__"]
27 changes: 18 additions & 9 deletions src/pt_snap_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

import json
import shlex
from collections.abc import Mapping
from pathlib import Path
from typing import Annotated
from typing import Annotated, NoReturn, cast

import typer

Expand Down Expand Up @@ -51,7 +52,7 @@ def version_callback(value: bool) -> None:

@app.callback()
def main(
version: Annotated[
_: Annotated[
bool | None,
typer.Option("--version", "-v", help="Show version and exit", callback=version_callback),
] = None,
Expand Down Expand Up @@ -117,15 +118,18 @@ def focus_database(
raise typer.Exit()

try:
focus_db_path = db_path
if focus_db_path is None:
raise AssertionError("db_path must be provided when setting focus")
if session:
state = focus_service.validate_session_db(db_path)
state = focus_service.validate_session_db(focus_db_path)
typer.echo(f"export {ENV_DB_PATH}={shlex.quote(str(state.db_path))}")
return
if global_focus:
state = focus_service.set_global_focus(db_path, device)
state = focus_service.set_global_focus(focus_db_path, device)
typer.secho(f"Using global database: {state.db_path}", fg=typer.colors.GREEN)
else:
state = focus_service.set_project_focus(db_path, device)
state = focus_service.set_project_focus(focus_db_path, device)
typer.secho(f"Using project database: {state.db_path}", fg=typer.colors.GREEN)
if state.focus_file:
typer.echo(f"Focus file: {state.focus_file}")
Expand Down Expand Up @@ -207,7 +211,7 @@ def query_database(
}
if category is not None:
filter_cats = [category]
query_service.list_templates(category)
_ = query_service.list_templates(category)
else:
filter_cats = categories
any_found = False
Expand Down Expand Up @@ -289,7 +293,12 @@ def query_database(
_error("--template-use is required when not using --list or --template-info")

try:
query_params = json.loads(params) if params else {}
loaded_params = ( # pyright: ignore[reportUnknownVariableType]
json.loads(params) if params else {}
)
if not isinstance(loaded_params, dict):
raise ValueError("Query parameters must be a JSON object.")
query_params = cast(dict[str, object], loaded_params)
result = query_service.execute_query(
template=template_use,
params=query_params,
Expand Down Expand Up @@ -369,11 +378,11 @@ def show_config(
typer.echo("No configuration set.")
else:
typer.echo("Current configuration:")
for key, value in current_config.items():
for key, value in cast(Mapping[str, object], current_config).items():
typer.echo(f" {key}: {value}")


def _error(message: str) -> None:
def _error(message: str) -> NoReturn:
typer.secho(f"Error: {message}", fg=typer.colors.RED)
raise typer.Exit(1) from None

Expand Down
Loading