diff --git a/pyproject.toml b/pyproject.toml index 31c1ed5..64bf540 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "rapidchecker" -version = "0.1.3" +version = "0.1.4" description = " Grammar and format checker for ABB RAPID code. " readme = "README.md" requires-python = ">=3.10" diff --git a/rapidchecker/cli.py b/rapidchecker/cli.py index 0ddb82b..a232617 100644 --- a/rapidchecker/cli.py +++ b/rapidchecker/cli.py @@ -1,5 +1,4 @@ import sys -from pathlib import Path import click from pyparsing import ParseBaseException @@ -8,14 +7,10 @@ from rapidchecker.whitespace_checks import WhiteSpaceError from .check import check_format +from .io import get_sys_files, read_sys_file from .whitespace_checks import check_whitespace -def read_sys_file(path: str | Path) -> str: - with Path(path).open() as f: - return f.read() - - def check_file(file_contents: str) -> list[ParseBaseException | WhiteSpaceError]: errors: list[ParseBaseException | WhiteSpaceError] = [] errors.extend(check_format(file_contents)) @@ -25,11 +20,11 @@ def check_file(file_contents: str) -> list[ParseBaseException | WhiteSpaceError] @click.command() -@click.argument("paths", nargs=-1, type=click.Path(exists=True, dir_okay=False)) +@click.argument("paths", nargs=-1, type=click.Path(exists=True, dir_okay=True)) def cli(paths: list[str]) -> None: found_errors = False - for filepath in paths: + for filepath in get_sys_files(paths): errors = check_file(read_sys_file(filepath)) if not errors: continue diff --git a/rapidchecker/io.py b/rapidchecker/io.py new file mode 100644 index 0000000..d019140 --- /dev/null +++ b/rapidchecker/io.py @@ -0,0 +1,16 @@ +from collections.abc import Iterable +from pathlib import Path + + +def get_sys_files(paths: list[str]) -> Iterable[Path]: + for path_str in paths: + path = Path(path_str) + if path.is_dir(): + yield from path.glob("**/*.sys") + else: + yield path + + +def read_sys_file(path: str | Path) -> str: + with Path(path).open() as f: + return f.read() diff --git a/uv.lock b/uv.lock index 22e8238..c4bab31 100644 --- a/uv.lock +++ b/uv.lock @@ -286,7 +286,7 @@ wheels = [ [[package]] name = "rapidchecker" -version = "0.1.3" +version = "0.1.4" source = { virtual = "." } dependencies = [ { name = "click" },