Skip to content

Commit

Permalink
Lint with ruff, plus fixed some issues - closes #33
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jun 29, 2023
1 parent f30a4b6 commit 92af5fe
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
- name: Run tests
run: |
pytest
- name: Lint with ruff
run: |
ruff check symbex
- name: Check if cog needs to be run
run: |
cog README.md
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ def get_long_description():
symbex=symbex.cli:cli
""",
install_requires=["click"],
extras_require={"test": ["pytest", "pytest-icdiff", "cogapp", "PyYAML"]},
extras_require={"test": ["pytest", "pytest-icdiff", "cogapp", "PyYAML", "ruff"]},
python_requires=">=3.8",
)
13 changes: 7 additions & 6 deletions symbex/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def cli(
module_dirs.append(mod_path.parent)
else:
module_files.append(mod_path)
except ModuleNotFoundError as ex:
except ModuleNotFoundError:
raise click.ClickException("Module not found: {}".format(module))
directories = [*directories, *module_dirs]
files = [*files, *module_files]
Expand Down Expand Up @@ -318,10 +318,6 @@ def iterate_files():
if path.is_file():
yield path

# Filter symbols by type
def filter(node: ast.AST) -> bool:
return True

# If any --filters were supplied, handle them:
if any(
[
Expand All @@ -337,7 +333,7 @@ def filter(node: ast.AST) -> bool:
no_init,
]
):

# Return just nodes matching filters
def filter(node: ast.AST) -> bool:
# Filters must ALL match
if async_ and not isinstance(node, ast.AsyncFunctionDef):
Expand Down Expand Up @@ -371,6 +367,11 @@ def filter(node: ast.AST) -> bool:
return False
return True

else:
# All nodes are allowed
def filter(node: ast.AST) -> bool:
return True

pwd = pathlib.Path(".").resolve()
num_matches = 0
replace_matches = []
Expand Down
3 changes: 2 additions & 1 deletion symbex/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def add_docstring(definition: str, node: AST, docstrings: bool, is_method: bool)
if not docstring:
return definition
docstring = quoted_string(docstring)
return f"{definition}\n{textwrap.indent(docstring, ' ' if is_method else ' ')}"
wrapped = textwrap.indent(docstring, " " if is_method else " ")
return f"{definition}\n{wrapped}"


def match(name: str, symbols: Iterable[str]) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion tests/example_symbols.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union, Tuple
from typing import Tuple


# Function with no arguments
Expand Down

0 comments on commit 92af5fe

Please sign in to comment.