gh-148315: Shell-quote the command line in pyvenv.cfg#148368
Open
pratyush618 wants to merge 3 commits intopython:mainfrom
Open
gh-148315: Shell-quote the command line in pyvenv.cfg#148368pratyush618 wants to merge 3 commits intopython:mainfrom
command line in pyvenv.cfg#148368pratyush618 wants to merge 3 commits intopython:mainfrom
Conversation
The `command = ...` record written to `pyvenv.cfg` by `venv.EnvBuilder.create_configuration` was assembled with a plain `' '.join(args)` and an unquoted `sys.executable`. When any of these tokens contained whitespace (for example a Windows user directory like `C:\Users\Z B\...`), the recorded command was no longer a faithful reproduction and truncated at the first space when shell-parsed. Build the full argv as a list and emit it via `shlex.join`, and split `--prompt="..."` into two separate argv tokens so its value is quoted by `shlex.join` as well.
ec004ad to
a8202d9
Compare
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
venv.EnvBuilder.create_configurationbuilt thecommand = ...record inpyvenv.cfgwith' '.join(args)and an unquotedsys.executable. When any token contained whitespace (for example a Windows user directory likeC:\Users\Z B\...), the recorded command was no longer a faithful reproduction and truncated at the first space when shell-parsed — exactly what the reporter of 3.14.4 venv breaks with --system-site-packages if Windows username has a space in it #148315 observed.shlex.join, and split--prompt="..."into two argv tokens so its value is quoted byshlex.jointoo._check_output_of_default_createandtest_config_file_command_keyfor the new format and addtest_config_file_command_quotes_paths_with_spacesto lock in the regression.Out of scope
The reporter also described a second venv being created at
./--system-site-packages/. I could not trace a code path that causes that purely from reading the source — thecommand =line itself is not executed bygetpath.py,site.py, orPC/venvlauncher.c. If the reporter re-tests with this patch and still sees the stray venv, aPYLAUNCHER_DEBUG=1trace should be gathered and tracked as a follow-up.Test plan
./python -m test test_venv -v./python -m venv "/tmp/with space venv" && grep '^command' "/tmp/with space venv/pyvenv.cfg"— right-hand side ofcommand =should round-trip throughshlex.splitas a single token.pyvenv.cfgin a shell and confirm it recreates an equivalent venv.