Skip to content

Commit

Permalink
Automatically recurse folders (#11)
Browse files Browse the repository at this point in the history
* Automatically recurse folders
  • Loading branch information
OdysseasKr authored Nov 21, 2024
1 parent c9037e6 commit 22cddf5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
11 changes: 3 additions & 8 deletions rapidchecker/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
from pathlib import Path

import click
from pyparsing import ParseBaseException
Expand All @@ -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))
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions rapidchecker/io.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 22cddf5

Please sign in to comment.