Skip to content

Commit 86f1d0b

Browse files
authored
Configure ruff to check for violation of the dependency rule (#285)
1 parent d684668 commit 86f1d0b

File tree

12 files changed

+185
-133
lines changed

12 files changed

+185
-133
lines changed

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ testpaths = [
134134
[tool.ruff]
135135
target-version = "py39"
136136
line-length = 120
137+
# The `src` settings makes sure that imports are correctly
138+
# evaluated during formatting when using nested `pyproject.toml`
139+
src = [
140+
"src",
141+
]
137142
extend-exclude = [
138143
"docs",
139144
]
@@ -146,6 +151,7 @@ select = [
146151
"I", # isort
147152
"N", # pep8-naming
148153
"S", # flake8-bandit
154+
"TID", # flake8-tidy-imports
149155
"RUF", # ruff-specific-rules
150156
]
151157
# Ignoring rules problematic with formatter

src/common/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
from .bootstrap import application_init
22
from .config import AppConfig
3+
4+
__all__ = ["AppConfig", "application_init"]

src/common/logs/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from opentelemetry.sdk._logs import LoggingHandler
66
from structlog.typing import Processor
77

8-
from ..config import AppConfig
8+
from common.config import AppConfig
9+
910
from .processors import (
1011
add_logging_open_telemetry_spans,
1112
drop_color_message_key,

src/common/pyproject.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[tool.ruff]
2+
# Extend the `pyproject.toml` file in the parent directory...
3+
extend = "../../pyproject.toml"
4+
5+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
6+
"domains".msg = "Clean Architecture dependency rule break: import of `domains` is not allowed"
7+
"dramatiq_worker".msg = "Clean Architecture dependency rule break: import of `dramatiq_worker` is not allowed"
8+
"http_app".msg = "Clean Architecture dependency rule break: import of `http_app` is not allowed"
9+
"gateways".msg = "Clean Architecture dependency rule break: import of `gateways` is not allowed"
10+
"migrations".msg = "Clean Architecture dependency rule break: import of `migrations` is not allowed"
11+
"socketio_app".msg = "Clean Architecture dependency rule break: import of `socketio_app` is not allowed"
12+
13+
# These ignore rules suggest these modules should not be inside `common`.
14+
[tool.ruff.lint.per-file-ignores]
15+
"storage/**/*.py" = ["TID251"] # Storage is allowed to import domains module as it needs the models
16+
"di_container.py" = ["TID251"] # DI Container is allowed to import domains module

src/domains/pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[tool.ruff]
2+
# Extend the `pyproject.toml` file in the parent directory...
3+
extend = "../../pyproject.toml"
4+
5+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
6+
"dramatiq_worker".msg = "Clean Architecture dependency rule break: import of `dramatiq_worker` is not allowed"
7+
"http_app".msg = "Clean Architecture dependency rule break: import of `http_app` is not allowed"
8+
"gateways".msg = "Clean Architecture dependency rule break: import of `gateways` is not allowed"
9+
"migrations".msg = "Clean Architecture dependency rule break: import of `migrations` is not allowed"
10+
"socketio_app".msg = "Clean Architecture dependency rule break: import of `socketio_app` is not allowed"

src/dramatiq_worker/pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[tool.ruff]
2+
# Extend the `pyproject.toml` file in the parent directory...
3+
extend = "../../pyproject.toml"
4+
5+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
6+
"http_app".msg = "Clean Architecture dependency rule break: import of `http_app` is not allowed"
7+
"gateways".msg = "Clean Architecture dependency rule break: import of `gateways` is not allowed"
8+
"migrations".msg = "Clean Architecture dependency rule break: import of `migrations` is not allowed"
9+
"socketio_app".msg = "Clean Architecture dependency rule break: import of `socketio_app` is not allowed"

src/gateways/pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[tool.ruff]
2+
# Extend the `pyproject.toml` file in the parent directory...
3+
extend = "../../pyproject.toml"
4+
5+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
6+
"domains".msg = "Clean Architecture dependency rule break: import of `domains` is not allowed"
7+
"dramatiq_worker".msg = "Clean Architecture dependency rule break: import of `dramatiq_worker` is not allowed"
8+
"http_app".msg = "Clean Architecture dependency rule break: import of `http_app` is not allowed"
9+
"gateways".msg = "Clean Architecture dependency rule break: import of `gateways` is not allowed"
10+
"migrations".msg = "Clean Architecture dependency rule break: import of `migrations` is not allowed"
11+
"socketio_app".msg = "Clean Architecture dependency rule break: import of `socketio_app` is not allowed"

src/http_app/pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[tool.ruff]
2+
# Extend the `pyproject.toml` file in the parent directory...
3+
extend = "../../pyproject.toml"
4+
5+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
6+
"dramatiq_worker".msg = "Clean Architecture dependency rule break: import of `dramatiq_worker` is not allowed"
7+
"gateways".msg = "Clean Architecture dependency rule break: import of `gateways` is not allowed"
8+
"migrations".msg = "Clean Architecture dependency rule break: import of `migrations` is not allowed"
9+
"socketio_app".msg = "Clean Architecture dependency rule break: import of `socketio_app` is not allowed"

src/migrations/pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[tool.ruff]
2+
# Extend the `pyproject.toml` file in the parent directory...
3+
extend = "../../pyproject.toml"
4+
5+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
6+
"dramatiq_worker".msg = "Clean Architecture dependency rule break: import of `dramatiq_worker` is not allowed"
7+
"http_app".msg = "Clean Architecture dependency rule break: import of `http_app` is not allowed"
8+
"gateways".msg = "Clean Architecture dependency rule break: import of `gateways` is not allowed"
9+
"socketio_app".msg = "Clean Architecture dependency rule break: import of `socketio_app` is not allowed"

src/socketio_app/pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[tool.ruff]
2+
# Extend the `pyproject.toml` file in the parent directory...
3+
extend = "../../pyproject.toml"
4+
5+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
6+
"dramatiq_worker".msg = "Clean Architecture dependency rule break: import of `dramatiq_worker` is not allowed"
7+
"http_app".msg = "Clean Architecture dependency rule break: import of `http_app` is not allowed"
8+
"gateways".msg = "Clean Architecture dependency rule break: import of `gateways` is not allowed"
9+
"migrations".msg = "Clean Architecture dependency rule break: import of `migrations` is not allowed"

0 commit comments

Comments
 (0)