Skip to content

Commit

Permalink
Handle circular dependency on root package (fix python-poetry#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
brechtm committed Dec 7, 2022
1 parent dd00a2f commit 9f64222
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/poetry_plugin_export/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def _export_generic_txt(
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,
):
Expand Down
7 changes: 7 additions & 0 deletions src/poetry_plugin_export/walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def get_python_version_region_markers(packages: list[Package]) -> list[BaseMarke
def get_project_dependency_packages(
locker: Locker,
project_requires: list[Dependency],
root_package_name: NormalizedName,
project_python_marker: BaseMarker | None = None,
extras: bool | Sequence[NormalizedName] | None = None,
) -> Iterator[DependencyPackage]:
Expand Down Expand Up @@ -103,13 +104,15 @@ def get_project_dependency_packages(
for package, dependency in get_project_dependencies(
project_requires=selected,
locked_packages=repository.packages,
root_package_name=root_package_name,
):
yield DependencyPackage(dependency=dependency, package=package)


def get_project_dependencies(
project_requires: list[Dependency],
locked_packages: list[Package],
root_package_name: NormalizedName,
) -> Iterable[tuple[Package, Dependency]]:
# group packages entries by name, this is required because requirement might use
# different constraints.
Expand All @@ -129,6 +132,7 @@ def get_project_dependencies(
nested_dependencies = walk_dependencies(
dependencies=project_requires,
packages_by_name=packages_by_name,
root_package_name=root_package_name,
)

return nested_dependencies.items()
Expand All @@ -137,6 +141,7 @@ def get_project_dependencies(
def walk_dependencies(
dependencies: list[Dependency],
packages_by_name: dict[str, list[Package]],
root_package_name: NormalizedName,
) -> dict[Package, Dependency]:
nested_dependencies: dict[Package, Dependency] = {}

Expand All @@ -145,6 +150,8 @@ def walk_dependencies(
requirement = dependencies.pop(0)
if (requirement, requirement.marker) in visited:
continue
if requirement.name == root_package_name:
continue
visited.add((requirement, requirement.marker))

locked_package = get_locked_package(
Expand Down

0 comments on commit 9f64222

Please sign in to comment.