Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions docs/Coding-Conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -802,20 +802,21 @@ from collections import defaultdict
from contextlib import contextmanager
```

### [O.1.5] ✔️ **DO** Use absolute imports
### [O.1.5] ✔️ **DO** Use absolute imports 💻

> 🐍 This rule stems from [PEP 8](https://www.python.org/dev/peps/pep-0008)

ℹ️ An exception can be made for `__init__.py` files republishing child module declarations
> 💻 This rule is enforced by error code I252

```python
# Bad
# Bad - will produce I252
from . import sibling
from .sibling import rivalry
```

```python
# Good
import my_app.relationships.parents
from my_app.relationships.sibling import rivalry
```

Expand Down Expand Up @@ -869,8 +870,9 @@ import os # Assuming os is never used
```

```python
# Good - assuming we are in a __init__.py file
from .mysubmodule import spam, eggs # OK even if neither are used in this module
# Good - assuming we are in a monty/__init__.py file
from monty import sandwich_shop
from monty.mysubmodule import spam, eggs # OK even if neither are used in this module
```


Expand Down
8 changes: 4 additions & 4 deletions ni_python_styleguide/_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from . import code_analysis # noqa: F401
from . import lint # noqa: F401
from . import string_helpers # noqa: F401
from . import temp_file # noqa: F401
from ni_python_styleguide._utils import code_analysis # noqa: F401
from ni_python_styleguide._utils import lint # noqa: F401
from ni_python_styleguide._utils import string_helpers # noqa: F401
from ni_python_styleguide._utils import temp_file # noqa: F401

DEFAULT_ENCODING = "UTF-8"
2 changes: 2 additions & 0 deletions ni_python_styleguide/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,5 @@ docstring-convention=all

# flake8-import-order
import-order-style=smarkets

ban-relative-imports = True
30 changes: 29 additions & 1 deletion poetry.lock

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

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ isort = ">=5.10"
flake8-black = ">=0.2.1"
flake8-docstrings = ">=1.5.0"
flake8-import-order = ">=0.18.1"
flake8-tidy-imports = [
{version = ">=4.4.1", python = ">=3.7,<3.9"},
{version=">=4.11.0", python="^3.9"},
]
pep8-naming = ">=0.11.1"

# Rejected flake8 plugins should be listed here (in alphabetical order)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@

-x = 5
? ^
+x = 5

+x = 5
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@
+

@click.command()
def _main():

def _main():
4 changes: 3 additions & 1 deletion tests/test_cli/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_given_input_file__produces_expected_output_simple(
output = styleguide_command(command="format")

assert output.exit_code in (True, 0), f"Error in running:\n{output}"
result = test_file.read_text(encoding="UTF-8")
result = test_file.read_text()
snapshot.snapshot_dir = test_dir
snapshot.assert_match(result, "output.py")

Expand All @@ -44,6 +44,8 @@ def test_given_input_file__produces_expected_output_diff(

assert output.exception is None
result = output.stdout.replace(str(test_file), in_file.relative_to(TEST_CASE_DIR).as_posix())
# to make line endings on different platforms consistent
result = result.rstrip()
snapshot.snapshot_dir = test_dir
snapshot.assert_match(result, "output.diff")

Expand Down
4 changes: 3 additions & 1 deletion tests/test_convention_doc/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ def test_rule_documents_enforcement_codes(rule):
if rule.is_automatically_enforced:
assert rule.error_codes is not None
else:
assert rule.error_codes is None
assert (
rule.error_codes is None
), f"Rule ({rule.identifier}) is not marked as automatically enforced, but lists an error code {rule.error_codes}"
Loading