Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pyright sanity check #42

Merged
merged 13 commits into from
Nov 20, 2024
42 changes: 42 additions & 0 deletions .github/workflows/sanity.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Sanity

on:
push:
branches:
- main
pull_request:

jobs:
sanity:
runs-on: ubuntu-latest
name: Sanity - ${{ matrix.python-version }}
strategy:
fail-fast: true
matrix:
python-version:
- '3.9'
- '3.12'

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PDM
uses: pdm-project/setup-pdm@v4
with:
version: 2.20.1
python-version: ${{ matrix.python-version }}
cache: true

- name: Install dependencies
run: |
pdm install -v
pdm info
echo "$(pdm venv --path in-project)/bin" >> $GITHUB_PATH

- name: Run pyright
uses: jakebailey/pyright-action@v2
with:
version: 1.1.389
python-version: ${{ matrix.python-version }}
annotate: errors
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Unit tests

on:
push:
bracnhes:
branches:
- main
pull_request:

Expand Down
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
ci:
autoupdate_schedule: quarterly
skip:
# https://github.com/pre-commit-ci/issues/issues/55
- pyright

minimum_pre_commit_version: "2.9.0"
repos:
Expand Down Expand Up @@ -36,6 +39,16 @@ repos:
- https://github.com/rhel-lightspeed/command-line-assistant.git
stages: [manual, pre-push]

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.389
hooks:
- id: pyright
additional_dependencies:
- pyright[nodejs]
- pytest
- requests
- tomli; python_version<"3.11"

- repo: https://github.com/gitleaks/gitleaks
rev: v8.21.2
hooks:
Expand Down
3 changes: 1 addition & 2 deletions command_line_assistant/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def main():

if enforce_script_session and (not args.record or not os.path.exists(output_file)):
parser.error(
f"Please call `{sys.argv[0]} --record` first to initialize script session or create the output file.",
file=sys.stderr,
f"Please call `{sys.argv[0]} --record` first to initialize script session or create the output file."
)

# NOTE: This needs more refinement, script session can't be combined with other arguments
Expand Down
18 changes: 10 additions & 8 deletions command_line_assistant/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
# tomllib is available in the stdlib after Python3.11. Before that, we import
# from tomli.
try:
import tomllib
import tomllib # pyright: ignore[reportMissingImports]
except ImportError:
import tomli as tomllib
import tomli as tomllib # pyright: ignore[reportMissingImports]


CONFIG_DEFAULT_PATH: Path = Path("~/.config/command-line-assistant/config.toml")
Expand Down Expand Up @@ -50,7 +50,9 @@ class LoggingSchema:
"minimal",
)
type: str = "minimal"
file: str | Path = "~/.cache/command-line-assistant/command-line-assistant.log"
file: str | Path = Path( # type: ignore
"~/.cache/command-line-assistant/command-line-assistant.log"
)

def _validate_logging_type(self, type: str):
if type not in self._logging_types:
Expand All @@ -59,33 +61,33 @@ def _validate_logging_type(self, type: str):
)

def __post_init__(self):
self.file = Path(self.file).expanduser()
self.file: Path = Path(self.file).expanduser()


@dataclasses.dataclass
class OutputSchema:
"""This class represents the [output] section of our config.toml file."""

enforce_script: bool = False
file: str | Path = "/tmp/command-line-assistant_output.txt"
file: str | Path = Path("/tmp/command-line-assistant_output.txt") # type: ignore
prompt_separator: str = "$"

def __post_init__(self):
self.file = Path(self.file).expanduser()
self.file: Path = Path(self.file).expanduser()


@dataclasses.dataclass
class HistorySchema:
"""This class represents the [history] section of our config.toml file."""

enabled: bool = True
file: str | Path = (
file: str | Path = Path( # type: ignore
"~/.local/share/command-line-assistant/command-line-assistant_history.json"
)
max_size: int = 100

def __post_init__(self):
self.file = Path(self.file).expanduser()
self.file: Path = Path(self.file).expanduser()


@dataclasses.dataclass
Expand Down
2 changes: 1 addition & 1 deletion command_line_assistant/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from command_line_assistant.config import Config


def handle_history_read(config: Config) -> dict:
def handle_history_read(config: Config) -> list:
"""
Reads the history from a file and returns it as a list of dictionaries.
"""
Expand Down