Skip to main content

Python Dependency Check Tool

Project description

dep-check

image CircleCI

dep-check is a Python dependency checker. It lets you write rules to define what each module can import, dep-check can then parse each source file in your project to verify everything is in order. You can also use it to draw a dependency graph for your project.

graph_example

Free software: MIT license

Supported languages

By default, the tool assumes it's operating on a Python project.

Installation

To install dep-check, run this command:

pip install dep-check

This is the preferred method to install dep-check, as it always installs the most recent stable release.

If you don't have pip installed, this Python installation guide can guide you through the process.

You can also see other installation methods.

Usage

Build your configuration file

dep_check build <ROOT_DIR> [-o config.yaml] [--lang LANG]
Argument Description Optional Default
ROOT_DIR The project root directory, containing the source files :x: N/A
-o / --output The output file (yaml format) :heavy_check_mark: dependency_config.yaml
--lang The language the project is written in :heavy_check_mark: python

By default, any import is forbidden (denylist). The configuration is an allowlist.

This command lists the imports of each module in a yaml file. Use this file as a starting point to write dependency rules on which module can import what, using wildcards.

Here is an example of additional rules added to the initial yaml file:

---

dependency_rules:
'*':
    - dep_check.models
    - dep_check.dependency_finder
    - dep_check.checker

dep_check.infra.io:
    - dep_check.use_cases%
    - jinja2
    - yaml

dep_check.infra.std_lib_filter:
    - dep_check.use_cases.interfaces

dep_check.use_cases%:
    - dep_check.use_cases.app_configuration
    - dep_check.use_cases.interfaces

dep_check.main:
    - '*'

lang: python
local_init: false
  • Use * to include any string, even an empty one.
  • Use % after a module name (e.g. my_module%) to include this module along with its sub-modules.

Here, for instance, the configuration file defines that dep_check.infra.io can import dep_check.use_cases, along with dep_check.use_cases.build, dep_check.use_cases.check, and so on.

To see all the supported wildcards, check the User Manual.

Check your configuration

Once your config file is ready, run

dep_check check <ROOT_DIR> [-c config.yaml] [--lang LANG]
Argument Description Optional Default
ROOT_DIR The project root directory, containing the source files :x: N/A
-c / --config The yaml file in which you wrote the dependency rules :heavy_check_mark: dependency_config.yaml
--lang The language the project is written in :heavy_check_mark: python

The command reads the configuration file, and parses each source file. It then verifies, for each file, that every import is authorized by the rules defined in the configuration file.

When it's done, it writes a report on the console, listing import errors by module and unused rules:

report

Draw a dependency graph

You need to have graphviz installed to run this command

dep_check graph <ROOT_DIR> [-o file.svg/dot] [-c config.yaml] [--lang LANG]
Argument Description Optional Default
ROOT_DIR The project root directory, containing the source files :x: N/A
-o / --output The output file you want (svg or dot format) :heavy_check_mark: dependency_graph.svg
-c / --config The graph configuration file containing options (yaml format) :heavy_check_mark: None
--lang The language the project is written in :heavy_check_mark: python

Note : if you generate a svg file, a dot file is also created in /tmp/graph.dot

A lot of options are available to customize your graph (hide some modules, add layers etc.). Check the User Manual for more information.

Contributing

If you want to make a contribution, be sure to follow the Contribution guide.

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template

Authors & contributors

Check out all the Authors and contributors of this project.

CHANGELOG

3.0.1(2023-03-28)

BUGFIX

  • Use OrderedSet instead of set, in order to have a deterministic runs

3.0.0(2022-12-21)

MAJOR

  • Update python support, tested on 3.9, 3.10, 3.11.
  • Add support of dynamic rules (see doc)
  • Support multiple files and directories in parameters.
  • Drop error_on_unused option (replaced by unused_level).
  • Add unused_level option to choose the raise an error when unused rules are detected.

2.0.1(2022-06-02)

MAJOR

  • Drop go compatibility.
  • Update python support, tested on 3.8, 3.9, 3.10.
  • Add error_on_unused option to raise an error when unused rules are detected.

1.0.3(2019-08-26)

BUGFIX

  • The tool now works correctly with Go.

1.0.0 (2019-08-20)

Modified

  • The tool now writes a full report, displaying the number of errors, warnings and files.
  • The commands have been simplified, to avoid too long command lines

Added

  • The tool now supports Go language
  • Better documentation

0.2.0 (2019-07-16)

Added

  • You can now add layers to your graph.
  • The tool now warns you if a rule in your configuration file is not used.

0.1.0 (2019-07-09)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dep_check-3.1.0.tar.gz (102.3 kB view details)

Uploaded Source

Built Distribution

dep_check-3.1.0-py2.py3-none-any.whl (20.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file dep_check-3.1.0.tar.gz.

File metadata

  • Download URL: dep_check-3.1.0.tar.gz
  • Upload date:
  • Size: 102.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.6

File hashes

Hashes for dep_check-3.1.0.tar.gz
Algorithm Hash digest
SHA256 7a0c2c3d711b2802b983cccb413b40787f4e33f78e1c02f8e6d48837423fda26
MD5 30dc66bc15e9e08f53cdf3c55a8343c7
BLAKE2b-256 c84ef1710ef9c0056135e932dd0ff46e3072f05f40a348b0b7dd3edf4d5ff5a3

See more details on using hashes here.

File details

Details for the file dep_check-3.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: dep_check-3.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.6

File hashes

Hashes for dep_check-3.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f2ac905201cc91dd9843c07b6aa3e5be535105f8d1ce9631b98956f956bfe7b4
MD5 d1836dd6eb17d72218e6f3763d067a49
BLAKE2b-256 e3a3e68956c6a5f54a03637ccee27bdf19d83f352e9a7917566e570c8179c7ae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page