diff --git a/pipenv/core.py b/pipenv/core.py index 4713a9f7..426df5f1 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -47,7 +47,7 @@ from .environments import ( PYENV_INSTALLED, PIPENV_YES, PIPENV_DONT_LOAD_ENV, PIPENV_DEFAULT_PYTHON_VERSION, PIPENV_MAX_SUBPROCESS, PIPENV_DONT_USE_PYENV, SESSION_IS_INTERACTIVE, PIPENV_USE_SYSTEM, - PIPENV_DOTENV_LOCATION, PIPENV_SHELL + PIPENV_DOTENV_LOCATION, PIPENV_SHELL, PIPENV_PYTHON ) # Backport required for earlier versions of Python. @@ -427,6 +427,10 @@ def find_a_system_python(python): def ensure_python(three=None, python=None): + # Support for the PIPENV_PYTHON environment variable. + if PIPENV_PYTHON and python is False and three is None: + python = PIPENV_PYTHON + def abort(): click.echo( 'You can specify specific versions of Python with:\n {0}'.format( diff --git a/pipenv/environments.py b/pipenv/environments.py index a8745a9a..ea032f4a 100644 --- a/pipenv/environments.py +++ b/pipenv/environments.py @@ -10,6 +10,9 @@ os.environ.pop('__PYVENV_LAUNCHER__', None) # Shell compatibility mode, for mis-configured shells. PIPENV_SHELL_FANCY = bool(os.environ.get('PIPENV_SHELL_FANCY')) +# Support for both Python 2 and Python 3 at the same time. +PIPENV_PYTHON = os.environ.get('PIPENV_PYTHON') + # Create the virtualenv in the project, instead of with pew. PIPENV_VENV_IN_PROJECT = bool(os.environ.get('PIPENV_VENV_IN_PROJECT')) or os.path.isdir('.venv') diff --git a/pipenv/project.py b/pipenv/project.py index 8ea1d472..6871e361 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -16,7 +16,7 @@ from pip import ConfigOptionParser from .utils import ( mkdir_p, convert_deps_from_pip, pep423_name, recase_file, find_requirements, is_file, is_vcs, python_version, cleanup_toml, - is_installable_file, is_valid_url, normalize_drive + is_installable_file, is_valid_url, normalize_drive, python_version ) from .environments import ( PIPENV_MAX_DEPTH, @@ -24,7 +24,8 @@ from .environments import ( PIPENV_VENV_IN_PROJECT, PIPENV_VIRTUALENV, PIPENV_NO_INHERIT, - PIPENV_TEST_INDEX + PIPENV_TEST_INDEX, + PIPENV_PYTHON ) if PIPENV_PIPFILE: @@ -37,7 +38,7 @@ if PIPENV_PIPFILE: class Project(object): """docstring for Project""" - def __init__(self, which=None, chdir=True): + def __init__(self, which=None, python_version=None, chdir=True): super(Project, self).__init__() self._name = None self._virtualenv_location = None @@ -47,6 +48,7 @@ class Project(object): self._requirements_location = None self._original_dir = os.path.abspath(os.curdir) self.which = which + self.python_version = python_version # Hack to skip this during pipenv run, or -r. if ('run' not in sys.argv) and chdir: @@ -161,7 +163,11 @@ class Project(object): # If the pipfile was located at '/home/user/MY_PROJECT/Pipfile', # the name of its virtualenv will be 'my-project-wyUfYPqE' - return sanitized + '-' + encoded_hash + + if PIPENV_PYTHON: + return sanitized + '-' + encoded_hash + '-' + PIPENV_PYTHON + else: + return sanitized + '-' + encoded_hash @property def virtualenv_location(self):