-
Notifications
You must be signed in to change notification settings - Fork 32
Apply ruff formatting to codebase #207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Format all Python files with ruff for consistent code style - Update CI workflow configuration - Maintain all existing functionality (237 tests pass)
- Remove unused imports (F401) in scripts and modules - Add __all__ lists to __init__.py files to document public API - Replace star import in test_equipment.py with explicit imports - Fix bare except clause in docs/source/conf.py (E722) - Remove unused local variables (F841) or add noqa for intentional ones - Add noqa comments for acceptable lint exceptions (E402, E741, F403) - All 237 tests pass (1 skipped)
Co-authored-by: rajeee <[email protected]>
## Summary This PR builds on top of PR #207 (ruff formatting) to also apply all ruff lint fixes to the codebase. - Remove unused imports (F401) in scripts and modules - Add `__all__` lists to `__init__.py` files to document public API and fix re-export warnings - Replace star import in `test_equipment.py` with explicit imports (fixes F403/F405) - Fix bare `except` clause in `docs/source/conf.py` (E722 -> `except Exception:`) - Remove unused local variables (F841) or add noqa for intentional ones - Add noqa comments for acceptable lint exceptions (E402, E741, F403) ### Lint Status Before: **107 errors** After: **0 errors** (all checks pass!) ### Test Status All 237 tests pass (1 skipped). ### How to run ```bash # Check for lint errors (should show 0 errors) ruff check . # Auto-fix any future lint issues ruff check --fix . ``` ### Notes - Some variables like `heating_des_init` and `cooling_des_init` in `ochre/utils/equipment.py` are kept with `# noqa: F841` because they're used dynamically by `eval()` when loading zone temperature files - The star import `from .Equipment import *` in `ochre/__init__.py` is kept for API compatibility with `# noqa: F403`
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
jmaguire1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still want to investigate/fix the alerts that are coming up (most seem to be unused imports) before we merge this in. We also need to figure out why the CI is failing before we merge, it looks like it's having trouble checking out the repo?
|
The tests are passing now - I just reran them. I think it was a temporary github.com access glitch. |
Summary
Linting vs. Formatting with Ruff
We have migrated to Ruff, which replaces several older tools with a single, faster engine.
ruff format .ruff check .(useruff check --fix .to automatically resolve simple issues)Current Policy
ruff format .before every commit.ruff check ochre/Models/StateSpaceModel.pycheck for lints in the StateSpaceModel.py file.Setting up Ruff
To ensure your environment is set up correctly to use the new tooling, please follow these steps:
Update your branch
Merge the latest
devbranch into your current feature branch to get the new configuration files.Install
uvif you don't already have it.We use
uvfor fast Python package management.You can install it from pip with:
curl -LsSf [https://astral.sh/uv/install.sh](https://astral.sh/uv/install.sh) | shSync Dependencies
If you already have a
.venvfolder in your project directory, please delete it first to ensure a clean install. Then run:Run Formatting
You can run Ruff directly using
uv(recommended) or by activating your environment.Option A (Recommended): Run via
uvuv run ruff format .Option B: Activate environment first