Refactor to support more env var configuration to virtualenv creation.

This commit is contained in:
Matt Davis
2022-12-13 07:42:56 -05:00
parent d40076a405
commit 78fb22b6cb
2 changed files with 17 additions and 10 deletions
+7 -10
View File
@@ -961,17 +961,19 @@ def convert_three_to_python(three, python):
return python
def _create_virtualenv_cmd(project, python, creator_venv=True, site_packages=False):
def _create_virtualenv_cmd(project, python, site_packages=False):
cmd = [
Path(sys.executable).absolute().as_posix(),
"-m",
"virtualenv",
]
if creator_venv:
cmd.append("--creator=venv")
if project.s.PIPENV_VIRTUALENV_CREATOR:
cmd.append(f"--creator={project.s.PIPENV_VIRTUALENV_CREATOR}")
cmd.append(f"--prompt={project.name}")
cmd.append(f"--python={python}")
cmd.append(project.get_location_for_virtualenv())
if project.s.PIPENV_VIRTUALENV_COPIES:
cmd.append("--copies")
# Pass site-packages flag to virtualenv, if desired...
if site_packages:
@@ -1023,13 +1025,8 @@ def do_create_virtualenv(project, python=None, site_packages=None, pypi_mirror=N
with console.status(
"Creating virtual environment...", spinner=project.s.PIPENV_SPINNER
):
try:
cmd = _create_virtualenv_cmd(project, python, creator_venv=True, site_packages=site_packages)
c = subprocess_run(cmd, env=pip_config)
except (ImportError, FileNotFoundError, exceptions.VirtualenvCreationException):
cmd = _create_virtualenv_cmd(project, python, creator_venv=False, site_packages=site_packages)
c = subprocess_run(cmd, env=pip_config)
cmd = _create_virtualenv_cmd(project, python, site_packages=site_packages)
c = subprocess_run(cmd, env=pip_config)
click.secho(f"{c.stdout}", fg="cyan", err=True)
if c.returncode != 0:
error = (
+10
View File
@@ -346,6 +346,16 @@ class Setting:
)
"""Tells Pipenv whether to name the venv something other than the default dir name."""
self.PIPENV_VIRTUALENV_CREATOR = get_from_env(
"VIRTUALENV_CREATOR", check_for_negation=False
)
"""Tells Pipenv to use the virtualenv --creator= argument with the user specified value."""
self.PIPENV_VIRTUALENV_COPIES = get_from_env(
"VIRTUALENV_COPIES", check_for_negation=True
)
"""Tells Pipenv to use the virtualenv --copies to prevent symlinks when specified as Truthy."""
self.PIPENV_PYUP_API_KEY = get_from_env("PYUP_API_KEY", check_for_negation=False)
# Internal, support running in a different Python from sys.executable.