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 1904959 commit da680e3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 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
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,31 +173,31 @@ cog.out(
)
]]] -->
```python
# File: symbex/lib.py Line: 106
# File: symbex/lib.py Line: 107
def function_definition(function_node: AST)
# File: symbex/lib.py Line: 13
def find_symbol_nodes(code: str, filename: str, symbols: Iterable[str]) -> List[Tuple[(AST, Optional[str])]]
# File: symbex/lib.py Line: 174
# File: symbex/lib.py Line: 175
def class_definition(class_def)
# File: symbex/lib.py Line: 208
# File: symbex/lib.py Line: 209
def annotation_definition(annotation: AST) -> str
# File: symbex/lib.py Line: 226
# File: symbex/lib.py Line: 227
def read_file(path)
# File: symbex/lib.py Line: 252
# File: symbex/lib.py Line: 253
class TypeSummary
# File: symbex/lib.py Line: 257
# File: symbex/lib.py Line: 258
def type_summary(node: AST) -> Optional[TypeSummary]
# File: symbex/lib.py Line: 303
# File: symbex/lib.py Line: 304
def quoted_string(s)
# File: symbex/lib.py Line: 314
# File: symbex/lib.py Line: 315
def import_line_for_function(function_name: str, filepath: str, possible_root_dirs: List[str]) -> str
# File: symbex/lib.py Line: 37
Expand All @@ -206,7 +206,7 @@ def code_for_node(code: str, node: AST, class_name: str, signatures: bool, docst
# File: symbex/lib.py Line: 71
def add_docstring(definition: str, node: AST, docstrings: bool, is_method: bool) -> str
# File: symbex/lib.py Line: 81
# File: symbex/lib.py Line: 82
def match(name: str, symbols: Iterable[str]) -> bool
```
<!-- [[[end]]] -->
Expand All @@ -227,7 +227,7 @@ cog.out(
)
]]] -->
```python
# File: symbex/lib.py Line: 81
# File: symbex/lib.py Line: 82
# from symbex.lib import match
def match(name: str, symbols: Iterable[str]) -> bool
```
Expand Down Expand Up @@ -265,7 +265,7 @@ cog.out(
)
]]] -->
```python
# File: symbex/lib.py Line: 81
# File: symbex/lib.py Line: 82
def match(name: str, symbols: Iterable[str]) -> bool
"Returns True if name matches any of the symbols, resolving wildcards"
```
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 da680e3

Please sign in to comment.