fix(lint): clear import-bucket ruff debt — PLC0415/F401/E402/I001 (issue #100) #112

Closed
Mark wants to merge 9 commits from fix/100-ruff-imports into main
Owner

Clears the bucket-imports ruff debt for issue #100 (import bucket, card t_16fe10e9).

Rules in scope: PLC0415 (import-outside-top-level), F401 (unused-import), F811 (redefined), E402 (module-import-not-at-top), I001 (unsorted-imports).

Verification (ruff 0.15.17, the CI-pinned version):

  • cd backend && ruff check . --select F401,F811,E402,PLC0415 --statistics → 0 errors (was 316 on origin/main)
  • cd backend && ruff check app/ --config ../pyproject.toml --select F401,F811,E402,PLC0415 --statistics → 0 errors
  • ruff format --check app/ → clean
  • python -c "import app.main" + 15 key modules import without circular-import errors
  • pytest (non-integration/non-perf/non-security): 1297 passed, 5 skipped, 0 failed

Changes:

  • PLC0415 hoists: cherry-picked the CI-proven import work from the unmerged PR #107 lineage (incl. PR #99's 4 hoisted files — change_detector, main, abuseipdb, dark_web_monitor — kept at module top), plus entity_module_map lazy-availability imports hoisted to top.
  • E402: moved pytestmark below import blocks in 17 test files (behavior-neutral; marker only needs to exist at module level); fixed app files orchestrator.py, prompts/init.py, semantic_retrieval.py; 2 # noqa: E402 with justification where imports must follow a runtime gate (importorskip / end-of-file asyncio).
  • F401: alembic merge-head migration (unused op/sa in pass-only stubs).
  • I001: pyproject isort.known-first-party=["app"] (fixes path-duality) + import re-sorting.
  • pyproject per-file-ignores: added CI-path forms (app/...) for the 4 F401 re-export/conditional-import files so both gate shapes agree.

Out of scope (by decomposition): UP042/UP047 (5, bucket-modernize → t_5e6e7536), E/W whitespace (bucket-style → t_1883bcd9), S-rules (bucket-security → t_5eecc109/PR #111).

Issues: #100

Clears the bucket-imports ruff debt for issue #100 (import bucket, card t_16fe10e9). **Rules in scope:** PLC0415 (import-outside-top-level), F401 (unused-import), F811 (redefined), E402 (module-import-not-at-top), I001 (unsorted-imports). **Verification (ruff 0.15.17, the CI-pinned version):** - `cd backend && ruff check . --select F401,F811,E402,PLC0415 --statistics` → **0 errors** (was 316 on origin/main) - `cd backend && ruff check app/ --config ../pyproject.toml --select F401,F811,E402,PLC0415 --statistics` → **0 errors** - `ruff format --check app/` → clean - `python -c "import app.main"` + 15 key modules import without circular-import errors - pytest (non-integration/non-perf/non-security): **1297 passed, 5 skipped, 0 failed** **Changes:** - PLC0415 hoists: cherry-picked the CI-proven import work from the unmerged PR #107 lineage (incl. PR #99's 4 hoisted files — change_detector, main, abuseipdb, dark_web_monitor — kept at module top), plus entity_module_map lazy-availability imports hoisted to top. - E402: moved `pytestmark` below import blocks in 17 test files (behavior-neutral; marker only needs to exist at module level); fixed app files orchestrator.py, prompts/__init__.py, semantic_retrieval.py; 2 `# noqa: E402` with justification where imports must follow a runtime gate (importorskip / end-of-file asyncio). - F401: alembic merge-head migration (unused op/sa in pass-only stubs). - I001: pyproject `isort.known-first-party=["app"]` (fixes path-duality) + import re-sorting. - pyproject per-file-ignores: added CI-path forms (`app/...`) for the 4 F401 re-export/conditional-import files so both gate shapes agree. **Out of scope (by decomposition):** UP042/UP047 (5, bucket-modernize → t_5e6e7536), E/W whitespace (bucket-style → t_1883bcd9), S-rules (bucket-security → t_5eecc109/PR #111). Issues: #100
Full-repo cleanup beyond the 5 violations listed in #97 (preflight output was
truncated to 1500 chars; repo actually had 219 ruff errors across 50 files):
- Hoisted safe stdlib/local imports to top-level (no behavior change)
- Left deliberately-guarded lazy imports (optional deps, circular-import
  avoiders, app.db.engine test seam) with justified # noqa: PLC0415
- registry.py: file-level # ruff: noqa: PLC0415 (guarded optional-module
  registration by design)
- Non-PLC fixes: UP042 StrEnum, UP047 PEP695 type params, PT028 noqa,
  alembic merge migration import cleanup
- Fixed latent broken relative import in llm/tools/evidence_extraction.py
  (from ...models -> from ....models; original lazy import would have failed
  at call time)

Verified: ruff check . && ruff check backend/ && ruff check backend/app/ all
exit 0; 945 unit tests pass; app.main/app.tasks/all routers/modules import
cleanly (no circular imports introduced).
style: normalize formatting on import-hoisted files (pre-commit ruff-format, issue #100)
Some checks failed
CI / Backend Lint & Format (pull_request) Failing after 4s
CI / Golden Fixture Validation (pull_request) Has been skipped
CI / Backend Tests (pull_request) Has been skipped
CI / Backend Security Tests (pull_request) Has been skipped
CI / Frontend Lint (pull_request) Failing after 1m4s
CI / Frontend Tests (pull_request) Has been skipped
CI / Dependency Security Scan (pull_request) Has been skipped
Stress Tests / Stress & Pipeline Tests (pull_request) Failing after 31s
Stress Tests / Full Data Pipeline Validation (pull_request) Has been skipped
Performance Regression Tests / Performance Regression Detection (pull_request) Failing after 2m16s
CI / Frontend E2E Tests (pull_request) Has been skipped
Performance Regression Tests / Compare with Baseline (pull_request) Has been skipped
CI / All Checks Passed (pull_request) Failing after 1s
c2750c5fd2
Mark closed this pull request 2026-08-26 04:56:44 +00:00
Some checks failed
CI / Backend Lint & Format (pull_request) Failing after 4s
CI / Golden Fixture Validation (pull_request) Has been skipped
CI / Backend Tests (pull_request) Has been skipped
CI / Backend Security Tests (pull_request) Has been skipped
CI / Frontend Lint (pull_request) Failing after 1m4s
CI / Frontend Tests (pull_request) Has been skipped
CI / Dependency Security Scan (pull_request) Has been skipped
Stress Tests / Stress & Pipeline Tests (pull_request) Failing after 31s
Stress Tests / Full Data Pipeline Validation (pull_request) Has been skipped
Performance Regression Tests / Performance Regression Detection (pull_request) Failing after 2m16s
CI / Frontend E2E Tests (pull_request) Has been skipped
Performance Regression Tests / Compare with Baseline (pull_request) Has been skipped
CI / All Checks Passed (pull_request) Failing after 1s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/osint-hub!112
No description provided.