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

Improve the site-packages directory detection #1683

Merged
merged 1 commit into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
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
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