Skip to content

Commit

Permalink
replaced command 'deptry check' with deptry (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Maas authored Sep 4, 2022
1 parent 93205c0 commit b3bed87
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ check: ## Check code formatting using isort, black, flake8 and mypy.
@echo "🚀 Checking code formatting: Running flake8"
@flake8 .
@echo "🚀 Checking for obsolete dependencies: Running deptry"
@deptry check .
@deptry .

test: ## Test the code with pytest
@echo "🚀 Testing code: Running pytest"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ In order to check for obsolete imports, __deptry__ should be run directly within
To scan your project for obsolete imports, run

```sh
deptry check .
deptry .
```

or for a more verbose version

```sh
deptry check . -v
deptry . -v
```

__deptry__ can be configured by using additional command line arguments, or
Expand Down
10 changes: 1 addition & 9 deletions deptry/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
from deptry.utils import run_within_dir


@click.group()
def deptry() -> None:
pass


@click.command()
@click.argument("directory", type=click.Path(exists=True))
@click.option(
Expand Down Expand Up @@ -42,7 +37,7 @@ def deptry() -> None:
is_flag=True,
help="Boolean flag to specify if notebooks should be ignored while scanning for imports.",
)
def check(
def deptry(
directory: pathlib.Path,
verbose: bool,
ignore_dependencies: List[str],
Expand Down Expand Up @@ -74,6 +69,3 @@ def check(
else:
logging.info("Succes! No obsolete dependencies found.")
sys.exit(0)


deptry.add_command(check)
2 changes: 1 addition & 1 deletion deptry/imports_to_package_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def convert(self, imported_modules: List[str]) -> List[str]:
"Warning: No metadata was found for any of the imported modules. This can simply be because the package only uses the Python standard library,"
)
logging.warning(
"but this can also be caused by the environment not being installed, found, or activated. Run `deptry check` with the `-v` flag for more details."
"but this can also be caused by the environment not being installed, found, or activated. Run `deptry` with the `-v` flag for more details."
)
logging.debug("\n")

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ In order to check for obsolete imports, _deptry_ should be run directly within t
To scan your project for obsolete imports, run

```sh
deptry check .
deptry .
```

which might output:
Expand Down
12 changes: 6 additions & 6 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ In order to check for obsolete imports, _deptry_ should be run directly within t
_deptry_ can be run with

```sh
deptry check .
deptry .
```

which might output the following:
Expand All @@ -23,7 +23,7 @@ pyproject.toml contains obsolete dependencies: ['pandas', 'numpy']
To show more details about the scanned python files, the imported modules found, and how deptry determined which dependencies are obsolete, add the `-v` flag:

```sh
deptry check . -v
deptry . -v
```

## Ignore dependencies
Expand All @@ -32,13 +32,13 @@ Sometimes, you might want _deptry_ to ignore certain dependencies, for example w
incorrectly marks a dependency as obsolete. Dependencies can be ignore with the `-i` flag:

```sh
deptry check . -i pandas
deptry . -i pandas
```

Multiple dependencies can be ignored by using the flag multiple times:

```sh
deptry check . -i pandas -i numpy
deptry . -i pandas -i numpy
```

## Ignore directories
Expand All @@ -48,15 +48,15 @@ the `.venv` directory is ignored. To ignore other directories, use the `-id` fla
both the `.venv` directory and another directory, use the flag twice:

```sh
deptry check . -id .venv -id other_directory
deptry . -id .venv -id other_directory
```

## Ignore notebooks

By default, _deptry_ scans the working directory for `.py` and `.ipynb` files to check for import statements. To ignore `.ipynb` files, use the `--ignore-notebooks` flag:

```sh
deptry check . --ignore-notebooks
deptry . --ignore-notebooks
```

## pyproject.toml
Expand Down
14 changes: 6 additions & 8 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,35 @@
def test_cli_returns_error(tmp_path):
"""
data/projects/project_with_obsolete has obsolete dependencies.
Verify that `deptry check` returns status code 1 and verify that it finds the right obsolete dependencies.
Verify that `deptry` returns status code 1 and verify that it finds the right obsolete dependencies.
"""

tmp_path_proj = tmp_path / "project_with_obsolete"
shutil.copytree("tests/data/projects/project_with_obsolete", tmp_path_proj)

with run_within_dir(str(tmp_path_proj)):
subprocess.check_call(shlex.split("poetry install --no-interaction --no-root")) == 0
result = subprocess.run(shlex.split("poetry run deptry check ."), capture_output=True, text=True)
result = subprocess.run(shlex.split("poetry run deptry ."), capture_output=True, text=True)
assert result.returncode == 1
assert result.stderr == "pyproject.toml contains obsolete dependencies: ['isort']\n"

result = subprocess.run(
shlex.split("poetry run deptry check . --ignore-notebooks"), capture_output=True, text=True
)
result = subprocess.run(shlex.split("poetry run deptry . --ignore-notebooks"), capture_output=True, text=True)
assert result.returncode == 1
assert result.stderr == "pyproject.toml contains obsolete dependencies: ['cookiecutter-poetry', 'isort']\n"


def test_cli_returns_no_error(tmp_path):
"""
data/projects/project_without_obsolete has no obsolete dependencies.
Verify that `deptry check` completes with status code 0.
Verify that `deptry` completes with status code 0.
"""

tmp_path_proj = tmp_path / "project_without_obsolete"
shutil.copytree("tests/data/projects/project_without_obsolete", tmp_path_proj)

with run_within_dir(str(tmp_path_proj)):
subprocess.check_call(shlex.split("poetry install --no-interaction --no-root")) == 0
result = subprocess.run(shlex.split("poetry run deptry check ."), capture_output=True, text=True)
result = subprocess.run(shlex.split("poetry run deptry ."), capture_output=True, text=True)
assert result.returncode == 0


Expand All @@ -54,7 +52,7 @@ def test_cli_argument_overwrites_pyproject_toml_argument(tmp_path):

with run_within_dir(str(tmp_path_proj)):
subprocess.check_call(shlex.split("poetry install --no-interaction --no-root")) == 0
result = subprocess.run(shlex.split("poetry run deptry check . -i click"), capture_output=True, text=True)
result = subprocess.run(shlex.split("poetry run deptry . -i click"), capture_output=True, text=True)
assert result.returncode == 1
assert result.stderr == "pyproject.toml contains obsolete dependencies: ['isort', 'toml']\n"

Expand Down

0 comments on commit b3bed87

Please sign in to comment.