diff --git a/src/poetry/packages/locker.py b/src/poetry/packages/locker.py index 6b3317a0795..249d2e157d8 100644 --- a/src/poetry/packages/locker.py +++ b/src/poetry/packages/locker.py @@ -236,16 +236,16 @@ def __walk_dependency_level( if locked_package: # create dependency from locked package to retain dependency metadata # if this is not done, we can end-up with incorrect nested dependencies + constraint = requirement.constraint + pretty_constraint = requirement.pretty_constraint marker = requirement.marker requirement = locked_package.to_dependency() requirement.marker = requirement.marker.intersect(marker) - key = (requirement.name, requirement.pretty_constraint) + key = (requirement.name, pretty_constraint) - if pinned_versions: - requirement.set_constraint( - locked_package.to_dependency().constraint - ) + if not pinned_versions: + requirement.set_constraint(constraint) for require in locked_package.requires: if require.marker.is_empty(): diff --git a/src/poetry/utils/exporter.py b/src/poetry/utils/exporter.py index 08a3c8dd60a..98070d19b23 100644 --- a/src/poetry/utils/exporter.py +++ b/src/poetry/utils/exporter.py @@ -1,3 +1,4 @@ +import itertools import urllib.parse from typing import TYPE_CHECKING @@ -69,13 +70,21 @@ def _export_requirements_txt( content = "" dependency_lines = set() - for dependency_package in self._poetry.locker.get_project_dependency_packages( - project_requires=self._poetry.package.all_requires, dev=dev, extras=extras + for package, groups in itertools.groupby( + self._poetry.locker.get_project_dependency_packages( + project_requires=self._poetry.package.all_requires, + dev=dev, + extras=extras, + ), + lambda dependency_package: dependency_package.package, ): line = "" - - dependency = dependency_package.dependency - package = dependency_package.package + dependency_packages = list(groups) + dependency = dependency_packages[0].dependency + marker = dependency.marker + for dep_package in dependency_packages[1:]: + marker = marker.union(dep_package.dependency.marker) + dependency.marker = marker if package.develop: line += "-e "