Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
e9730ddc
Commit
e9730ddc
authored
Nov 25, 2022
by
Randy Döring
Committed by
Bjorn Neergaard
Nov 30, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(provider): extract handling of any marker dependencies into separate method
parent
dcd48c8d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
49 deletions
+54
-49
src/poetry/puzzle/provider.py
+54
-49
No files found.
src/poetry/puzzle/provider.py
View file @
e9730ddc
...
@@ -740,55 +740,7 @@ class Provider:
...
@@ -740,55 +740,7 @@ class Provider:
f
"<warning>Different requirements found for {warnings}.</warning>"
f
"<warning>Different requirements found for {warnings}.</warning>"
)
)
# We need to check if one of the duplicate dependencies
self
.
_handle_any_marker_dependencies
(
deps
)
# has no markers. If there is one, we need to change its
# environment markers to the inverse of the union of the
# other dependencies markers.
# For instance, if we have the following dependencies:
# - ipython
# - ipython (1.2.4) ; implementation_name == "pypy"
#
# the marker for `ipython` will become `implementation_name != "pypy"`.
#
# Further, we have to merge the constraints of the requirements
# without markers into the constraints of the requirements with markers.
# for instance, if we have the following dependencies:
# - foo (>= 1.2)
# - foo (!= 1.2.1) ; python == 3.10
#
# the constraint for the second entry will become (!= 1.2.1, >= 1.2)
any_markers_dependencies
=
[
d
for
d
in
deps
if
d
.
marker
.
is_any
()]
other_markers_dependencies
=
[
d
for
d
in
deps
if
not
d
.
marker
.
is_any
()]
marker
=
other_markers_dependencies
[
0
]
.
marker
for
other_dep
in
other_markers_dependencies
[
1
:]:
marker
=
marker
.
union
(
other_dep
.
marker
)
inverted_marker
=
marker
.
invert
()
if
any_markers_dependencies
:
for
dep_any
in
any_markers_dependencies
:
dep_any
.
marker
=
inverted_marker
for
dep_other
in
other_markers_dependencies
:
dep_other
.
constraint
=
dep_other
.
constraint
.
intersect
(
dep_any
.
constraint
)
elif
not
inverted_marker
.
is_empty
()
and
self
.
_python_constraint
.
allows_any
(
get_python_constraint_from_marker
(
inverted_marker
)
):
# if there is no any marker dependency
# and the inverted marker is not empty,
# a dependency with the inverted union of all markers is required
# in order to not miss other dependencies later, for instance:
# - foo (1.0) ; python == 3.7
# - foo (2.0) ; python == 3.8
# - bar (2.0) ; python == 3.8
# - bar (3.0) ; python == 3.9
#
# the last dependency would be missed without this,
# because the intersection with both foo dependencies is empty
inverted_marker_dep
=
deps
[
0
]
.
with_constraint
(
EmptyConstraint
())
inverted_marker_dep
.
marker
=
inverted_marker
deps
.
append
(
inverted_marker_dep
)
overrides
=
[]
overrides
=
[]
overrides_marker_intersection
:
BaseMarker
=
AnyMarker
()
overrides_marker_intersection
:
BaseMarker
=
AnyMarker
()
...
@@ -1021,3 +973,56 @@ class Provider:
...
@@ -1021,3 +973,56 @@ class Provider:
)
)
deps
.
append
(
_deps
[
0
]
.
with_constraint
(
new_constraint
))
deps
.
append
(
_deps
[
0
]
.
with_constraint
(
new_constraint
))
return
deps
return
deps
def
_handle_any_marker_dependencies
(
self
,
dependencies
:
list
[
Dependency
])
->
None
:
"""
We need to check if one of the duplicate dependencies
has no markers. If there is one, we need to change its
environment markers to the inverse of the union of the
other dependencies markers.
For instance, if we have the following dependencies:
- ipython
- ipython (1.2.4) ; implementation_name == "pypy"
the marker for `ipython` will become `implementation_name != "pypy"`.
Further, we have to merge the constraints of the requirements
without markers into the constraints of the requirements with markers.
for instance, if we have the following dependencies:
- foo (>= 1.2)
- foo (!= 1.2.1) ; python == 3.10
the constraint for the second entry will become (!= 1.2.1, >= 1.2).
"""
any_markers_dependencies
=
[
d
for
d
in
dependencies
if
d
.
marker
.
is_any
()]
other_markers_dependencies
=
[
d
for
d
in
dependencies
if
not
d
.
marker
.
is_any
()]
marker
=
other_markers_dependencies
[
0
]
.
marker
for
other_dep
in
other_markers_dependencies
[
1
:]:
marker
=
marker
.
union
(
other_dep
.
marker
)
inverted_marker
=
marker
.
invert
()
if
any_markers_dependencies
:
for
dep_any
in
any_markers_dependencies
:
dep_any
.
marker
=
inverted_marker
for
dep_other
in
other_markers_dependencies
:
dep_other
.
constraint
=
dep_other
.
constraint
.
intersect
(
dep_any
.
constraint
)
elif
not
inverted_marker
.
is_empty
()
and
self
.
_python_constraint
.
allows_any
(
get_python_constraint_from_marker
(
inverted_marker
)
):
# if there is no any marker dependency
# and the inverted marker is not empty,
# a dependency with the inverted union of all markers is required
# in order to not miss other dependencies later, for instance:
# - foo (1.0) ; python == 3.7
# - foo (2.0) ; python == 3.8
# - bar (2.0) ; python == 3.8
# - bar (3.0) ; python == 3.9
#
# the last dependency would be missed without this,
# because the intersection with both foo dependencies is empty
inverted_marker_dep
=
dependencies
[
0
]
.
with_constraint
(
EmptyConstraint
())
inverted_marker_dep
.
marker
=
inverted_marker
dependencies
.
append
(
inverted_marker_dep
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment