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

make use of locked markers in lock file version 2.1 and thereby avoid dependency walk failed #286

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
290 changes: 168 additions & 122 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include = [

[tool.poetry.dependencies]
python = "^3.9"
poetry = ">=1.8.0,<3.0.0"
poetry = { git = "https://github.com/radoering/poetry.git", branch = "lock-markers-and-groups3a" }
poetry-core = ">=1.7.0,<3.0.0"

[tool.poetry.group.dev.dependencies]
Expand All @@ -42,7 +42,7 @@ export = "poetry_plugin_export.plugins:ExportApplicationPlugin"

[tool.ruff]
fix = true
target-version = "py39"
target-version = "py38"
line-length = 88
extend-exclude = [
"docs/*",
Expand Down
31 changes: 20 additions & 11 deletions src/poetry_plugin_export/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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 @@ -91,23 +92,31 @@ def _export_generic_txt(
content = ""
dependency_lines = set()

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

python_marker = parse_marker(
create_nested_marker(
"python_version", self._poetry.package.python_constraint
)
)
if self._poetry.locker.is_locked_groups_and_markers():
dependency_package_iterator = get_project_dependency_packages2(
self._poetry.locker,
project_python_marker=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=python_marker,
extras=self._extras,
)

for dependency_package in get_project_dependency_packages(
self._poetry.locker,
project_requires=root.all_requires,
root_package_name=root.name,
project_python_marker=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
7 changes: 5 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,14 @@ def _factory(
# with https://github.com/python-poetry/poetry/pull/9133
locker = TestLocker(
poetry.locker.lock,
poetry.locker._pyproject_data, # type: ignore[attr-defined]
poetry.locker._pyproject_data,
)
except AttributeError:
# before https://github.com/python-poetry/poetry/pull/9133
locker = TestLocker(poetry.locker.lock, poetry.locker._local_config)
locker = TestLocker(
poetry.locker.lock,
poetry.locker._local_config, # type: ignore[attr-defined]
)
locker.write()

poetry.set_locker(locker)
Expand Down
Loading
Loading