Skip to content

Commit

Permalink
make use of locked markers in lock file version 2.1 and thereby avoid…
Browse files Browse the repository at this point in the history
… `dependency walk failed`
  • Loading branch information
radoering committed Aug 24, 2024
1 parent c672530 commit f5e4b38
Show file tree
Hide file tree
Showing 3 changed files with 1,848 additions and 1,504 deletions.
32 changes: 21 additions & 11 deletions src/poetry_plugin_export/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from poetry.repositories.http_repository import HTTPRepository

from poetry_plugin_export.walker import get_project_dependency_packages
from poetry_plugin_export.walker import get_project_dependency_packages2


if TYPE_CHECKING:
Expand Down Expand Up @@ -89,17 +90,26 @@ def _export_generic_txt(
content = ""
dependency_lines = set()

root = self._poetry.package.with_dependency_groups(
list(self._groups), only=True
)

for dependency_package in get_project_dependency_packages(
self._poetry.locker,
project_requires=root.all_requires,
root_package_name=root.name,
project_python_marker=root.python_marker,
extras=self._extras,
):
if self._poetry.locker.is_locked_groups_and_markers():
dependency_package_iterator = get_project_dependency_packages2(
self._poetry.locker,
project_python_marker=self._poetry.package.python_marker,
groups=set(self._groups),
extras=self._extras,
)
else:
root = self._poetry.package.with_dependency_groups(
list(self._groups), only=True
)
dependency_package_iterator = get_project_dependency_packages(
self._poetry.locker,
project_requires=root.all_requires,
root_package_name=root.name,
project_python_marker=root.python_marker,
extras=self._extras,
)

for dependency_package in dependency_package_iterator:
line = ""

if not with_extras:
Expand Down
22 changes: 22 additions & 0 deletions src/poetry_plugin_export/walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,5 +264,27 @@ def get_locked_package(
return next(iter(compatible_candidates), None)


def get_project_dependency_packages2(
locker: Locker,
project_python_marker: BaseMarker | None = None,
groups: Collection[str] = (),
extras: Collection[NormalizedName] = (),
) -> Iterator[DependencyPackage]:
for package, info in locker.locked_packages().items():
if not info.groups.intersection(groups):
continue

marker = info.get_marker(groups)
if not marker.validate({"extra": extras}):
continue

if project_python_marker:
marker = project_python_marker.intersect(marker)

package.marker = marker

yield DependencyPackage(dependency=package.to_dependency(), package=package)


class DependencyWalkerError(Exception):
pass
Loading

0 comments on commit f5e4b38

Please sign in to comment.