-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically use
requirements.in
if the project uses a `requiremen…
…ts.txt` + `requirements.in`-setup (#641)
- Loading branch information
Showing
16 changed files
with
234 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[tool.black] | ||
line-length = 120 | ||
|
||
[tool.deptry.per_rule_ignores] | ||
DEP001 = ["toml"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
black==22.6.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
click==8.1.3 | ||
isort==5.10.1 | ||
urllib3 | ||
pandas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Generated from requirements.in | ||
click==8.1.3 | ||
isort==5.10.1 | ||
urllib3 | ||
requests | ||
pandas | ||
numpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from os import chdir, walk | ||
from pathlib import Path | ||
|
||
import black | ||
import click | ||
import white as w | ||
from urllib3 import contrib | ||
import requests |
37 changes: 37 additions & 0 deletions
37
tests/data/project_with_requirements_in/src/notebook.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "9f4924ec-2200-4801-9d49-d4833651cbc4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import click\n", | ||
"from urllib3 import contrib\n", | ||
"import toml" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.11" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
from __future__ import annotations | ||
|
||
import uuid | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
from tests.functional.utils import Project | ||
from tests.utils import get_issues_report | ||
|
||
if TYPE_CHECKING: | ||
from tests.utils import PipVenvFactory | ||
|
||
|
||
@pytest.mark.xdist_group(name=Project.REQUIREMENTS_IN) | ||
def test_cli_single_requirements_files(pip_venv_factory: PipVenvFactory) -> None: | ||
""" | ||
in this case, deptry should recognize that there is a `requirements.in` in the project, and | ||
use that as the source of the dependencies. | ||
""" | ||
with pip_venv_factory( | ||
Project.REQUIREMENTS_IN, | ||
install_command=("pip install -r requirements.txt -r requirements-dev.txt"), | ||
) as virtual_env: | ||
issue_report = f"{uuid.uuid4()}.json" | ||
result = virtual_env.run(f"deptry . -o {issue_report}") | ||
|
||
assert result.returncode == 1 | ||
assert get_issues_report(Path(issue_report)) == [ | ||
{ | ||
"error": {"code": "DEP002", "message": "'isort' defined as a dependency but not used in the codebase"}, | ||
"module": "isort", | ||
"location": {"file": str(Path("requirements.in")), "line": None, "column": None}, | ||
}, | ||
{ | ||
"error": {"code": "DEP002", "message": "'pandas' defined as a dependency but not used in the codebase"}, | ||
"module": "pandas", | ||
"location": {"file": str(Path("requirements.in")), "line": None, "column": None}, | ||
}, | ||
{ | ||
"error": {"code": "DEP004", "message": "'black' imported but declared as a dev dependency"}, | ||
"module": "black", | ||
"location": {"file": str(Path("src/main.py")), "line": 4, "column": 8}, | ||
}, | ||
{ | ||
"error": {"code": "DEP001", "message": "'white' imported but missing from the dependency definitions"}, | ||
"module": "white", | ||
"location": {"file": str(Path("src/main.py")), "line": 6, "column": 8}, | ||
}, | ||
{ | ||
"error": {"code": "DEP003", "message": "'requests' imported but it is a transitive dependency"}, | ||
"module": "requests", | ||
"location": {"file": str(Path("src/main.py")), "line": 8, "column": 8}, | ||
}, | ||
] | ||
|
||
|
||
@pytest.mark.xdist_group(name=Project.REQUIREMENTS_IN) | ||
def test_cli_multiple_requirements_files(pip_venv_factory: PipVenvFactory) -> None: | ||
""" | ||
in this case, deptry recognizes that there is a `requirements.in` in the project, but the user | ||
can overwrite that with '--requirements-files requirements.txt', so it still takes requirements.txt as the source | ||
for the project's dependencies. | ||
""" | ||
with pip_venv_factory( | ||
Project.REQUIREMENTS_IN, | ||
install_command=("pip install -r requirements.txt -r requirements-dev.txt"), | ||
) as virtual_env: | ||
issue_report = f"{uuid.uuid4()}.json" | ||
result = virtual_env.run(f"deptry . --requirements-files requirements.txt -o {issue_report}") | ||
|
||
assert result.returncode == 1 | ||
assert get_issues_report(Path(issue_report)) == [ | ||
{ | ||
"error": {"code": "DEP002", "message": "'isort' defined as a dependency but not used in the codebase"}, | ||
"module": "isort", | ||
"location": {"file": str(Path("requirements.txt")), "line": None, "column": None}, | ||
}, | ||
{ | ||
"error": {"code": "DEP002", "message": "'pandas' defined as a dependency but not used in the codebase"}, | ||
"module": "pandas", | ||
"location": {"file": str(Path("requirements.txt")), "line": None, "column": None}, | ||
}, | ||
{ | ||
"error": {"code": "DEP002", "message": "'numpy' defined as a dependency but not used in the codebase"}, | ||
"module": "numpy", | ||
"location": {"file": str(Path("requirements.txt")), "line": None, "column": None}, | ||
}, | ||
{ | ||
"error": {"code": "DEP004", "message": "'black' imported but declared as a dev dependency"}, | ||
"module": "black", | ||
"location": {"file": str(Path("src/main.py")), "line": 4, "column": 8}, | ||
}, | ||
{ | ||
"error": {"code": "DEP001", "message": "'white' imported but missing from the dependency definitions"}, | ||
"module": "white", | ||
"location": {"file": str(Path("src/main.py")), "line": 6, "column": 8}, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters