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 Jan 6, 2023
1 parent d920881 commit f61fa9f
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 @@ -95,6 +95,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: Collection[NormalizedName] = (),
) -> Iterator[DependencyPackage]:
Expand Down Expand Up @@ -96,13 +97,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 @@ -122,6 +125,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 @@ -130,6 +134,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 @@ -138,6 +143,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 f61fa9f

Please sign in to comment.