From 69c5ceabf25f131cbf2a22bce43a3b0a08a516ba Mon Sep 17 00:00:00 2001 From: frostming Date: Thu, 4 Jun 2020 19:21:26 +0800 Subject: [PATCH] accepts python as argument --- pipenv/environment.py | 9 ++++++++- pipenv/project.py | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pipenv/environment.py b/pipenv/environment.py index db51af74..508b615e 100644 --- a/pipenv/environment.py +++ b/pipenv/environment.py @@ -41,6 +41,7 @@ class Environment(object): def __init__( self, prefix=None, # type: Optional[str] + python=None, # type: Optional[str] is_venv=False, # type: bool base_working_set=None, # type: pkg_resources.WorkingSet pipfile=None, # type: Optional[Union[tomlkit.toml_document.TOMLDocument, TPipfile]] @@ -51,6 +52,9 @@ class Environment(object): self._modules = {'pkg_resources': pkg_resources, 'pipenv': pipenv} self.base_working_set = base_working_set if base_working_set else BASE_WORKING_SET prefix = normalize_path(prefix) + self._python = None + if python is not None: + self._python = vistir.compat.Path(python).absolute().as_posix() self.is_venv = is_venv or prefix != normalize_path(sys.prefix) if not sources: sources = [] @@ -267,12 +271,15 @@ class Environment(object): def python(self): # type: () -> str """Path to the environment python""" + if self._python is not None: + return self._python if os.name == "nt" and not self.is_venv: py = vistir.compat.Path(self.prefix).joinpath("python").absolute().as_posix() else: py = vistir.compat.Path(self.script_basedir).joinpath("python").absolute().as_posix() if not py: - return vistir.compat.Path(sys.executable).as_posix() + py = vistir.compat.Path(sys.executable).as_posix() + self._python = py return py @cached_property diff --git a/pipenv/project.py b/pipenv/project.py index 6ae4e6ac..72331c0b 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -352,12 +352,14 @@ class Project(object): is_venv = is_in_virtualenv() if allow_global and not is_venv: prefix = sys.prefix + python = sys.executable else: prefix = self.virtualenv_location + python = None sources = self.sources if self.sources else [DEFAULT_SOURCE] environment = Environment( - prefix=prefix, is_venv=is_venv, sources=sources, pipfile=self.parsed_pipfile, - project=self + prefix=prefix, python=python, is_venv=is_venv, sources=sources, + pipfile=self.parsed_pipfile, project=self ) pipenv_dist = get_pipenv_dist(pkg="pipenv") if pipenv_dist: