Skip to content

CMLDEV-1069 Enable ruff linting in PCL, replace flake8/isort/black#217

Merged
tmikuska merged 6 commits into
devfrom
CMLDEV-1069-ruff-in-pcl
May 11, 2026
Merged

CMLDEV-1069 Enable ruff linting in PCL, replace flake8/isort/black#217
tmikuska merged 6 commits into
devfrom
CMLDEV-1069-ruff-in-pcl

Conversation

@marpauli-cisco
Copy link
Copy Markdown
Collaborator

Summary:

  • Add comprehensive ruff configuration to pyproject.toml reusing the monorepo core rule set with PCL-appropriate overrides
  • Fix all 52 ruff violations across source and test files
  • Replace flake8/isort/black with ruff in CI and pre-commit hooks

Changes:

Config (pyproject.toml):

  • Add [tool.ruff] with rule selection (E, W, F, I, PL, S, B, UP, N, SIM, C4, A, RUF, G, T20), ignore set, per-file-ignores for tests and API-driven constructors, isort and format settings
  • Replace flake8 dev dependency with ruff

Source (virl2_client/):

  • Add ClassVar annotations to mutable class-level dicts (_URL_TEMPLATES, _ERROR_PREFIX) across 15 model files

Tests (tests/):

  • Collapse nested with statements (SIM117) across 12 test files
  • Escape regex metacharacters in pytest.raises(match=...) patterns (RUF043)
  • Fix collapsible if statements (SIM102), blind pytest.raises(Exception) (B017), function call in default argument (B008), if/else to ternary (SIM108)
  • Apply ruff-format fixes to 2 test files

CI & tooling:

  • Replace flake8 lint step with ruff check --no-fix + ruff format --check in GitHub Actions
  • Remove isort and black hooks from .pre-commit-config.yaml
  • Rename legacy ruff hook ID to ruff-check
  • Regenerate poetry.lock and tests/requirements.txt

Testing:

  • ruff check virl2_client/ tests/ conftest.py — all checks passed
  • ruff format --check virl2_client/ tests/ conftest.py — all files formatted
  • pytest -n auto — all 1543 tests passing

Configure ruff with the monorepo core rule set (E, W, F, I, PL, S, B,
UP, N, SIM, C4, A, RUF, G, T20) and PCL-appropriate overrides.
Add per-file-ignores for tests and API-driven constructors.
Add ClassVar annotations to mutable class-level dicts (_URL_TEMPLATES
etc.) across 15 model files. In tests, collapse nested with statements,
escape regex metacharacters in pytest match patterns, replace if/else
with ternary, and fix blind pytest.raises(Exception).
Remove isort and black hooks from pre-commit config; rename legacy
'ruff' hook ID to 'ruff-check'. Replace flake8 CI step with
ruff check + ruff format --check. Swap flake8 dev dependency for
ruff and regenerate lock/requirements. Apply ruff-format fixes to
two test files.
@tmikuska tmikuska changed the base branch from main to dev April 26, 2026 07:36
marpauli-cisco and others added 3 commits May 11, 2026 17:26
Apply the same import cleanups across all tests as in the autostart/
backward_compat changes:
- Switch `from helpers` to `from tests.helpers` so the local module is
  imported through its package path (groups it with first-party imports
  after ruff sorting).
- Consolidate `from virl2_client.models.<sub> import X` into
  `from virl2_client.models import X` where X is re-exported by
  `models/__init__.py`. Mixed imports (where some symbols aren't
  re-exported) are left untouched.
- Drop redundant inline `import` statements in test_client_library_runtime.py
  that duplicate module-level imports.

Add two tests in test_event_listening.py to close the previously-missed
branches in event_listening.py:
- test_ssl_verify_path_missing_raises: covers the FileNotFoundError
  branch in _init_ws_connection_data when ssl_verify points at a
  non-existent file (line 95).
- test_parse_cancels_pending_close_wait_on_error: covers the finally
  branch that cancels close_wait when _parse() exits via an exception
  before _ws_close_event is set (lines 193-195).

event_listening.py is now at 100% line coverage, and the whole
virl2_client package reports 100% / 1547 tests pass.
@tmikuska tmikuska merged commit 9852098 into dev May 11, 2026
5 checks passed
@tmikuska tmikuska deleted the CMLDEV-1069-ruff-in-pcl branch May 11, 2026 16:48
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.

2 participants