Usage

Configuration

dep-checker can be configured via the [tool.dep_checker] table of pyproject.toml.
The configuration can also be placed in the [dep_checker] section of tox.ini or setup.cfg.

Changed in version 0.5.0: Added support for pyproject.toml

allowed_unused

List of requirements which are allowed to be unused in the source code.

Examples:

# pyproject.toml
[tool.dep_checker]
allowed_unused = ["pytest", "sphinx"]
# tox.ini / setup.cfg
[dep_checker]
allowed_unused = pytest, sphinx
name_mapping

Mapping of requirement names (e.g. “biopython”) to the names of packages they provide (e.g. “Bio”).

New in version 0.4.1.

Examples:

# pyproject.toml
[tool.dep_checker.name_mapping]
biopython = "Bio"
# tox.ini / setup.cfg
[dep_checker]
name_mapping =
    biopython = Bio
namespace_packages

List of namespace packages, such as ruamel.yaml.

This currently only handles imports in the form import namespace.package or from namespace.package import object, but not from namespace import package.

New in version 0.4.1.

Examples:

# pyproject.toml
[tool.dep_checker]
namespace_packages = ["ruamel.yaml", "jaraco.docker"]
# tox.ini / setup.cfg
[dep_checker]
namespace_packages = ruamel.yaml, jaraco.docker

Ignoring imports that aren’t listed as requirements

To ignore lines where packages are imported, but aren’t listed in requirements.txt, use # nodep.

For example:

# 3rd party
import pytest  # nodep

New in version 0.4.1.

Command Line

Tool to check all requirements are actually required.

dep-checker [OPTIONS] PKG_NAME

Options

--req-file <FILENAME>

The requirements file.

-a, --allowed-unused <allowed_unused>

Requirements which are allowed to be unused in the source code.

-d, --work-dir <work_dir>

The directory to find the source of the package in. Useful with the src/ layout.

--colour, --no-colour

Whether to use coloured output.

Arguments

PKG_NAME

Required argument.

As a pre-commit hook

dep-checker can also be used as a pre-commit hook. To do so, add the following to your .pre-commit-config.yaml file:

- repo: https://github.com/python-coincidence/dep_checker
  rev: 0.8.0
  hooks:
  - id: dep_checker
    args:
    - <PKG_NAME>

<PKG_NAME> should be replaced with the name of the package to check, e.g. consolekit:

- repo: https://github.com/python-coincidence/dep_checker
  rev: 0.8.0
  hooks:
  - id: dep_checker
    args:
    - consolekit