Commit 658f6410 by Arun Babu Neelicattu

Account for pure/plat lib differences in env

When detecting installed packages, ensure that we check both purelib
and platlib site directories when determining if a package is a
standard package.
parent 6473994b
......@@ -75,11 +75,7 @@ class InstalledRepository(Repository):
repo.add_package(package)
is_standard_package = True
try:
path.relative_to(env.site_packages)
except ValueError:
is_standard_package = False
is_standard_package = env.is_path_relative_to_lib(path)
if is_standard_package:
if path.name.endswith(".dist-info"):
......
......@@ -754,6 +754,8 @@ class Env(object):
self._site_packages = None
self._paths = None
self._supported_tags = None
self._purelib = None
self._platlib = None
@property
def path(self): # type: () -> Path
......@@ -810,11 +812,38 @@ class Env(object):
@property
def site_packages(self): # type: () -> Path
if self._site_packages is None:
self._site_packages = Path(self.paths["purelib"])
self._site_packages = Path(self.purelib)
return self._site_packages
@property
def purelib(self): # type: () -> Path
if self._purelib is None:
self._purelib = Path(self.paths["purelib"])
return self._purelib
@property
def platlib(self): # type: () -> Path
if self._platlib is None:
if "platlib" in self.paths:
self._platlib = Path(self.paths["platlib"])
else:
self._platlib = self.purelib
return self._platlib
def is_path_relative_to_lib(self, path): # type: (Path) -> bool
for lib_path in [self.purelib, self.platlib]:
try:
path.relative_to(lib_path)
return True
except ValueError:
pass
return False
@property
def sys_path(self): # type: () -> List[str]
raise NotImplementedError()
......
Metadata-Version: 2.1
Name: lib64
Version: 2.3.4
Summary: lib64 description.
License: MIT
Keywords: cli,commands
Author: Foo Bar
Author-email: foo@bar.com
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Description-Content-Type: text/x-rst
lib64
####
from typing import Optional
import pytest
from poetry.core.packages import Package
from poetry.repositories.installed_repository import InstalledRepository
from poetry.utils._compat import PY36
from poetry.utils._compat import Path
......@@ -11,25 +14,34 @@ from pytest_mock.plugin import MockFixture
FIXTURES_DIR = Path(__file__).parent / "fixtures"
ENV_DIR = (FIXTURES_DIR / "installed").resolve()
SITE_PACKAGES = ENV_DIR / "lib" / "python3.7" / "site-packages"
SITE_PURELIB = ENV_DIR / "lib" / "python3.7" / "site-packages"
SITE_PLATLIB = ENV_DIR / "lib64" / "python3.7" / "site-packages"
SRC = ENV_DIR / "src"
VENDOR_DIR = ENV_DIR / "vendor" / "py3.7"
INSTALLED_RESULTS = [
metadata.PathDistribution(SITE_PACKAGES / "cleo-0.7.6.dist-info"),
metadata.PathDistribution(SITE_PURELIB / "cleo-0.7.6.dist-info"),
metadata.PathDistribution(SRC / "pendulum" / "pendulum.egg-info"),
metadata.PathDistribution(
zipp.Path(str(SITE_PACKAGES / "foo-0.1.0-py3.8.egg"), "EGG-INFO")
zipp.Path(str(SITE_PURELIB / "foo-0.1.0-py3.8.egg"), "EGG-INFO")
),
metadata.PathDistribution(VENDOR_DIR / "attrs-19.3.0.dist-info"),
metadata.PathDistribution(SITE_PACKAGES / "editable-2.3.4.dist-info"),
metadata.PathDistribution(SITE_PACKAGES / "editable-with-import-2.3.4.dist-info"),
metadata.PathDistribution(SITE_PURELIB / "editable-2.3.4.dist-info"),
metadata.PathDistribution(SITE_PURELIB / "editable-with-import-2.3.4.dist-info"),
metadata.PathDistribution(SITE_PLATLIB / "lib64-2.3.4.dist-info"),
]
class MockEnv(BaseMockEnv):
@property
def site_packages(self): # type: () -> Path
return SITE_PACKAGES
def paths(self):
return {
"purelib": SITE_PURELIB,
"platlib": SITE_PLATLIB,
}
@property
def sys_path(self):
return [ENV_DIR, SITE_PLATLIB, SITE_PURELIB]
@pytest.fixture
......@@ -58,17 +70,27 @@ def repository(mocker, env): # type: (MockFixture, MockEnv) -> InstalledReposit
return InstalledRepository.load(env)
def get_package_from_repository(
name, repository
): # type: (str, InstalledRepository) -> Optional[Package]
for pkg in repository.packages:
if pkg.name == name:
return pkg
return None
def test_load_successful(repository):
assert len(repository.packages) == 5
assert len(repository.packages) == len(INSTALLED_RESULTS) - 1
def test_load_ensure_isolation(repository):
for pkg in repository.packages:
assert pkg.name != "attrs"
package = get_package_from_repository("attrs", repository)
assert package is None
def test_load_standard_package(repository):
cleo = repository.packages[0]
cleo = get_package_from_repository("cleo", repository)
assert cleo is not None
assert cleo.name == "cleo"
assert cleo.version.text == "0.7.6"
assert (
......@@ -76,13 +98,14 @@ def test_load_standard_package(repository):
== "Cleo allows you to create beautiful and testable command-line interfaces."
)
foo = repository.packages[3]
assert foo.name == "foo"
foo = get_package_from_repository("foo", repository)
assert foo is not None
assert foo.version.text == "0.1.0"
def test_load_git_package(repository):
pendulum = repository.packages[4]
pendulum = get_package_from_repository("pendulum", repository)
assert pendulum is not None
assert pendulum.name == "pendulum"
assert pendulum.version.text == "2.0.5"
assert pendulum.description == "Python datetimes made easy"
......@@ -91,12 +114,20 @@ def test_load_git_package(repository):
assert pendulum.source_reference == "bb058f6b78b2d28ef5d9a5e759cfa179a1a713d6"
def test_load_platlib_package(repository):
lib64 = get_package_from_repository("lib64", repository)
assert lib64 is not None
assert lib64.name == "lib64"
assert lib64.version.text == "2.3.4"
@pytest.mark.skipif(
not PY36, reason="pathlib.resolve() does not support strict argument"
)
def test_load_editable_package(repository):
# test editable package with text .pth file
editable = repository.packages[1]
editable = get_package_from_repository("editable", repository)
assert editable is not None
assert editable.name == "editable"
assert editable.version.text == "2.3.4"
assert editable.source_type == "directory"
......@@ -108,7 +139,8 @@ def test_load_editable_package(repository):
def test_load_editable_with_import_package(repository):
# test editable package with executable .pth file
editable = repository.packages[2]
editable = get_package_from_repository("editable-with-import", repository)
assert editable is not None
assert editable.name == "editable-with-import"
assert editable.version.text == "2.3.4"
assert editable.source_type == ""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment