Skip to content

Commit

Permalink
Merge pull request #12 from sbidoul/fix-extra-detection
Browse files Browse the repository at this point in the history
Fix optional dependencies detection
  • Loading branch information
sbidoul authored Sep 23, 2023
2 parents fb21a82 + d20cd33 commit 52350e3
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 52350e3

Please sign in to comment.