Repository navigation
Resolve symbolic links for environment metadata - #2686
Merged
Merged
Conversation
gaborbernat
marked this pull request as draft
January 22, 2024 19:11
ofek
marked this pull request as ready for review
January 22, 2024 22:34
Contributor
Author
|
This is ready for review. |
Contributor
|
@ofek plan to pick it up again, or shall I close it? |
Contributor
Author
|
How do you recommend testing? |
Contributor
|
A unit test sounds good 👍 |
Contributor
Author
|
Oh snap sorry, I forgot to follow-up with the test |
5 of 6 tasks
gaborbernat
added a commit
that referenced
this pull request
Oct 1, 2026
`pyvenv.cfg` can end up with a path where a plain value should be, depending on what happens to sit in the directory virtualenv is run from. `PyEnvCfg.write()` makes a value absolute when it names something that exists. The check runs for every key and is relative to the working directory, so a value that isn't a path gets replaced whenever the current folder has an entry with the same name. On current `main`: - `virtualenv 3.14` with Python 3.14 writes `python-version = /cwd/3.14`, because the environment folder itself matches the value - with a file or folder called `true` in the working directory, `--system-site-packages` writes `include-system-site-packages = /cwd/true`. `site.py` only accepts `true`, so the environment comes up without the system site-packages and nothing says why - a `cpython` folder in the working directory does the same to `implementation` on Windows and macOS, where the lookup ignores case I reproduced all three on Windows and the first two on Linux. The check dates back to #2686 (it resolved symlinks then, #3022 changed it to `abspath`). It only makes sense for keys that hold a path, so this limits it to those: `home`, `executable`, `base-prefix`, `base-exec-prefix`, `base-executable` and GraalPy's `venvlauncher_command`. Every other value is written as given. One thing to be aware of: a creator plugin that adds a path key of its own no longer gets it made absolute. `test_pyenv_cfg_preserves_symlinks` used a made-up key (`test_path`), so it now uses `home`. There are two new tests. One checks that plain values survive when the working directory has an entry of the same name, the other that a relative `home` is still made absolute. Putting the old line back fails the first on all four keys. Never calling `abspath`, or dropping `home` from the list, fails the second. Using `realpath` in place of `abspath` fails the symlink test (run on Linux, my Windows machine can't create symlinks). On the outside input: it is the names of files and folders in the working directory, plus the destination name. Before, those could change what a non-path key says, and after this they can't. No new input is read, values still go through the line boundary collapsing from #3247, and nothing on this path is executed. - [x] ran the linter to address style issues (`tox -e fix`) - [x] wrote descriptive pull request text - [x] ensured there are test(s) validating the fix - [x] added news fragment in `docs/changelog` folder - [ ] updated/extended the documentation - [x] for changes to activation scripts, `pyvenv.cfg`, wheel downloads, app-data or release workflows: explained in the PR text which outside input the change handles, such as a path, a prompt or a downloaded file, and how it stops that input from running as code. See the [security scope](https://github.com/pypa/virtualenv/blob/main/.github/SECURITY.md#scope). --------- Co-authored-by: Bernat Gabor <[email protected]>
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.
Resolves #2682
Caution
DO NOT CHECKOUT THE FIRST COMMIT!
I tried running
tox -e py311and it completely wiped my Python installation. 😢