Skip to main content

Find packages that should or should not be in requirements for a project

Project description

Build Status codecov PyPI

pip-check-reqs

It happens: you start using a module in your project and it works and you don’t realise that it’s only being included in your virtualenv because it’s a dependency of a package you’re using. pip-missing-reqs finds those modules so you can include them in the requirements.txt for the project.

Alternatively, you have a long-running project that has some packages in requirements.txt that are no longer actively used in the codebase. The pip-extra-reqs tool will find those modules so you can remove them.

Assuming your project follows a layout like the suggested sample project:

setup.py
setup.cfg
requirements.txt
sample/__init__.py
sample/sample.py
sample/tests/test_sample.py

Basic usage, running in your project directory:

<activate virtualenv for your project>
pip-missing-reqs --ignore-file=sample/tests/* sample
pip-extra-reqs --ignore-file=sample/tests/* sample

This will find all imports in the code in “sample” and check that the packages those modules belong to are in the requirements.txt file.

Additionally it is possible to check that there are no dependencies in requirements.txt that are then unused in the project:

<activate virtualenv for your project>
pip-extra-reqs --ignore-file=sample/tests/* sample

This would find anything that is listed in requirements.txt but that is not imported by sample.

Sample tox.ini configuration

To make your life easier, copy something like this into your tox.ini:

[testenv:pip-check-reqs]
deps=-rrequirements.txt
commands=
    pip-missing-reqs --ignore-file=sample/tests/* sample
    pip-extra-reqs --ignore-file=sample/tests/* sample

Excluding test files (or others) from this check

Your test files will sometimes be present in the same directory as your application source (“sample” in the above examples). The requirements for those tests generally should not be in the requirements.txt file, and you don’t want this tool to generate false hits for those.

You may exclude those test files from your check using the –ignore-file option (shorthand is -f). Multiple instances of the option are allowed.

Excluding modules from the check

If your project has modules which are conditionally imported, or requirements which are conditionally included, you may exclude certain modules from the check by name (or glob pattern) using –ignore-module (shorthand is -m):

# ignore the module spam
pip-missing-reqs --ignore-module=spam sample
# ignore the whole package spam as well
pip-missing-reqs --ignore-module=spam --ignore-module=spam.* sample

With Thanks To

Josh Hesketh – who refactored code and contributed the pip-extra-reqs tool.

Wil Cooley – who handled the removal of normalize_name and fixed some bugs.

Release History

2.3.0

  • Support pip >= 21.2.1

2.2.2

  • AST parsing failures will now report tracebacks with a proper filename for the parsed frame, instead of <unknown>.

2.2.1

  • Python source is now always read using utf-8, even if default encoding for reading files is set otherwise.

2.2.0

  • Added –skip-incompatible flag to pip-extra-reqs, which makes it ignore requirements with environment markers that are incompatible with the current environment.

  • Added –requirements-file flag to pip-extra-reqs and pip-missing-reqs commands. This flag makes it possible to specify a path to the requirements file. Previously, “requirements.txt” was always used.

  • Fixed some of the logs not being visible with -d and -v flags.

2.1.1

  • Bug fix: Though Python 2 support was removed from the source code, the published wheel was still universal. The published wheel now explicitly does not support Python 2. Please use version 2.0.4 for Python 2.

2.1.0

  • Remove support for Python 2. Please use an older version of this tool if you require that support.

  • Remove requirement for setuptools.

  • Support newer versions of pip, including the current version, for more features (20.1.1). Thanks to @Czaki for important parts of this change.

2.0.1

  • handled removal of normalize_name from pip.utils

  • handle packages with no files

2.0 renamed package to pip_check_reqs

  • added tool pip-extra-reqs to find packages installed but not used (contributed by Josh Hesketh)

1.2.1

  • relax requirement to 6.0+

1.2.0

  • bumped pip requirement to 6.0.8+

  • updated use of pip internals to match that version

1.1.9

  • test fixes and cleanup

  • remove hard-coded simplejson debugging behaviour

1.1.8

  • use os.path.realpath to avoid symlink craziness on debian/ubuntu

1.1.7

  • tweak to debug output

1.1.6

  • add debug (very verbose) run output

1.1.5

  • add header to output to make it clearer when in a larger test run

  • fix tests and self-test

1.1.4

  • add –version

  • remove debug print from released code lol

1.1.3

  • fix program to generate exit code useful for testing

1.1.2

  • corrected version of vendored search_packages_info() from pip

  • handle relative imports

1.1.1

  • fixed handling of import from __future__

  • self-tested and added own requirements.txt

  • cleaned up usage to require a file or directory to scan (rather than defaulting to “.”)

  • vendored code from pip 1.6dev which fixes bug in search_packages_info until pip 1.6 is released

1.1.0

  • implemented –ignore-module

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

pip_check_reqs-2.3.0.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

pip_check_reqs-2.3.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file pip_check_reqs-2.3.0.tar.gz.

File metadata

  • Download URL: pip_check_reqs-2.3.0.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for pip_check_reqs-2.3.0.tar.gz
Algorithm Hash digest
SHA256 12c676b870c0a8fc0ed46e71370e2e58bc98ad4845baa5c3e2fe516ef2d962fa
MD5 2aae9a43a01229ee9d7a902ffd9d574c
BLAKE2b-256 cdb99e80a40850fd8e742a2e77ae3297c4a4ebafb38081f07b2e521bb9702e4b

See more details on using hashes here.

File details

Details for the file pip_check_reqs-2.3.0-py3-none-any.whl.

File metadata

  • Download URL: pip_check_reqs-2.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for pip_check_reqs-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b7a6b23c5dcb2577b4b2eec8bfeb2f0964b829ecb579b1534b76187e70ab645
MD5 801213b539b1603de18c1a5b478dd29d
BLAKE2b-256 1425c9d85cb6318240c3218ad7262fa3b817e6ba322fe9c584a7d6381b1122da

See more details on using hashes here.

Supported by

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