# Check Dependencies
Check all imports from python files and compares them against the declared imports of a pyproject dependency list of expected imports.
It can be used as a stand-alone or as part of a CI/CD to check if an application has all the necessary, but no superfluous imports.
## Usage
```commandline
usage: check-dependencies [-h] [--include-extra] [--verbose] [--all] [--missing MISSING] [--extra EXTRA] file_name [file_name ...]
Find undeclared and unused (or all) imports in Python files
positional arguments:
file_name Python Source file to analyse
optional arguments:
-h, --help show this help message and exit
--include-extra Include dev dependencies
--verbose Show every import of a package
--all Show all imports (including correct ones)
--missing MISSING Comma seperated list of requirements known to be missing. Assume they are part of the requirements
--extra EXTRA Comma seperated list of requirements known to not be imported. Assume they are not part of the requirements```
```
### Output
The output is a list of imports with a prefix indicating the status of the import.
- `!` - Undeclared import
- `+` - Extra import, declared in pyproject.toml, but not used in the file
- ` ` - Correct import (only shown with `--all`)
**In case of `--verbose`**, the output is a list of all imports in the file, prefixed with:
- `!NA` - Undeclared import
- `+EXTRA` - Extra import, declared in pyproject.toml, but not used in the file
- ` OK` - Correct import (only shown with `--all`)
Additionally, each import is prefixed with the file name and line number
where it is imported.
### Examples
#### Basic usage
```commandline
> check-dependencies project/src/
pandas
! matplotlib
numpy
+ requests
```
#### Output all dependencies
Output all dependencies, including the correct ones.
```commandline
> check-dependencies --all project/src/
pandas
! matplotlib
numpy
+ requests
```
#### Verbose output
Output each erroneous import and extra dependency with cause, file name and line number.
```commandline
> check-dependencies --verbose project/src/
!NA matplotlib project/src/main.py:4
+EXTRA project/pyproject.toml requests
```
#### Combine verbose and all
Output all imports, including the correct ones with file name and line number.
```commandline
> check-dependencies --verbose --all project/src/
OK project/src/data.py:5 pandas
OK project/src/main.py:3 pandas
OK project/src/plotting.py:4 pandas
!NA project/src/plotting.py:5 matplotlib
OK project/src/plotting.py:6 numpy
### Dependencies in config file not used in application:
# Config file: project/pyproject.toml
+EXTRA requests
```
### Configuration
The configuration is read from `pyproject.toml` file. The configuration file
supports two entries, `[tool.check_dependencies.extra-requirements]` that can be used to
add extra dependencies to the list of requirements to be treated as existing
requirements.
The second entry, `[tool.check_dependencies.ignore-requirements]` does the opposite, it will
ignore extra requirements that are not used in the application.
```toml
[tool.check_dependencies]
known-missing = [
undeclared_package,
another_package
]
known-extra = [
package_as_extra_for_another_package,
yet_another_package
]
```
#### Exit code
- 0: No missing or superfluous dependencies found
- 2: Missing (used, but not declared in pyproject.toml) dependencies found
- 4: Extra (declared in pyproject.toml, but unused) dependencies found
- 6: Both missing and superfluous dependencies found
- 8: Could not find associated pyproject.toml file
- 1: Another error occurred
## Development
Feature requests and merge requests are welcome. For major changes, please open an
issue first to discuss what you would like to change.
Please make sure to update tests as appropriate. Also with this project, I want
to keep the dependencies to a minimum, so please keep that in mind when proposing
a change. Currently, the only dependencies is `toml` to support Python 3.10 and below.
### Coding Standards
| **Type** | Package | Comment |
|---------------|----------|---------------------------------|
| **Linter** | `black` | Also for auto-formatted modules |
| **Logging** | `logger` | Minimize additional packages |
| **Packaging** | `poetry` | |
| **Tests** | `pytest` | |
| **Typing** | `mypy` | Type all methods |
| **Linting** | `flake8` | |
| **Imports** | `isort` | |
Raw data
{
"_id": null,
"home_page": "https://github.com/schollm/check-dependencies",
"name": "check-dependencies",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "packaging, development, requirements, dependencies",
"author": "Micha Scholl",
"author_email": "schollm-git@gmx.com",
"download_url": "https://files.pythonhosted.org/packages/36/49/552c87b45759b427d210c1029896d3269d92650dc281e282630a2117d454/check_dependencies-0.10.2.tar.gz",
"platform": null,
"description": "# Check Dependencies\nCheck all imports from python files and compares them against the declared imports of a pyproject dependency list of expected imports. \nIt can be used as a stand-alone or as part of a CI/CD to check if an application has all the necessary, but no superfluous imports.\n\n## Usage\n```commandline\nusage: check-dependencies [-h] [--include-extra] [--verbose] [--all] [--missing MISSING] [--extra EXTRA] file_name [file_name ...]\n\nFind undeclared and unused (or all) imports in Python files\n\npositional arguments:\n file_name Python Source file to analyse\n\noptional arguments:\n -h, --help show this help message and exit\n --include-extra Include dev dependencies\n --verbose Show every import of a package\n --all Show all imports (including correct ones)\n --missing MISSING Comma seperated list of requirements known to be missing. Assume they are part of the requirements\n --extra EXTRA Comma seperated list of requirements known to not be imported. Assume they are not part of the requirements```\n```\n\n### Output\nThe output is a list of imports with a prefix indicating the status of the import.\n- `!` - Undeclared import\n- `+` - Extra import, declared in pyproject.toml, but not used in the file\n- ` ` - Correct import (only shown with `--all`)\n\n**In case of `--verbose`**, the output is a list of all imports in the file, prefixed with:\n- `!NA` - Undeclared import\n- `+EXTRA` - Extra import, declared in pyproject.toml, but not used in the file\n- ` OK` - Correct import (only shown with `--all`)\n\nAdditionally, each import is prefixed with the file name and line number\nwhere it is imported.\n\n\n### Examples\n#### Basic usage\n```commandline\n> check-dependencies project/src/\n pandas\n! matplotlib\n numpy\n+ requests\n```\n\n#### Output all dependencies\nOutput all dependencies, including the correct ones.\n```commandline\n> check-dependencies --all project/src/\n pandas\n! matplotlib\n numpy\n+ requests\n```\n#### Verbose output\nOutput each erroneous import and extra dependency with cause, file name and line number.\n```commandline\n> check-dependencies --verbose project/src/\n!NA matplotlib project/src/main.py:4\n+EXTRA project/pyproject.toml requests\n```\n\n#### Combine verbose and all\nOutput all imports, including the correct ones with file name and line number.\n```commandline\n> check-dependencies --verbose --all project/src/\n OK project/src/data.py:5 pandas\n OK project/src/main.py:3 pandas\n OK project/src/plotting.py:4 pandas\n!NA project/src/plotting.py:5 matplotlib\n OK project/src/plotting.py:6 numpy\n\n### Dependencies in config file not used in application:\n# Config file: project/pyproject.toml\n+EXTRA requests\n```\n\n### Configuration\nThe configuration is read from `pyproject.toml` file. The configuration file\nsupports two entries, `[tool.check_dependencies.extra-requirements]` that can be used to\nadd extra dependencies to the list of requirements to be treated as existing\nrequirements.\nThe second entry, `[tool.check_dependencies.ignore-requirements]` does the opposite, it will\nignore extra requirements that are not used in the application.\n\n```toml\n[tool.check_dependencies]\nknown-missing = [\n undeclared_package,\n another_package\n]\nknown-extra = [\n package_as_extra_for_another_package,\n yet_another_package\n]\n```\n\n#### Exit code\n- 0: No missing or superfluous dependencies found\n- 2: Missing (used, but not declared in pyproject.toml) dependencies found\n- 4: Extra (declared in pyproject.toml, but unused) dependencies found\n- 6: Both missing and superfluous dependencies found\n- 8: Could not find associated pyproject.toml file\n- 1: Another error occurred\n\n## Development\nFeature requests and merge requests are welcome. For major changes, please open an \nissue first to discuss what you would like to change.\n\nPlease make sure to update tests as appropriate. Also with this project, I want\nto keep the dependencies to a minimum, so please keep that in mind when proposing\na change. Currently, the only dependencies is `toml` to support Python 3.10 and below.\n\n### Coding Standards\n\n| **Type** | Package | Comment |\n|---------------|----------|---------------------------------|\n| **Linter** | `black` | Also for auto-formatted modules |\n| **Logging** | `logger` | Minimize additional packages |\n| **Packaging** | `poetry` | |\n| **Tests** | `pytest` | |\n| **Typing** | `mypy` | Type all methods |\n| **Linting** | `flake8` | |\n| **Imports** | `isort` | |\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Check dependencies of a python project against pyproject.toml requirements",
"version": "0.10.2",
"project_urls": {
"Bug Tracker": "https://github.com/schollm/check-dependencies/issues",
"Documentation": "https://github.com/schollm/check-dependencies/blob/main/README.md",
"Homepage": "https://github.com/schollm/check-dependencies",
"Repository": "https://github.com/schollm/check-dependencies"
},
"split_keywords": [
"packaging",
" development",
" requirements",
" dependencies"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2f5cc9d5ecc06a55ca90c49f0a51809a3f53b601196e959277120c82dd88b618",
"md5": "7288ec8d10a5d7957da55415eac4b901",
"sha256": "a58b15ae155e3273b979322a08fa5bbe045db5bfb1ec4cdb066d430a41a4535a"
},
"downloads": -1,
"filename": "check_dependencies-0.10.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7288ec8d10a5d7957da55415eac4b901",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 10472,
"upload_time": "2024-06-26T07:36:27",
"upload_time_iso_8601": "2024-06-26T07:36:27.458004Z",
"url": "https://files.pythonhosted.org/packages/2f/5c/c9d5ecc06a55ca90c49f0a51809a3f53b601196e959277120c82dd88b618/check_dependencies-0.10.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3649552c87b45759b427d210c1029896d3269d92650dc281e282630a2117d454",
"md5": "447fea1c12cd1b95a5d1d6fe566d9daa",
"sha256": "69874089eb605a13e8e881172f1ae5ec2b088a02a83a33b380163bc1d6fb404f"
},
"downloads": -1,
"filename": "check_dependencies-0.10.2.tar.gz",
"has_sig": false,
"md5_digest": "447fea1c12cd1b95a5d1d6fe566d9daa",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 9972,
"upload_time": "2024-06-26T07:36:29",
"upload_time_iso_8601": "2024-06-26T07:36:29.119160Z",
"url": "https://files.pythonhosted.org/packages/36/49/552c87b45759b427d210c1029896d3269d92650dc281e282630a2117d454/check_dependencies-0.10.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-26 07:36:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "schollm",
"github_project": "check-dependencies",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "check-dependencies"
}