Skip to content

Commit

Permalink
Fix optional dependencies detection
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Sep 23, 2023
1 parent fb21a82 commit d20cd33
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ select = [
target-version = "py37"
ignore = ["C901"]

[tool.ruff.isort]
known-first-party = ["pyproject_dependencies"]

# coverage

[tool.coverage.run]
Expand Down
4 changes: 2 additions & 2 deletions src/pyproject_dependencies/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

from .compat import tomllib

extra_marker_re = re.compile(r"extra\s*==")
extra_marker_re = re.compile(r".+extra\s*==")


def _dep_has_extra(dep: str) -> bool:
return bool(extra_marker_re.search(dep))
return bool(extra_marker_re.match(dep))


def subprocess_runner(
Expand Down
17 changes: 17 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

from pyproject_dependencies.__main__ import _dep_has_extra


@pytest.mark.parametrize(
("dep", "expected"),
[
("stuff", False),
("stuff[extra]", False),
("stuff==1.0", False),
("extra==1.0", False),
("stuff>=1; extra == 'test'", True),
],
)
def test_dep_has_extras(dep: str, expected: bool) -> None:
assert _dep_has_extra(dep) is expected

0 comments on commit d20cd33

Please sign in to comment.