Skip to content
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
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ pre-commit
pylint
pytest
pytest-cov
packaging>=24.0
poetry
poetry-plugin-export
2 changes: 1 addition & 1 deletion pre_commit_hooks/safety_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def main(argv=None): # pylint: disable=inconsistent-return-statements

files = [Path(f) for f in parsed_args.files]
if all(
"requirements" in file_path.name and file_path.name.endswith(".txt")
"requirements" in str(file_path) and file_path.name.endswith(".txt")
for file_path in files
):
return call_safety_check(
Expand Down
10 changes: 10 additions & 0 deletions tests/safety_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ def test_bare_url_to_tarball_dependency(tmp_path):
assert safety([str(requirements_file)]) == 0


def test_requirements_txt_directory(tmp_path):
requirements_path = tmp_path / "requirements"
requirements_path.mkdir(exist_ok=True)
requirements_file = requirements_path / "app.txt"
with open(requirements_file, "w", encoding="utf-8") as file:
file.write("urllib3==1.24.1")

assert safety([str(requirements_file)]) == EXIT_CODE_VULNERABILITIES_FOUND


def test_pyproject_toml_without_deps(tmp_path):
pyproject_file = tmp_path / "pyproject.toml"
with open(pyproject_file, "w", encoding="utf-8") as file:
Expand Down