8000 bpo-41011: venv -- add more variables to pyvenv.cfg (GH-30382) by akulakov · Pull Request #30382 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-41011: venv -- add more variables to pyvenv.cfg (GH- 8000 30382) #30382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use sys.executable not sys.argv
  • Loading branch information
akulakov committed Jan 4, 2022
commit f93cae0e6c4b37c170c2940fa8406437861e7025
2 changes: 1 addition & 1 deletion Lib/test/test_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_defaults(self):
self.assertIn('home = %s' % path, data)
self.assertIn('executable = %s' %
os.path.join(self.env_dir, self.bindir, self.exe), data)
self.assertIn('command = %s' % self.exe, data)
self.assertIn('command = %s' % sys.executable, data)
fn = self.get_env_file(self.bindir, self.exe)
if not os.path.exists(fn): # diagnostics for Windows buildbot failures
bd = self.get_env_file(self.bindir)
Expand Down
2 changes: 1 addition & 1 deletion Lib/venv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def create_configuration(self, context):
if self.prompt is not None:
f.write(f'prompt = {self.prompt!r}\n')
f.write('executable = %s\n' % context.env_exec_cmd)
f.write('command = %s\n' % ' '.join(sys.argv))
f.write('command = %s\n' % sys.executable)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That (sys.executable) is not the command (-line) which was used to create the environment - it would be the python -m venv ... or equivalent command line which need to be recorded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would something like this work?

            args = ' '.join(sys.argv[1:])
            f.write(f'command = {sys.executable} -m {context.env_name} {args}\n')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would something like this work?

Not necessarily. The code to create a venv might be called programmatically through the EnvBuilder API. The intention is to provide a command which, if run, produces a venv with the current settings. So the thing to do is:

  1. Run python3 -m venv -h to see what the command-line options are.
  2. Look at the existing code to see how those options map to attributes of the EnvBuilder which are used in making the venv.
  3. Looking at the EnvBuilder attributes of the current instance, work out what command-line would give those attributes, and synthesize the command line from there.


if os.name != 'nt':
def symlink_or_copy(self, src, dst, relative_symlinks_ok=False):
Expand Down
0