diff --git a/pyproject.toml b/pyproject.toml index be62abe..8f0eef5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,9 @@ select = [ target-version = "py37" ignore = ["C901"] +[tool.ruff.isort] +known-first-party = ["pyproject_dependencies"] + # coverage [tool.coverage.run] diff --git a/src/pyproject_dependencies/__main__.py b/src/pyproject_dependencies/__main__.py index f831dbf..1027c2a 100644 --- a/src/pyproject_dependencies/__main__.py +++ b/src/pyproject_dependencies/__main__.py @@ -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( diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..cae0805 --- /dev/null +++ b/tests/test_utils.py @@ -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