Repository navigation
Stop tracking compiled Python files and forbid committing them - #32
Merged
Merged
Conversation
Nine .pyc files under koopmanrl/environments/__pycache__/ and koopmanrl/koopman_tensor/__pycache__/ were tracked, among them the bytecode of the removed cartpole environments. They showed up as modified after every run and shipped stale bytecode to every clone. They are build artefacts that Python regenerates on import, so they are removed from the repository. .gitignore listed __pycache__/ per directory and missed koopmanrl/koopman_tensor/ and its observables/ package, which is how those files got in. The per-directory entries are replaced by a general rule, __pycache__/ and *.py[cod], that covers every directory. Ignoring does not stop a force-add, so a local pre-commit hook, forbid-compiled-python, fails on any .pyc, .pyo, .pyd or file under a __pycache__/ directory. CI runs `pre-commit run --all-files` on the tracked files, so a compiled file that is committed anyway fails the Lint workflow. The guides describe the new state: koopmanrl/environments/AGENTS.md no longer warns about tracked .pyc files, and the root AGENTS.md and the contributing page of the docs list the new hook and the ignored compiled files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Nine compiled Python files were tracked under
koopmanrl/environments/__pycache__/andkoopmanrl/koopman_tensor/__pycache__/. Two of them were the bytecode of the cartpole environments, which have since been removed. They showed up as modified after every run and gave every clone stale bytecode. This PR stops tracking them and ignores compiled files in every directory. It also adds a pre-commit hook, so a compiled file that someone force-adds fails both locally and in CI.Changes
.pycfiles (git rm): 7 underkoopmanrl/environments/__pycache__/(includingcartpole_control_envandcontinuous_cartpole) and 2 underkoopmanrl/koopman_tensor/__pycache__/. Python regenerates them on import..gitignore: the six per-directory<dir>/__pycache__/entries are replaced by one general rule under the existing# Ignore PyCachesheader. The old entries missedkoopmanrl/koopman_tensor/andobservables/, which is how these files got in. The new rule is:.pre-commit-config.yaml: a newrepo: localhook,forbid-compiled-python(language: fail,files: '(\.py[cod]$|(^|/)__pycache__/)'). It rejects any.pyc,.pyoor.pydfile, and any file under a__pycache__/directory, including one at the top level..gitignorecannot stopgit add -f, but this hook does..github/workflows/lint.ymlrunsuv run pre-commit run --all-files, which checks the tracked files, so a compiled file that is committed anyway also fails the Lint workflow.koopmanrl/environments/AGENTS.md: the bullet that warned about tracked.pycfiles now says they are gitignored and rejected by the hook.AGENTS.md: the hook is added to the list of pre-commit hooks, and compiled files are added to the list of ignored files.docs/docs/developers/contributing.md: the hook is added to the list of hooks.Test plan
uv run pre-commit run --all-filespasses on the branch. All hooks pass;forbid-compiled-pythonreports "no files to check".koopmanrl/__pycache__/dummy.cpython-310.pyc. Bothuv run pre-commit run --files <it>and--all-filesthen fail with "Compiled Python files (.pyc, .pyo, .pyd, pycache/) must not be committed". I removed the dummy afterwards.uv run python -c "import koopmanrl.environments, koopmanrl.koopman_tensor.torch_tensor",git statusis clean.git status --ignoredlists the new__pycache__/directories as ignored.git cloneof the branch:.pycfiles and no__pycache__/directories.uv sync,uv run python -c "import koopmanrl.environments"creates__pycache__/, andgit status --ignoredshows it as ignored (!!).uv run pytest -q tests/test_koopman_tensor_regressors.pygives 17 passed. Its__pycache__/directories underkoopman_tensor/,observables/andtests/are also ignored.🤖 Generated with Claude Code