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

Set 'home' to parent directory of system_executable #2441

Merged
merged 1 commit into from Nov 12, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/2440.bugfix.rst
@@ -0,0 +1 @@
Use parent directory of python executable for pyvenv.cfg "home" value per PEP 405 - by :user:`vfazio`.
2 changes: 1 addition & 1 deletion src/virtualenv/create/creator.py
Expand Up @@ -157,7 +157,7 @@ def run(self):

def set_pyenv_cfg(self):
self.pyenv_cfg.content = OrderedDict()
self.pyenv_cfg["home"] = self.interpreter.system_exec_prefix
self.pyenv_cfg["home"] = os.path.dirname(os.path.abspath(self.interpreter.system_executable))
self.pyenv_cfg["implementation"] = self.interpreter.implementation
self.pyenv_cfg["version_info"] = ".".join(str(i) for i in self.interpreter.version_info)
self.pyenv_cfg["virtualenv"] = __version__
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/create/test_creator.py
Expand Up @@ -318,6 +318,28 @@ def test_prompt_set(tmp_path, creator, prompt):
assert cfg["prompt"] == actual_prompt


@pytest.mark.parametrize("creator", CURRENT_CREATORS)
def test_home_path_is_exe_parent(tmp_path, creator):
cmd = [str(tmp_path), "--seeder", "app-data", "--without-pip", "--creator", creator]

result = cli_run(cmd)
cfg = PyEnvCfg.from_file(result.creator.pyenv_cfg.path)

# Cannot assume "home" path is a specific value as path resolution may change
# between versions (symlinks, framework paths, etc) but we can check that a
# python executable is present from the configured path per PEP 405
if sys.platform == "win32":
exes = ("python.exe",)
else:
exes = (
"python",
f"python{sys.version_info.major}",
f"python{sys.version_info.major}.{sys.version_info.minor}",
)

assert any(os.path.exists(os.path.join(cfg["home"], exe)) for exe in exes)


@pytest.mark.slow()
@pytest.mark.usefixtures("current_fastest")
def test_cross_major(cross_python, coverage_env, tmp_path, session_app_data):
Expand Down