Skip to content

Commit

Permalink
Fix system env detection
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater committed Aug 19, 2021
1 parent 84eed29 commit 94b54a1
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,9 @@ def remove_venv(cls, path): # type: (Union[Path,str]) -> None
shutil.rmtree(str(file_path))

@classmethod
def get_system_env(cls, naive=False): # type: (bool) -> "SystemEnv"
def get_system_env(
cls, naive=False
): # type: (bool) -> Union["SystemEnv", "GenericEnv"]
"""
Retrieve the current Python environment.
This can be the base Python environment or an activated virtual environment.
Expand All @@ -846,15 +848,13 @@ def get_system_env(cls, naive=False): # type: (bool) -> "SystemEnv"
(e.g. plugin installation or self update).
"""
prefix, base_prefix = Path(sys.prefix), Path(cls.get_base_prefix())
if naive is False:
from poetry.locations import data_dir

if not naive:
try:
prefix.relative_to(data_dir())
Path(__file__).relative_to(prefix)
except ValueError:
pass
else:
prefix = base_prefix
return GenericEnv(base_prefix)

return SystemEnv(prefix)

Expand Down Expand Up @@ -1387,6 +1387,11 @@ def _updated_path(self):
return os.pathsep.join([str(self._bin_dir), os.environ.get("PATH", "")])


class GenericEnv(VirtualEnv):
def is_venv(self): # type: () -> bool
return self._path != self._base


class NullEnv(SystemEnv):
def __init__(self, path=None, base=None, execute=False):
if path is None:
Expand Down

0 comments on commit 94b54a1

Please sign in to comment.