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

Simplify analysis of locked packages #6747

Merged
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
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ generate-setup-file = false
[tool.poetry.dependencies]
python = "^3.7"

poetry-core = "^1.3.2"
poetry-core = "^1.4.0"
poetry-plugin-export = "^1.2.0"
"backports.cached-property" = { version = "^1.0.2", python = "<3.8" }
cachecontrol = { version = "^0.12.9", extras = ["filecache"] }
Expand All @@ -70,7 +70,7 @@ shellingham = "^1.5"
tomli = { version = "^2.0.1", python = "<3.11" }
# exclude 0.11.2 and 0.11.3 due to https://github.com/sdispater/tomlkit/issues/225
tomlkit = ">=0.11.1,<1.0.0,!=0.11.2,!=0.11.3"
trove-classifiers = "^2022.5.19"
trove-classifiers = ">=2022.5.19"
# exclude 20.4.5 - 20.4.6 due to https://github.com/pypa/pip/issues/9953
virtualenv = "^20.4.3,!=20.4.5,!=20.4.6"
xattr = { version = "^0.10.0", markers = "sys_platform == 'darwin'" }
Expand Down
12 changes: 1 addition & 11 deletions src/poetry/puzzle/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,17 +853,7 @@ def get_locked(self, dependency: Dependency) -> DependencyPackage | None:
locked = self._locked.get(dependency.name, [])
for dependency_package in locked:
package = dependency_package.package
if (
# Locked dependencies are always without features.
# Thus, we can't use is_same_package_as() here because it compares
# the complete_name (including features).
dependency.name == package.name
and (
dependency.source_type is None
or dependency.is_same_source_as(package)
)
and dependency.constraint.allows(package.version)
):
if package.satisfies(dependency):
return DependencyPackage(dependency, package)
return None

Expand Down
104 changes: 104 additions & 0 deletions tests/installation/test_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2555,3 +2555,107 @@ def test_installer_should_use_the_locked_version_of_git_dependencies_without_ref
source_reference="HEAD",
source_resolved_reference=expected_reference,
)


# https://github.com/python-poetry/poetry/issues/6710
@pytest.mark.parametrize("env_platform", ["darwin", "linux"])
def test_installer_distinguishes_locked_packages_by_source(
pool: RepositoryPool,
locker: Locker,
installed: CustomInstalledRepository,
config: Config,
repo: Repository,
package: ProjectPackage,
env_platform: str,
):
# Require 1.11.0+cpu from pytorch for most platforms, but specify 1.11.0 and pypi on
# darwin.
package.add_dependency(
Factory.create_dependency(
"torch",
{
"version": "1.11.0+cpu",
"markers": "sys_platform != 'darwin'",
"source": "pytorch",
},
)
)
package.add_dependency(
Factory.create_dependency(
"torch",
{
"version": "1.11.0",
"markers": "sys_platform == 'darwin'",
"source": "pypi",
},
)
)

# Locking finds both the pypi and the pytorch packages.
locker.locked(True)
locker.mock_lock_data(
{
"package": [
{
"name": "torch",
"version": "1.11.0",
"category": "main",
"optional": False,
"files": [],
"python-versions": "*",
},
{
"name": "torch",
"version": "1.11.0+cpu",
"category": "main",
"optional": False,
"files": [],
"python-versions": "*",
"source": {
"type": "legacy",
"url": "https://download.pytorch.org/whl",
"reference": "pytorch",
},
},
],
"metadata": {
"python-versions": "*",
"platform": "*",
"content-hash": "123456789",
},
}
)
installer = Installer(
NullIO(),
MockEnv(platform=env_platform),
package,
locker,
pool,
config,
installed=installed,
executor=Executor(
MockEnv(platform=env_platform),
pool,
config,
NullIO(),
),
)
installer.use_executor(True)
installer.run()

# Results of installation are consistent with the platform requirements.
version = "1.11.0" if env_platform == "darwin" else "1.11.0+cpu"
source_type = None if env_platform == "darwin" else "legacy"
source_url = (
None if env_platform == "darwin" else "https://download.pytorch.org/whl"
)
source_reference = None if env_platform == "darwin" else "pytorch"

assert len(installer.executor.installations) == 1
assert installer.executor.installations[0] == Package(
"torch",
version,
source_type=source_type,
source_url=source_url,
source_reference=source_reference,
)