Skip to content

Commit

Permalink
add alternative bin search path in case of conda env under windows
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer authored and neersighted committed Jan 17, 2022
1 parent 20587f1 commit 85ff214
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,7 @@ class Env:
def __init__(self, path: Path, base: Optional[Path] = None) -> None:
self._is_windows = sys.platform == "win32"
self._is_mingw = sysconfig.get_platform().startswith("mingw")
self._is_conda = bool(os.environ.get("CONDA_DEFAULT_ENV"))

if not self._is_windows or self._is_mingw:
bin_dir = "bin"
Expand Down Expand Up @@ -1125,10 +1126,15 @@ def marker_env(self) -> Dict[str, Any]:
def parent_env(self) -> "GenericEnv":
return GenericEnv(self.base, child_env=self)

def find_executables(self) -> None:
def _find_python_executable(self) -> None:
bin_dir = self._bin_dir

if self._is_windows and self._is_conda:
bin_dir = self._path

python_executables = sorted(
p.name
for p in self._bin_dir.glob("python*")
for p in bin_dir.glob("python*")
if re.match(r"python(?:\d+(?:\.\d+)?)?(?:\.exe)?$", p.name)
)
if python_executables:
Expand All @@ -1138,6 +1144,7 @@ def find_executables(self) -> None:

self._executable = executable

def _find_pip_executable(self) -> None:
pip_executables = sorted(
p.name
for p in self._bin_dir.glob("pip*")
Expand All @@ -1150,6 +1157,10 @@ def find_executables(self) -> None:

self._pip_executable = pip_executable

def find_executables(self) -> None:
self._find_python_executable()
self._find_pip_executable()

def get_embedded_wheel(self, distribution: str) -> Path:
return get_embed_wheel(
distribution, f"{self.version_info[0]}.{self.version_info[1]}"
Expand Down Expand Up @@ -1395,7 +1406,7 @@ def _bin(self, bin: str) -> str:
# the root of the env path.
if self._is_windows:
if not bin.endswith(".exe"):
bin_path = self._bin_dir / (bin + ".exe")
bin_path = self._path / (bin + ".exe")
else:
bin_path = self._path / bin

Expand Down

0 comments on commit 85ff214

Please sign in to comment.