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

Fix system environment detection #4406

Merged
merged 1 commit into from
Aug 19, 2021
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
17 changes: 10 additions & 7 deletions poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ def remove_venv(cls, path: Union[Path, str]) -> None:
shutil.rmtree(str(file_path))

@classmethod
def get_system_env(cls, naive: bool = False) -> "SystemEnv":
def get_system_env(cls, naive: bool = False) -> Union["SystemEnv", "GenericEnv"]:
"""
Retrieve the current Python environment.

Expand All @@ -1009,16 +1009,14 @@ def get_system_env(cls, naive: bool = False) -> "SystemEnv":
want to retrieve Poetry's custom virtual environment
(e.g. plugin installation or self update).
"""
prefix, base_prefix = Path(sys.prefix), cls.get_base_prefix()
if naive is False:
from poetry.locations import data_dir

prefix, base_prefix = Path(sys.prefix), Path(cls.get_base_prefix())
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 @@ -1586,6 +1584,11 @@ def _updated_path(self) -> str:
return os.pathsep.join([str(self._bin_dir), os.environ.get("PATH", "")])


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


class NullEnv(SystemEnv):
def __init__(
self, path: Path = None, base: Optional[Path] = None, execute: bool = False
Expand Down