Skip to content

Commit

Permalink
move intersection with project python constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Apr 3, 2022
1 parent bbb119b commit db65a79
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@


if TYPE_CHECKING:
from poetry.core.semver.version_constraint import VersionConstraint
from poetry.core.version.markers import BaseMarker
from tomlkit.items import InlineTable
from tomlkit.toml_document import TOMLDocument
Expand Down Expand Up @@ -315,9 +316,19 @@ def get_project_dependencies(
def get_project_dependency_packages(
self,
project_requires: list[Dependency],
project_python_marker: VersionConstraint | None = None,
dev: bool = False,
extras: bool | Sequence[str] | None = None,
) -> Iterator[DependencyPackage]:
# Apply the project python marker to all requirements.
if project_python_marker is not None:
marked_requires: list[Dependency] = []
for require in project_requires:
require = deepcopy(require)
require.marker = require.marker.intersect(project_python_marker)
marked_requires.append(require)
project_requires = marked_requires

repository = self.locked_repository(with_dev_reqs=dev)

# Build a set of all packages required by our selected extras
Expand Down
11 changes: 3 additions & 8 deletions src/poetry/utils/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import urllib.parse

from copy import deepcopy
from typing import TYPE_CHECKING
from typing import Sequence

Expand Down Expand Up @@ -70,17 +69,13 @@ def _export_requirements_txt(
content = ""
dependency_lines = set()

# Get project dependencies, and add the project-wide marker to them.
# Get project dependencies.
groups = ["dev"] if dev else []
root_package = self._poetry.package.with_dependency_groups(groups)
project_requires = []
for require in root_package.all_requires:
require = deepcopy(require)
require.marker = require.marker.intersect(root_package.python_marker)
project_requires.append(require)

for dependency_package in self._poetry.locker.get_project_dependency_packages(
project_requires=project_requires,
project_requires=root_package.all_requires,
project_python_marker=root_package.python_marker,
dev=dev,
extras=extras,
):
Expand Down

0 comments on commit db65a79

Please sign in to comment.