Skip to content

Commit

Permalink
Ensure correct paths are used for generic envs
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater committed Sep 6, 2021
1 parent c5fe517 commit d526348
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,38 @@ def _version_nodot(version):
print(json.dumps(sysconfig.get_paths()))
"""

GET_PATHS_FOR_GENERIC_ENVS = """\
# We can't use sysconfig.get_paths() because
# on some distributions it does not return the proper paths
# (those used by pip for instance). We go through distutils
# to get the proper ones.
import json
import site
import sysconfig
from distutils.command.install import SCHEME_KEYS # noqa
from distutils.core import Distribution
d = Distribution()
d.parse_config_files()
obj = d.get_command_obj("install", create=True)
obj.finalize_options()
paths = sysconfig.get_paths().copy()
for key in SCHEME_KEYS:
if key == "headers":
# headers is not a path returned by sysconfig.get_paths()
continue
paths[key] = getattr(obj, f"install_{key}")
if site.check_enableusersite() and hasattr(obj, "install_usersite"):
paths["usersite"] = getattr(obj, "install_usersite")
paths["userbase"] = getattr(obj, "install_userbase")
print(json.dumps(paths))
"""


class SitePackages:
def __init__(
Expand Down Expand Up @@ -1617,6 +1649,11 @@ def _updated_path(self) -> str:


class GenericEnv(VirtualEnv):
def get_paths(self) -> Dict[str, str]:
output = self.run_python_script(GET_PATHS_FOR_GENERIC_ENVS)

return json.loads(output)

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

Expand Down

0 comments on commit d526348

Please sign in to comment.