From d20cd332a3accb862fd83fa75ab5cd1db6a21b3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sat, 23 Sep 2023 09:18:07 +0200 Subject: [PATCH] Fix optional dependencies detection --- pyproject.toml | 3 +++ src/pyproject_dependencies/__main__.py | 4 ++-- tests/test_utils.py | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/test_utils.py 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