From 5d87114c4e8e335e882789eb2a4801edba879244 Mon Sep 17 00:00:00 2001 From: David Berenstein Date: Wed, 12 Aug 2026 18:07:19 +0200 Subject: [PATCH 1/2] build: point lint tasks at pre-commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `task lint` and `task format` ran `ruff` and `mypy .`, neither of which this repo enforces: there is no ruff config anywhere, ruff is absent from .pre-commit-config.yaml, and CI (.github/workflows/pre-commit.yml) runs pre-commit only. The result was that both tasks reported ~1300 findings and rewrote ~120 otherwise-clean files, and one ruff SIM117 autofix produced syntactically invalid code in tests/test_powermetrics.py. Both tasks now run pre-commit, matching CI exactly. On current master they pass clean. Also drops the unreferenced `ruff` dev dependency, fixes the `precommit` task (its command was the stray string "c"), and removes `docs-check-drift`, which pointed at scripts/check-docs-drift.py — a file that does not exist. Co-Authored-By: Claude Opus 5 (1M context) --- pyproject.toml | 8 +++----- uv.lock | 27 --------------------------- 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 26a360338..0d02686ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,7 +84,6 @@ dev = [ "taskipy", "bumpver", "pre-commit", - "ruff", "black", "mypy", "pytest", @@ -138,16 +137,15 @@ carbonserver-api-requirements = "uv pip compile carbonserver/pyproject.toml --ge build-doc = "uv run --only-group doc zensical build -f mkdocs.yml && uv run --only-group doc python scripts/check_docs_links.py site" precommit-install = "pre-commit install" precommit-update = "pre-commit autoupdate" -precommit = "c" +precommit = "pre-commit run --all-files" mypy-check = "mypy -m codecarbon --ignore-missing-imports --no-strict-optional --disable-error-code attr-defined --disable-error-code assignment --disable-error-code misc" -lint = "black --check --diff . && ruff check . && mypy ." -format = "black . && ruff check --fix --exit-non-zero-on-fix ." +lint = "pre-commit run --all-files" +format = "pre-commit run --all-files" test-package = "CODECARBON_ALLOW_MULTIPLE_RUNS=True pytest --ignore=tests/test_viz_data.py -vv -m 'not integ_test' tests/" test-coverage = "CODECARBON_ALLOW_MULTIPLE_RUNS=True pytest --cov --cov-report=xml --ignore=tests/test_viz_data.py -vv -m 'not integ_test' tests/" test-package-integ = "CODECARBON_ALLOW_MULTIPLE_RUNS=True python -m pytest -vv tests/" docs = "uv run --only-group doc zensical build -f mkdocs.yml && uv run --only-group doc python scripts/check_docs_links.py site" docs-serve = "zensical serve -f mkdocs.yml" -docs-check-drift = "python scripts/check-docs-drift.py" carbonboard = "python codecarbon/viz/carbonboard.py" [tool.bumpver] diff --git a/uv.lock b/uv.lock index f37050957..7830e8098 100644 --- a/uv.lock +++ b/uv.lock @@ -468,7 +468,6 @@ dev = [ { name = "requests" }, { name = "requests-mock" }, { name = "responses" }, - { name = "ruff" }, { name = "scikit-learn", version = "1.7.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, { name = "scikit-learn", version = "1.9.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, { name = "taskipy" }, @@ -526,7 +525,6 @@ dev = [ { name = "requests" }, { name = "requests-mock" }, { name = "responses" }, - { name = "ruff" }, { name = "scikit-learn" }, { name = "taskipy" }, ] @@ -2853,31 +2851,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/10/85/48f0abdcef5cce4e034c7a5b0ceeceba0b01bf0d942824f4bb720afe2dec/rpds_py-2026.6.3-pp311-pypy311_pp73-musllinux_1_2_x86_64.whl", hash = "sha256:8e65860d238379ed982fd9ba690579b5e95af2f4840f99c772816dbe573cb826", size = 586486, upload-time = "2026-06-30T07:17:51.141Z" }, ] -[[package]] -name = "ruff" -version = "0.16.1" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/70/25/7113f6d5498888c5fb7db34081cba7d5971c4cb1bfb26819966eee68f003/ruff-0.16.1.tar.gz", hash = "sha256:fedad7c801dabd3fb9741d76aca39246e6ddd9ca446a015875207bf19f1e6bc7", size = 4877500, upload-time = "2026-07-30T19:37:01.379Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/1b/bd/694da69368e0973de65df2ddc73ab18d43c469d5963d9b150911de6bc513/ruff-0.16.1-py3-none-linux_armv6l.whl", hash = "sha256:58edb313b88f0c5460a26adf5f39a37a3be789494a15e3e411e35fa78b89f9a0", size = 10839126, upload-time = "2026-07-30T19:36:13.697Z" }, - { url = "https://files.pythonhosted.org/packages/3f/f0/b626e5d5bd0dd9576263658ef12885e2288afd1029a48e26ffed65ec1ac1/ruff-0.16.1-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:fde5a99e2f97479af66edd6622c6d5a2a7592c77cf4153d9e4428f5eeb55b60c", size = 11070253, upload-time = "2026-07-30T19:36:17.14Z" }, - { url = "https://files.pythonhosted.org/packages/83/63/f40acfb6b35b88623e71684942b552c3edd96035f5d98f313815f7b277de/ruff-0.16.1-py3-none-macosx_11_0_arm64.whl", hash = "sha256:e0d4c20532fca4f7fa609369161d968dd28f65d83dabbd61d8e9c7edbf7001f6", size = 10561425, upload-time = "2026-07-30T19:36:20.04Z" }, - { url = "https://files.pythonhosted.org/packages/aa/dd/14ec0e9c2b4d315547dd38765004b4863e354e1b52cb308272215d9f6f6d/ruff-0.16.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:30affbcedf59ad5703d9c91f82266e02b47739f797e1a7b6e158e5526a6dae38", size = 10948879, upload-time = "2026-07-30T19:36:22.476Z" }, - { url = "https://files.pythonhosted.org/packages/33/e9/9d870cbae575030fdef595f04b4b97573c525b5497cce4f4498cf2f85446/ruff-0.16.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:24e9c631573cbca9d20f1283f8f479b2afa4a8503504822bd71a293889f16743", size = 10643691, upload-time = "2026-07-30T19:36:24.914Z" }, - { url = "https://files.pythonhosted.org/packages/c4/09/12743d544e2173f53ecd27217c65f90d2bc0f8424a66a60339e56bbc0457/ruff-0.16.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b41bdd48fb420987a9b5212e4957c26ad4abce401fa9ea9d4d85843727945f4f", size = 11435354, upload-time = "2026-07-30T19:36:28.447Z" }, - { url = "https://files.pythonhosted.org/packages/7f/89/a1652b2daee52083c9554a6333b678a8b01d0400f976827bb87857f9449a/ruff-0.16.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b0d1e1393b7648079e13669de1c1f4fde06d4583e84d8fd5c1551e0a77a2aa75", size = 12259033, upload-time = "2026-07-30T19:36:31.326Z" }, - { url = "https://files.pythonhosted.org/packages/16/96/ecdcb8c54ee7b123b487f807eb014e6e019155a0b81dfb669acd52f28ce3/ruff-0.16.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:07bf434b1c95f4e093be4532068ef4fcf00924eb2ade8796075980902d6fd54a", size = 11667981, upload-time = "2026-07-30T19:36:34.394Z" }, - { url = "https://files.pythonhosted.org/packages/cd/90/c52e12e0d862e9572f2a33aa227409143520abe53111e9a6babbac7b4af8/ruff-0.16.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:39897739f112253ee4fdd2e8aa9a4f9ded99fb2be367d5f31dfa4ded6025584c", size = 11468183, upload-time = "2026-07-30T19:36:37.339Z" }, - { url = "https://files.pythonhosted.org/packages/2c/6b/4ffb7ad1d83eb16cf8cbb3c8815d3f11c88460fd162d4b372a2059be1c2a/ruff-0.16.1-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:82ae3c0c0d74daf17b968a10b7b3bb3ef297ab7de0c1f749646b25e690ccb150", size = 11470071, upload-time = "2026-07-30T19:36:39.91Z" }, - { url = "https://files.pythonhosted.org/packages/9c/72/32ae7db4c0b5e32ab611787caa19d1546800676d79f7483b7100a3561bf4/ruff-0.16.1-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:4d5f2ed10f8242d83fc08d521301089364e3375375705356f20c0e31606ef3ef", size = 10919503, upload-time = "2026-07-30T19:36:42.65Z" }, - { url = "https://files.pythonhosted.org/packages/f7/ca/3d901ba6ad6fc38da39c3448fc6c59ac945679293a17c3ceb6d6c1cba13e/ruff-0.16.1-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:a4665b309891f83f3e3c25447935f1213e9abbd4b5640af7a1f2def9f8d413c1", size = 10649861, upload-time = "2026-07-30T19:36:45.18Z" }, - { url = "https://files.pythonhosted.org/packages/92/79/894ef1ced26552d5f8c9cf6d85b0687840e1128c55aeab7b9c2d54a0d880/ruff-0.16.1-py3-none-musllinux_1_2_i686.whl", hash = "sha256:26e9ca5c9bc3971f20d3cf18a957f52ffd6a5f6564ff15c4912a144dcac22494", size = 11148137, upload-time = "2026-07-30T19:36:47.936Z" }, - { url = "https://files.pythonhosted.org/packages/2d/69/3609a09fa1cb46cc28b762363e440a354204e5dff01bd0c8d7437874d6b9/ruff-0.16.1-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:67e1e1e3fa4f0c82f0e36d4cd61e661f6e7a6196cb1aa92fe0828fa7b8f257cd", size = 11559211, upload-time = "2026-07-30T19:36:50.448Z" }, - { url = "https://files.pythonhosted.org/packages/fc/8a/fb22af2fd78a736e241fabf67e30ce1799a64244026377a49e133af90762/ruff-0.16.1-py3-none-win32.whl", hash = "sha256:d31765e131295b8445caf301e3e8a85b34d1b9b211b4109b7ba457888b051806", size = 10838258, upload-time = "2026-07-30T19:36:53.298Z" }, - { url = "https://files.pythonhosted.org/packages/d4/35/e57fd9fb5d423961df087a00b12d42c0a830288dc2f3b45ecca299158b4f/ruff-0.16.1-py3-none-win_amd64.whl", hash = "sha256:09b05e8b90c2cb06ad63464350e7a45e8e44a2dfe52072ebfba6666ca8d3f596", size = 11961111, upload-time = "2026-07-30T19:36:56.107Z" }, - { url = "https://files.pythonhosted.org/packages/cb/46/240ea004bf6dc4feb40e9832f2205a476a47dd5b8a3f8211a5fc5f95e20e/ruff-0.16.1-py3-none-win_arm64.whl", hash = "sha256:dbaadaac38c70239f056d306b7476f246b0bf000fa6b3876402acbf5b227eaf8", size = 11309414, upload-time = "2026-07-30T19:36:58.79Z" }, -] - [[package]] name = "scikit-learn" version = "1.7.2" From 5f12ba9bd3c0f6f6b3c051f0f5783629da04c9f1 Mon Sep 17 00:00:00 2001 From: David Berenstein Date: Wed, 12 Aug 2026 19:55:32 +0200 Subject: [PATCH 2/2] build: drop the lint alias, it rewrites files Co-Authored-By: Claude Opus 5 (1M context) --- docs/how-to/agent-instructions.md | 8 +++----- pyproject.toml | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/how-to/agent-instructions.md b/docs/how-to/agent-instructions.md index 8b3ebfd0e..4486f158e 100644 --- a/docs/how-to/agent-instructions.md +++ b/docs/how-to/agent-instructions.md @@ -60,8 +60,7 @@ Here's what you need to know to navigate and contribute effectively. # Run specific test uv run pytest tests/test_emissions_tracker.py - # Lint and format - uv run task lint + # Lint and format (runs the pre-commit hooks, which rewrite files in place) uv run task format ``` @@ -112,7 +111,7 @@ Here's what you need to know to navigate and contribute effectively. 1. **Check existing tests** in `tests/` for similar functionality 2. **Add unit tests** first (test-driven development) 3. **Update documentation** if public interface changes -4. **Follow coding style**: Use `uv run task format` and `uv run task lint` +4. **Follow coding style**: Use `uv run task format` ### API Development 1. **Follow FastAPI patterns** - see routers in `carbonserver/carbonserver/api/routers/` @@ -134,8 +133,7 @@ uv run task -l # Main tasks: # - test-package: Core package testing -# - lint: Code linting and style checks -# - format: Code formatting +# - format: Lint and format, by running the pre-commit hooks # - test-api-unit: API unit tests # - test-api-integ: API integration tests # - dashboard: Run API locally diff --git a/pyproject.toml b/pyproject.toml index 0d02686ad..0b5bcbd5a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -139,7 +139,8 @@ precommit-install = "pre-commit install" precommit-update = "pre-commit autoupdate" precommit = "pre-commit run --all-files" mypy-check = "mypy -m codecarbon --ignore-missing-imports --no-strict-optional --disable-error-code attr-defined --disable-error-code assignment --disable-error-code misc" -lint = "pre-commit run --all-files" +# No `lint` task: the pre-commit hooks fix what they can, so this rewrites +# files rather than only reporting. Use `mypy-check` for a read-only check. format = "pre-commit run --all-files" test-package = "CODECARBON_ALLOW_MULTIPLE_RUNS=True pytest --ignore=tests/test_viz_data.py -vv -m 'not integ_test' tests/" test-coverage = "CODECARBON_ALLOW_MULTIPLE_RUNS=True pytest --cov --cov-report=xml --ignore=tests/test_viz_data.py -vv -m 'not integ_test' tests/"