Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax regex re. recognizing requirements.txt #372

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fawltydeps/extract_declared_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def first_applicable_parser(path: Path) -> Optional[ParserChoice]:
lambda path: path.name == "pyproject.toml", parse_pyproject_toml
),
ParserChoice.REQUIREMENTS_TXT: ParsingStrategy(
lambda path: re.compile(r".*\brequirements\b.*\.(txt|in)").match(path.name)
lambda path: re.compile(r".*requirements.*\.(txt|in)").match(path.name)
is not None,
parse_requirements_txt,
),
Expand Down
41 changes: 41 additions & 0 deletions tests/test_deps_parser_determination.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import logging
import shutil
from pathlib import Path

import pytest

from fawltydeps.extract_declared_dependencies import (
first_applicable_parser,
parse_source,
parse_sources,
validate_deps_source,
Expand All @@ -16,6 +18,45 @@

from .utils import assert_unordered_equivalence, collect_dep_names


@pytest.mark.parametrize(
["path", "expect_choice"],
[
pytest.param(Path(path), expect_choice, id=path)
for path, expect_choice in [
("requirements.txt", ParserChoice.REQUIREMENTS_TXT),
("setup.py", ParserChoice.SETUP_PY),
("setup.cfg", ParserChoice.SETUP_CFG),
("pyproject.toml", ParserChoice.PYPROJECT_TOML),
("anything_else", None),
("sub/requirements.txt", ParserChoice.REQUIREMENTS_TXT),
("sub/setup.py", ParserChoice.SETUP_PY),
("sub/setup.cfg", ParserChoice.SETUP_CFG),
("sub/pyproject.toml", ParserChoice.PYPROJECT_TOML),
("sub/anything_else", None),
("/abs/requirements.txt", ParserChoice.REQUIREMENTS_TXT),
("/abs/setup.py", ParserChoice.SETUP_PY),
("/abs/setup.cfg", ParserChoice.SETUP_CFG),
("/abs/pyproject.toml", ParserChoice.PYPROJECT_TOML),
("/abs/anything_else", None),
("requirements.txt/wat", None),
("setup.py/wat", None),
("setup.cfg/wat", None),
("pyproject.toml/wat", None),
("requirements-dev.txt", ParserChoice.REQUIREMENTS_TXT),
("test-requirements.txt", ParserChoice.REQUIREMENTS_TXT),
("extra-requirements-dev.txt", ParserChoice.REQUIREMENTS_TXT),
("abc_requirements.txt", ParserChoice.REQUIREMENTS_TXT),
("requirements_abc.txt", ParserChoice.REQUIREMENTS_TXT),
("more_requirements_stuff.txt", ParserChoice.REQUIREMENTS_TXT),
("evenrequirementsthis.txt", ParserChoice.REQUIREMENTS_TXT),
]
],
)
def test_first_applicable_parser(path, expect_choice):
assert first_applicable_parser(path) is expect_choice


PARSER_CHOICE_FILE_NAME_MATCH_GRID = {
ParserChoice.REQUIREMENTS_TXT: "requirements.txt",
ParserChoice.SETUP_PY: "setup.py",
Expand Down