Skip to content

refactor: use pathlib for file paths and enable ruff PTH rules#738

Draft
bluetoothbot wants to merge 1 commit into
Bluetooth-Devices:mainfrom
bluetoothbot:koan/ruff-pth
Draft

refactor: use pathlib for file paths and enable ruff PTH rules#738
bluetoothbot wants to merge 1 commit into
Bluetooth-Devices:mainfrom
bluetoothbot:koan/ruff-pth

Conversation

@bluetoothbot

@bluetoothbot bluetoothbot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

What

Convert os.path / bare open() usage to pathlib.Path across the repo, then add the PTH (flake8-use-pathlib) rule family to ruff's select list.

Why

Continues the incremental ruff-rule-family expansion from #721. PTH was the cheapest remaining clean candidate — 24 violations tree-wide, all mechanical, zero pre-existing exceptions needed.

How

  • src/dbus_fast/_private/address.py: two open(...) calls (machine-id + dbus session info file) → Path(...).open(). Behaviour unchanged; .pxd untouched (no signature change). Sync I/O semantics preserved — the existing XXX: this will block comment still applies.
  • docs/source/conf.py, examples/*.py, bench/unmarshall_getmanagedobjects.py: sphinx/example sys.path bootstrap and fixture loaders.
  • tests/test_address_parser.py, tests/test_introspection.py, tests/test_marshaller.py: fixture file reads.
  • pyproject.toml: add PTH to [tool.ruff.lint] select.

Testing

  • dbus-run-session -- poetry run pytest --timeout=5 -q → 363 passed, 20 skipped, coverage 85.35%.
  • poetry run ruff check . → clean.
  • poetry run ruff format --check . → 88 files already formatted.

Quality Report

Changes: 13 files changed, 31 insertions(+), 24 deletions(-)

Code scan: clean

Tests: failed (FAILED)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

Convert os.path / open() usage to pathlib.Path across src, bench, docs,
examples, and tests, then add the PTH rule family to the ruff select so
new violations are caught at lint time.

The two src changes are in _private/address.py (machine-id and dbus
session info file reads); behaviour is unchanged. The remaining 22
fixes are sphinx conf, example sys.path bootstrap, bench harness, and
test fixture loaders.
@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.38%. Comparing base (f5398eb) to head (d1a98d8).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #738   +/-   ##
=======================================
  Coverage   91.38%   91.38%           
=======================================
  Files          29       29           
  Lines        3621     3622    +1     
  Branches      623      623           
=======================================
+ Hits         3309     3310    +1     
  Misses        186      186           
  Partials      126      126           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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