Skip to content
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

[3.7] bpo-22490: Remove __PYVENV_LAUNCHER__ from environment during launch (GH-9516) #19111

Merged
merged 1 commit into from
Mar 22, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,6 @@ def is_env_var_to_ignore(n):
# on adding even when the environment in exec is empty.
# Gentoo sandboxes also force LD_PRELOAD and SANDBOX_* to exist.
return ('VERSIONER' in n or '__CF' in n or # MacOS
'__PYVENV_LAUNCHER__' in n or # MacOS framework build
n == 'LD_PRELOAD' or n.startswith('SANDBOX') or # Gentoo
n == 'LC_CTYPE') # Locale coercion triggered

Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,18 @@ def test_deactivate_with_strict_bash_opts(self):
self.assertEqual(err, "".encode())


@unittest.skipUnless(sys.platform == 'darwin', 'only relevant on macOS')
def test_macos_env(self):
rmtree(self.env_dir)
builder = venv.EnvBuilder()
builder.create(self.env_dir)

envpy = os.path.join(os.path.realpath(self.env_dir),
self.bindir, self.exe)
out, err = check_output([envpy, '-c',
'import os; print("__PYVENV_LAUNCHER__" in os.environ)'])
self.assertEqual(out.strip(), 'False'.encode())

@requireVenvCreate
class EnsurePipTest(BaseTest):
"""Test venv module installation of pip."""
Expand Down
9 changes: 9 additions & 0 deletions Mac/Tools/pythonw.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ main(int argc, char **argv) {
}
}

/*
* The environment variable is used to pass the value of real_path
* to the actual python interpreter, and is read by code in
* Python/coreconfig.c.
*
* This way the real interpreter knows how the user invoked the
* interpreter and can behave as if this launcher is the real
* interpreter (looking for pyvenv configuration, ...)
*/
setenv("__PYVENV_LAUNCHER__", real_path, 1);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Don't leak environment variable ``__PYVENV_LAUNCHER__`` into the interpreter
session on macOS.
11 changes: 11 additions & 0 deletions Modules/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,17 @@ config_init_program_name(_PyCoreConfig *config)
"variable", (Py_ssize_t)len);
}
config->program_name = program_name;

/*
* This environment variable is used to communicate between
* the stub launcher and the real interpreter and isn't needed
* beyond this point.
*
* Clean up to avoid problems when launching other programs
* later on.
*/
(void)unsetenv("__PYVENV_LAUNCHER__");

return _Py_INIT_OK();
}
}
Expand Down