Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Port) Fix: conda environment is detected as broken (#4566) #5008

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,11 +924,13 @@ class Env(object):
def __init__(self, path, base=None): # type: (Path, Optional[Path]) -> 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"
else:
bin_dir = "Scripts"

self._path = path
self._bin_dir = self._path / bin_dir

Expand Down Expand Up @@ -1079,13 +1081,16 @@ def get_base_prefix(cls): # type: () -> str

return sys.prefix

def find_executables(self): # type: () -> None
def _find_python_executable(self): # type: () -> 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*")
if re.match(r"python(?:\d+(?:\.\d+)?)?(?:\.exe)?$", p.name)
]
p.name
for p in bin_dir.glob("python*")
if re.match(r"python(?:\d+(?:\.\d+)?)?(?:\.exe)?$", p.name)
)
if python_executables:
executable = python_executables[0]
Expand All @@ -1094,12 +1099,11 @@ def find_executables(self): # type: () -> None

self._executable = executable

def _find_pip_executable(self): # type: () -> None
pip_executables = sorted(
[
p.name
for p in self._bin_dir.glob("pip*")
if re.match(r"pip(?:\d+(?:\.\d+)?)?(?:\.exe)?$", p.name)
]
p.name
for p in self._bin_dir.glob("pip*")
if re.match(r"pip(?:\d+(?:\.\d+)?)?(?:\.exe)?$", p.name)
)
if pip_executables:
pip_executable = pip_executables[0]
Expand All @@ -1108,6 +1112,10 @@ def find_executables(self): # type: () -> None

self._pip_executable = pip_executable

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

def get_version_info(self): # type: () -> Tuple[int]
raise NotImplementedError()

Expand Down Expand Up @@ -1235,7 +1243,7 @@ def _bin(self, bin): # type: (str) -> str
# a base Python install.
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