Skip to content

chore: fix ruff lint findings and refactor read_item - #393

Merged
ThePhaseless merged 2 commits into
mainfrom
chore/ruff-lint-cleanup
Aug 10, 2026
Merged

chore: fix ruff lint findings and refactor read_item#393
ThePhaseless merged 2 commits into
mainfrom
chore/ruff-lint-cleanup

Conversation

@ThePhaseless

Copy link
Copy Markdown
Owner

Summary

Resolves all 15 ruff lint findings reported by ruff check ..

Changes

Fixed lint violations

Rule File Fix
I001 src/consts.py Sort imports (auto-fix)
PLC0415 tests/main_test.py Move import base64 to module top-level
UP037 src/models.py Remove quotes from LinkResponse return annotation
D213 src/endpoints.py Multi-line docstring summary on second line
RUF100 src/owui.py Remove unused # noqa: BLE001 directive

Refactored read_item (resolves C901 + PLR0915)

Split the endpoint into focused helpers with clear separation of concerns:

  • setup_routes — installs media-blocking and CSP-stripping routes, captures final URL
  • load_page_and_solve — navigation, challenge detection, solve or wait-for-networkidle
  • build_response_content — dispatches to PDF fetch or HTML content
  • _fetch_pdf_content — base64-encodes PDF bytes with viewer-HTML fallback

read_item is now a thin orchestrator. No behavioral change.

Added to ruff ignore list

  • CPY001 — missing copyright notice (not enforced in this project)
  • BLE001 — blind exception catch (PDF fetch fallback catches broadly by design)

Verification

$ uv run ruff check .
All checks passed!

$ uv run --group test pytest tests/main_test.py -k "max_timeout or networkidle or domcontentloaded"
8 passed in 1.36s

Network-dependent tests (test_bypass, test_health_check, test_pdf_handling) are not run locally.

- Fix I001: sort imports in src/consts.py
- Fix PLC0415: move `import base64` to top of tests/main_test.py
- Fix UP037: remove quotes from LinkResponse return annotation
- Fix D213: correct multi-line docstring summary placement
- Remove unused `# noqa: BLE001` in src/owui.py
- Refactor read_item into helpers: setup_routes, load_page_and_solve,
  build_response_content, _fetch_pdf_content — resolves C901 and PLR0915
- Add CPY001, BLE001 to ruff ignore list
Resolved conflicts in src/consts.py and src/endpoints.py:
- consts.py: take theirs (CHALLENGE_TITLES removed, browser_locale added,
  CaptchaType import no longer needed — detection is now library-based)
- endpoints.py: merge both refactors — keep theirs' detect_cloudflare_challenge
  + page_html capture, reapply my helper extraction (setup_routes,
  _navigate_and_solve, _solve_challenge, _wait_for_networkidle,
  build_response_content, _fetch_pdf_content) on top
@ThePhaseless
ThePhaseless merged commit f821290 into main Aug 10, 2026
8 of 9 checks passed
@ThePhaseless
ThePhaseless deleted the chore/ruff-lint-cleanup branch August 10, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant