Skip to content

Commit

Permalink
add support for PEP 621: use all_requires_for_locking instead of `a…
Browse files Browse the repository at this point in the history
…ll_requires`
  • Loading branch information
radoering committed Apr 1, 2024
1 parent a059d47 commit f60eb6f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/poetry/console/commands/debug/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def handle(self) -> int:

packages = [op.package for op in ops]

requires = package.all_requires
requires = package.all_requires_for_locking
for pkg in packages:
for require in requires:
if pkg.name == require.name:
Expand Down
6 changes: 3 additions & 3 deletions src/poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def _display_packages_information(
write_why = self.option("why") and (why_end_column + 3) <= width
write_description = (why_end_column + 24) <= width

requires = root.all_requires
requires = root.all_requires_for_locking

for locked in locked_packages:
color = "cyan"
Expand Down Expand Up @@ -406,7 +406,7 @@ def _display_packages_tree_information(
packages = locked_repository.packages

for p in packages:
for require in root.all_requires:
for require in root.all_requires_for_locking:
if p.name == require.name:
self.display_package_tree(self.io, p, packages)
break
Expand Down Expand Up @@ -544,7 +544,7 @@ def find_latest_package(
from poetry.version.version_selector import VersionSelector

# find the latest version allowed in this pool
requires = root.all_requires
requires = root.all_requires_for_locking
if package.is_direct_origin():
for dep in requires:
if dep.name == package.name and dep.source_type == package.source_type:
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def create_pyproject_from_package(cls, package: Package) -> TOMLDocument:
dependency_section = content["dependencies"] = tomlkit.table()
dependency_section["python"] = package.python_versions

for dep in package.all_requires:
for dep in package.all_requires_for_locking:
constraint: DependencySpec | str = dependency_to_specification(
dep, tomlkit.inline_table()
)
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/puzzle/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def incompatibilities_for(
"""
package = dependency_package.package
if package.is_root():
dependencies = package.all_requires
dependencies = package.all_requires_for_locking
else:
dependencies = package.requires

Expand Down Expand Up @@ -479,7 +479,7 @@ def complete_package(
dependency_package = dependency_package.clone()
package = dependency_package.package
dependency = dependency_package.dependency
requires = package.all_requires
requires = package.all_requires_for_locking
elif package.is_direct_origin():
requires = package.requires
else:
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/puzzle/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def __init__(
def reachable(self) -> list[PackageNode]:
children: list[PackageNode] = []

for dependency in self.package.all_requires:
for dependency in self.package.all_requires_for_locking:
for pkg in self.packages:
if pkg.complete_name == dependency.complete_name and (
dependency.constraint.allows(pkg.version)
Expand Down
23 changes: 19 additions & 4 deletions tests/puzzle/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from cleo.io.null_io import NullIO
from packaging.utils import canonicalize_name
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.dependency_group import MAIN_GROUP
from poetry.core.packages.dependency_group import DependencyGroup
from poetry.core.packages.package import Package
from poetry.core.packages.project_package import ProjectPackage
from poetry.core.packages.vcs_dependency import VCSDependency
Expand Down Expand Up @@ -3118,17 +3120,30 @@ def test_solver_chooses_from_correct_repository_if_forced(
assert ops[0].package.source_url == legacy_repository.url


@pytest.mark.parametrize("project_dependencies", [True, False])
def test_solver_chooses_from_correct_repository_if_forced_and_transitive_dependency(
package: ProjectPackage,
io: NullIO,
legacy_repository: LegacyRepository,
pypi_repository: PyPiRepository,
project_dependencies: bool,
) -> None:
package.python_versions = "^3.7"
package.add_dependency(Factory.create_dependency("foo", "^1.0"))
package.add_dependency(
Factory.create_dependency("tomlkit", {"version": "^0.5", "source": "legacy"})
)
if project_dependencies:
main_group = DependencyGroup(MAIN_GROUP)
package.add_dependency_group(main_group)
main_group.add_dependency(Factory.create_dependency("foo", "^1.0"))
main_group.add_dependency(Factory.create_dependency("tomlkit", "^0.5"))
main_group.add_poetry_dependency(
Factory.create_dependency("tomlkit", {"source": "legacy"})
)
else:
package.add_dependency(Factory.create_dependency("foo", "^1.0"))
package.add_dependency(
Factory.create_dependency(
"tomlkit", {"version": "^0.5", "source": "legacy"}
)
)

repo = Repository("repo")
foo = get_package("foo", "1.0.0")
Expand Down

0 comments on commit f60eb6f

Please sign in to comment.