Skip to content

Commit

Permalink
add cli
Browse files Browse the repository at this point in the history
  • Loading branch information
noklam committed Feb 4, 2025
1 parent f73288a commit a362539
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
run:
python src/ruff_in_python/main.py
python src/ruff_in_python/main.py tests/bar.py

lint:
ruff check . --fix & ruff format .
Expand Down
45 changes: 29 additions & 16 deletions src/ruff_in_python/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from pathlib import Path
import typer
import logging
from rich.logging import RichHandler
from ruff_in_python.check import check_ast
from ruff_in_python.parser import parse_file
from rich import print

logger = logging.getLogger()

Expand All @@ -11,27 +16,35 @@
)


def main(filepath: str = None):
if not filepath:
filepath = "tests/bar.py"
logger.info(f"flie path: {filepath}")
set_up_logging()
run_once(filepath)


def set_up_logging():
logger.info("dummy: set up logging")
logger.info("Dummy: set up logging")


def run_once(filepath: str = None):
def run_once(filepath: str | Path = None):
filepath = Path(filepath)
logger.info("run once")
logger.info("Identified files to lint in")
logger.info("Checked files in ")
logger.info("Found TODO errors")
errors = []
logger.info(f"Checking {filepath}")
python_ast = parse_file((filepath))
errors = check_ast(filepath, python_ast)
if errors:
logger.info(f"Found {len(errors)} errors")
for error in errors:
logger.warning(error)
logger.warning(error.richify())

logger.info(f"Finished Checking {filepath}")


app = typer.Typer()


@app.command()
def main(filepath: str):
if not filepath:
filepath = "tests/bar.py"
logger.info(f"flie path: {filepath}")
set_up_logging()
run_once(filepath)


if __name__ == "__main__":
main("dummy")
app()

0 comments on commit a362539

Please sign in to comment.