Skip to content

Commit

Permalink
Refactor to support more env var configuration to virtualenv creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
matteius committed Dec 13, 2022
1 parent d40076a commit 78fb22b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
17 changes: 7 additions & 10 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 = (
Expand Down
10 changes: 10 additions & 0 deletions pipenv/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,16 @@ def __init__(self) -> None:
)
"""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.
Expand Down

0 comments on commit 78fb22b

Please sign in to comment.