Skip to content

Commit

Permalink
Fix extracting extras from markers with many extras
Browse files Browse the repository at this point in the history
  • Loading branch information
q0w committed Dec 30, 2022
1 parent 1d739a2 commit ca01961
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog/2791.bugfix.rst
@@ -0,0 +1 @@
Fix extracting extras from markers with many extras - by :user:`q0w`.
3 changes: 1 addition & 2 deletions src/tox/tox_env/python/virtual_env/package/util.py
Expand Up @@ -45,10 +45,9 @@ def extract_extra_markers(deps: list[Requirement]) -> list[tuple[Requirement, se
extra_markers.add(marker_value.value)
del markers[_at]
_at -= 1
if _at > 0 and (isinstance(markers[_at], str) and markers[_at] in ("and", "or")):
if _at >= 0 and (isinstance(markers[_at], str) and markers[_at] in ("and", "or")):
del markers[_at]
if len(markers) == 0:
req.marker = None
break
result.append((req, extra_markers or {None}))
return result
Expand Up @@ -51,6 +51,15 @@ def test_load_dependency_many_extra(pkg_with_extras: PathDistribution) -> None:
assert str(left) == str(right)


def test_load_dependency_poetry_many_extra() -> None:
requires = [Requirement('filelock<4.0.0,>=3.9.0; extra == "extras1" or extra == "extras2"')]
result = dependencies_with_extras(requires, {"extras1"}, "")
exp = [Requirement("filelock<4.0.0,>=3.9.0")]
for left, right in zip_longest(result, exp):
assert isinstance(right, Requirement)
assert str(left) == str(right)


def test_loads_deps_recursive_extras() -> None:
requires = [
Requirement("no-extra"),
Expand Down

0 comments on commit ca01961

Please sign in to comment.