@biffo/cli 0.346.0 → 0.348.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -94,11 +94,21 @@ line-length = 100
|
|
|
94
94
|
# place: ANN401 rejects the `Any` in a Pydantic mode="before" validator, which
|
|
95
95
|
# is the one signature where `Any` is genuinely correct.
|
|
96
96
|
[tool.ruff.lint]
|
|
97
|
-
select = ["E", "F", "I", "N", "W", "B", "S", "UP"]
|
|
97
|
+
select = ["E", "F", "I", "N", "W", "B", "S", "UP", "TID251"]
|
|
98
98
|
ignore = [
|
|
99
99
|
"S101", # allow assert in tests
|
|
100
100
|
]
|
|
101
101
|
|
|
102
|
+
# `src.<pkg>` imports resolve in this repo only if something puts the repo root on
|
|
103
|
+
# sys.path, then fail with ModuleNotFoundError once the plugin is vendored to
|
|
104
|
+
# services/<name>/ (services/api's own `src` package claims the name first, so
|
|
105
|
+
# the failure only shows when an API test runs earlier in the same session).
|
|
106
|
+
# Import by the package name (`from <pkg>.<mod> import x`) instead. TID251 matches
|
|
107
|
+
# the module and every submodule beneath it, so `from src.<pkg>.<mod> import x`
|
|
108
|
+
# is rejected too. Enforced by `ruff check .` in ci.yml and in pre-push `verify`.
|
|
109
|
+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
|
|
110
|
+
"src".msg = "Import by package name (`from <pkg>.<mod> import x`), not through `src.`: it fails once the plugin is vendored into an instance."
|
|
111
|
+
|
|
102
112
|
# FastAPI's dependency-injection defaults are the framework's idiomatic
|
|
103
113
|
# call-in-default pattern, not the B008 mutable-default bug. Without this a
|
|
104
114
|
# plugin cannot write `x = Depends(...)` — the mandatory idiom for any plugin
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""The TID251 `src` ban rejects `src.<pkg>.<mod>` imports and accepts `<pkg>.<mod>`."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import subprocess
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _tid251(tmp_path: Path, source: str) -> list[dict]:
|
|
12
|
+
f = tmp_path / "probe.py"
|
|
13
|
+
f.write_text(source)
|
|
14
|
+
out = subprocess.run( # noqa: S603
|
|
15
|
+
[
|
|
16
|
+
sys.executable,
|
|
17
|
+
"-m",
|
|
18
|
+
"ruff",
|
|
19
|
+
"check",
|
|
20
|
+
"--config",
|
|
21
|
+
str(ROOT / "pyproject.toml"),
|
|
22
|
+
"--no-cache",
|
|
23
|
+
"--select",
|
|
24
|
+
"TID251",
|
|
25
|
+
"--output-format",
|
|
26
|
+
"json",
|
|
27
|
+
str(f),
|
|
28
|
+
],
|
|
29
|
+
capture_output=True,
|
|
30
|
+
text=True,
|
|
31
|
+
check=False,
|
|
32
|
+
)
|
|
33
|
+
return json.loads(out.stdout)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_submodule_src_import_is_rejected(tmp_path):
|
|
37
|
+
assert _tid251(tmp_path, "from src.pkg.mod import x\n")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_plain_and_dotted_src_imports_are_rejected(tmp_path):
|
|
41
|
+
assert _tid251(tmp_path, "import src\n")
|
|
42
|
+
assert _tid251(tmp_path, "import src.pkg.mod\n")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_package_name_import_is_accepted(tmp_path):
|
|
46
|
+
assert _tid251(tmp_path, "from pkg.mod import x\n") == []
|