Repository navigation
Description
Found by the canary experiment for #205 (QuantEcon/test-actions-lecture-intro#70, run). That experiment runs setup-environment in standard mode on the canary's own environment.yml, which pins anaconda=2025.12.
What happens
In standard mode the action runs these steps in order:
setup-miniconda, withactivate-environment: <environment-name>andpython-version, creates the environment:conda create --name quantecon python=3.13.actions/cacherestores$CONDA/envs/<environment-name>on top of it.- On anything but an exact hit,
conda env update --pruneruns.
The restore's tar overwrites the files both environments share, and leaves the files only the fresh environment has. When the cached environment's packages differ from what conda create python=<version> installs that day, the restored environment is a mix of both.
On the canary:
- The two environments differ. The fresh environment gets pip 26.2.1 and Python 3.13.15. The cached one has pip 25.3 and Python 3.13.9, Anaconda 2025.12's pins.
- An exact hit leaves pip broken (
hitjob).pip listfails withImportError: cannot import name 'BuildDependencyInstallError' from 'pip._internal.exceptions': pip 26.2.1'sbuild_env/package sits beside pip 25.3'sexceptions.py.conda listthen reportspip 26.2.1from PyPI besidepython 3.13.9. The lectures still built, because nothing in a build runs pip. - A fallback restore fails the job (
editjob).conda env updateruns pip for the file'spip:section and dies with the sameImportError.
So a repository that pins its stack, as every one pinning anaconda does, gets a broken pip on every restore. Its first run after an edit to environment.yml fails outright. This predates #206: a restore has always landed on the freshly created environment. No production consumer is affected yet: those that use setup-environment run it in a container, which has no Conda cache.
Why the harness doesn't see it
Its fixture pins nothing: python=3.13 and an unpinned pip. So the fresh and cached environments hold the same versions, and every file is overwritten.
Proposed fix
Delete the environment setup-miniconda created before the restore, so that a restore is an exact copy of the cache. On a miss, create the environment again the same way, conda create -n <environment-name> python=<python-version>, before conda env update, so python-version keeps its meaning.
Restoring before setup-miniconda runs would also avoid the mix. It depends on what setup-miniconda does with an environment that already exists, which would need checking.
Test
Pin an older pip in the harness fixture, so the fresh and cached environments differ. Then:
- assert that
python -m pip --versionworks afterenv-hit-build's exact hit; env-file-edit's fallback update must succeed.
Both would fail today. The canary experiment, re-run at the fix's commit, would confirm it on a full Anaconda stack.
Activity
fix(setup-environment): a restored Conda environment is an exact copy…
experiment: re-run at the QuantEcon/actions#209 fix, and check pip af…
test(setup-environment): a restore must be an exact copy of the cache (…
fix(setup-environment): a restored Conda environment is an exact copy…
fix(setup-environment): a restored Conda environment is an exact copy…
docs(setup-environment): give the real reason container mode caches n…