-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from fpgmaas/docs
added documentation, also added some common known packages to import_…
- Loading branch information
Showing
8 changed files
with
145 additions
and
16 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
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 |
---|---|---|
@@ -1,8 +1,50 @@ | ||
|
||
# deptry | ||
|
||
|
||
[](https://img.shields.io/github/v/release/fpgmaas/deptry) | ||
[](https://img.shields.io/github/workflow/status/fpgmaas/deptry/merge-to-main) | ||
[](https://img.shields.io/github/commit-activity/m/fpgmaas/deptry) | ||
[](https://fpgmaas.github.io/deptry/) | ||
[](https://github.com/psf/black) | ||
[](https://pycqa.github.io/isort/) | ||
[](https://img.shields.io/github/license/fpgmaas/deptry) | ||
|
||
A repository to check for unused dependencies in a poetry managed python project | ||
--- | ||
|
||
_deptry_ is a command line tool to check for unused dependencies in a poetry managed python project. It does so by scanning the imported modules within all `.py` files in | ||
a directory and it's subdirectories, and comparing those to the dependencies listed in `pyproject.toml`. | ||
|
||
## Installation and usage | ||
|
||
### Installation | ||
|
||
_deptry_ can be added to your project with | ||
|
||
``` | ||
poetry add deptry | ||
``` | ||
|
||
Alternatively, it can be installed with `pip install deptry`. | ||
|
||
### Prerequisites | ||
|
||
In order to check for obsolete imports, _deptry_ should be run directly within the directory that contains the _pyproject.toml_ file, and it requires the environment created with _pyproject.toml_ to be activated. | ||
|
||
### Usage | ||
|
||
To scan your project for obsolete imports, run | ||
|
||
```sh | ||
deptry check | ||
``` | ||
|
||
which might output: | ||
|
||
``` | ||
pyproject.toml contains obsolete dependencies: ['pandas', 'numpy'] | ||
``` | ||
|
||
_deptry_ can be configured by using additional command line arguments, or | ||
by adding a `[tool.deptry]` section in _pyproject.toml_. For more information, see the [Usage and Configuration](./usage.md) | ||
|
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Usage & Configuration | ||
|
||
## Prerequisites | ||
|
||
In order to check for obsolete imports, _deptry_ should be run directly within the directory that contains the _pyproject.toml_ file, and it requires the environment created with _pyproject.toml_ to be activated. | ||
|
||
## Basic Usage | ||
|
||
_deptry_ can be run with | ||
|
||
```sh | ||
deptry check | ||
``` | ||
|
||
which might output the following: | ||
|
||
``` | ||
pyproject.toml contains obsolete dependencies: ['pandas', 'numpy'] | ||
``` | ||
|
||
## Increased verbosity | ||
|
||
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 | ||
``` | ||
|
||
## Ignore dependencies | ||
|
||
Sometimes, you might want _deptry_ to ignore certain dependencies, for example when you have an module that is used but not imported, or when _deptry_ | ||
incorrectly marks a dependency as obsolete. Dependencies can be ignore with the `-i` flag: | ||
|
||
```sh | ||
deptry check -i pandas | ||
``` | ||
|
||
Multiple dependencies can be ignored by using the flag multiple times: | ||
|
||
```sh | ||
deptry check -i pandas -i numpy | ||
``` | ||
|
||
## Ignore directories | ||
|
||
_deptry_ scans the working directory and it's subdirectories recursively for `.py` files to scan for import statements. By default, | ||
the `.venv` directory is ignored. To ignore other directories, use the `-id` flag. Note that this overwrites the default, so to ignore | ||
both the `.venv` directory and another directory, use the flag twice: | ||
|
||
```sh | ||
deptry check -id .venv -id other_directory | ||
``` | ||
|
||
## pyproject.toml | ||
|
||
_deptry_ can also be configured through `pyproject.toml`. An example `pyproject.toml` entry for `deptry` looks as follows: | ||
|
||
```toml | ||
[tool.deptry] | ||
ignore_dependencies = [ | ||
'pandas' | ||
] | ||
ignore_directories = [ | ||
'.venv', | ||
'other_directory' | ||
] | ||
``` | ||
|
||
## Lookup hierarchy | ||
|
||
Command-line options have defaults that you can see in --help. A pyproject.toml can override those defaults. Finally, options provided by the user on the command line override both. |
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,19 @@ | ||
from deptry.imports_to_package_names import ImportsToPackageNames | ||
|
||
|
||
def test_simple_import(): | ||
imported_modules = ["click"] | ||
package_names = ImportsToPackageNames().convert(imported_modules) | ||
assert package_names == ["click"] | ||
|
||
|
||
def test_common_exception(): | ||
imported_modules = ["bs4"] | ||
package_names = ImportsToPackageNames().convert(imported_modules) | ||
assert package_names == ["beautifulsoup4"] | ||
|
||
|
||
def test_stdlib(): | ||
imported_modules = ["sys"] | ||
package_names = ImportsToPackageNames().convert(imported_modules) | ||
assert package_names == [] |