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-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 5 commits
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
3 changes: 3 additions & 0 deletions Lib/test/test_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def test_defaults(self):
executable = sys._base_executable
path = os.path.dirname(executable)
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' % 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: 2 additions & 0 deletions Lib/venv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def create_configuration(self, context):
f.write('version = %d.%d.%d\n' % sys.version_info[:3])
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' % 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Added two new variables to *pyvenv.cfg* which is generated by :mod:`venv`
module: *executable* for the executable within the environment and *command*
for the command used to create the environment.
Copy link
Member

Choose a reason for hiding this comment

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

command -> command line

0