Skip to content

Commit

Permalink
Improve the site-packages directory detection
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater committed Dec 6, 2019
1 parent c349357 commit 316a838
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,11 @@ def pip_version(self):

@property
def site_packages(self): # type: () -> Path
# It seems that PyPy3 virtual environments
# have their site-packages directory at the root
if self._path.joinpath("site-packages").exists():
return self._path.joinpath("site-packages")

if self._is_windows:
return self._path / "Lib" / "site-packages"

Expand Down
27 changes: 27 additions & 0 deletions tests/utils/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from poetry.factory import Factory
from poetry.semver import Version
from poetry.utils._compat import WINDOWS
from poetry.utils._compat import Path
from poetry.utils.env import EnvCommandError
from poetry.utils.env import EnvManager
Expand Down Expand Up @@ -696,3 +697,29 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(

envs_file = TomlFile(Path(tmp_dir) / "virtualenvs" / "envs.toml")
assert not envs_file.exists()


def test_env_site_packages_should_find_the_site_packages_directory_if_standard(tmp_dir):
if WINDOWS:
site_packages = Path(tmp_dir).joinpath("Lib/site-packages")
else:
site_packages = Path(tmp_dir).joinpath(
"lib/python{}/site-packages".format(
".".join(str(v) for v in sys.version_info[:2])
)
)

site_packages.mkdir(parents=True)

env = VirtualEnv(Path(tmp_dir), Path(tmp_dir))

assert site_packages == env.site_packages


def test_env_site_packages_should_find_the_site_packages_directory_if_root(tmp_dir):
site_packages = Path(tmp_dir).joinpath("site-packages")
site_packages.mkdir(parents=True)

env = VirtualEnv(Path(tmp_dir), Path(tmp_dir))

assert site_packages == env.site_packages

0 comments on commit 316a838

Please sign in to comment.