-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
240 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
run: | ||
python src/ruff_in_python/main.py | ||
python src/ruff_in_python/main.py | ||
|
||
lint: | ||
ruff check . --fix & ruff format . | ||
install: | ||
pip install -e . | ||
|
||
test: | ||
pytest -vv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
 |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
def main(name: str): | ||
print(f"Hello {name}") | ||
import logging | ||
from rich.logging import RichHandler | ||
|
||
logger = logging.getLogger() | ||
|
||
logging.basicConfig( | ||
level="NOTSET", | ||
format="%(message)s", | ||
datefmt="[%X]", | ||
handlers=[RichHandler(rich_tracebacks=True)], | ||
) | ||
|
||
|
||
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") | ||
|
||
|
||
def run_once(filepath: str = None): | ||
logger.info("run once") | ||
logger.info("Identified files to lint in") | ||
logger.info("Checked files in ") | ||
logger.info("Found TODO errors") | ||
errors = [] | ||
for error in errors: | ||
logger.warning(error) | ||
|
||
|
||
if __name__ == "__main__": | ||
main("dummy") | ||
main("dummy") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import ast | ||
from pathlib import Path | ||
|
||
|
||
def pretty_print_ast(self): | ||
# Monkeypatch so it's easier to visualise the ast module | ||
return ast.dump(self, indent=2) | ||
|
||
|
||
ast.Module.__repr__ = pretty_print_ast | ||
|
||
|
||
def parse(path: Path): | ||
with open(path) as f: | ||
return ast.parse(f.read()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import ast" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"stmt = \"print(123)\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"parsed = ast.parse(stmt)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 12, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Module(\n", | ||
" body=[\n", | ||
" Expr(\n", | ||
" value=Call(\n", | ||
" func=Name(id='print', ctx=Load()),\n", | ||
" args=[\n", | ||
" Constant(value=123)],\n", | ||
" keywords=[]))],\n", | ||
" type_ignores=[])\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(ast.dump(parsed, indent=2))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"This works fine, but it's easier to make a pretty print function to avoid doing this everytime. Actually, in Python I can just monkeypatch the class to do this." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"ast.Module" | ||
] | ||
}, | ||
"execution_count": 13, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"type(parsed)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 14, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def pretty_print_ast(self):\n", | ||
" return ast.dump(self, indent=2)\n", | ||
"ast.Module.__repr__ = pretty_print_ast" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 15, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"Module(\n", | ||
" body=[\n", | ||
" Expr(\n", | ||
" value=Call(\n", | ||
" func=Name(id='print', ctx=Load()),\n", | ||
" args=[\n", | ||
" Constant(value=123)],\n", | ||
" keywords=[]))],\n", | ||
" type_ignores=[])" | ||
] | ||
}, | ||
"execution_count": 15, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"parsed" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "kedro", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.14" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import ast | ||
from ruff_in_python.parser import parse | ||
|
||
|
||
def test_parser(): | ||
stmt = "print(123)" | ||
res = parse(stmt) | ||
assert isinstance(res, ast.Module) |