Skip to content

Adopt Ruff and mypy in pre-commit and CI - #228

Merged
gAldeia merged 4 commits into
cavalab:devfrom
alcides:codex/ruff-ci-193
Oct 14, 2026
Merged

gAldeia merged 4 commits into
cavalab:devfrom
alcides:codex/ruff-ci-193

Conversation

@alcides

@alcides alcides commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Closes #193.

Contributors currently have no shared formatting, lint, or type-check gate. This adds Ruff 0.17.0 (the latest release at implementation time) and mypy 2.4.0 to pre-commit, with a dedicated GitHub Actions workflow running the same hooks on every PR and pushes to master/dev.

  • Apply Ruff formatting and fix lint findings across all Python sources and notebooks; also format Markdown Python examples. Preserve notebook outputs and metadata, and make adapter API re-exports explicit so unused-import fixes retain the functions the harness imports.
  • Check unannotated function bodies with mypy. A small runner supplies module names for importlib-loaded hyphenated directories (e.g. gp-elite/ps-tree) and discovers all tracked/new Python files through Git. Third-party imports remain Any because algorithm dependencies live in separate containers; site packages are ignored so results match between local hooks and CI. Notebooks are linted/formatted, but not type-checked.
  • Fix the findings, including the E2E loaded-model/API name collision, the stale tuned gplearn import, collection annotations, and guards for unset NeSymRes configuration and unfitted Operon estimators. Retain compatibility with older algorithm environments by postponing new annotations and targeting Python 3.7 syntax in Ruff.
  • Document installation, hook usage, type-check scope, and synchronized version upgrades in CONTRIBUTING.md.

This is intentionally a repository-wide formatting change (111 files), as discussed in the issue.

Validation:

  • pre-commit run --all-files --show-diff-on-failure: Ruff lint, Ruff format, and mypy all pass (149 Python source files checked).
  • ruff check . and ruff format --check .: pass.
  • python scripts/check_method_layout.py: pass (existing ignored algorithms/tir/regressor.py warning remains).
  • python -m pytest -q experiment/metrics/test_evaluation.py: 5 passed.
  • From experiment/: python -m pytest -q test_algorithm.py test_evaluate_model.py --ml sklearn: 4 passed.
  • Verified notebook outputs/metadata are unchanged, and injected a temporary type error in an unannotated function under gp-elite to verify the type checker fails correctly.

The full algorithm Docker matrix was not run locally; existing Docker CI remains responsible for container-specific integration tests.

@gAldeia

gAldeia commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Thank you, @alcides, for putting this together.

I added the final Ruff formatting fix in the gp-elite wrapper and reran the lint check successfully.

I also fixed the Python 3.15 Docker CI failures for gp-elite, keplearn, and PIR by temporarily constraining those methods to Python <3.15, since Conda Forge does not yet provide compatible pyarrow builds for Python 3.15. The constraint is scoped to the affected methods rather than the shared base environment.

I’ll close #193, since this PR now implements the proposed linting and formatting checks.

@gAldeia
gAldeia merged commit 1f85a14 into cavalab:dev Oct 14, 2026
35 checks passed
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