Package: pip-check-reqs
pip-check-reqsIt happens: you start using a module in your project and it works and you
don’t realise that it’s only being included in yourvirtualenvbecause
it’s a dependency of a package you’re using. pip-missing-reqs finds those
modules so you can include them in therequirements.txtfor 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.pyBasic usage, running in your project directory:<activate virtualenv for your project>
pip-missing-reqs --ignore-file=sample/tests/* sampleThis 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/* sampleThis would find anything that is listed in requirements.txt but that is not
imported by sample.Sample tox.ini configurationTo 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/* sampleExcluding test files (or others) from this checkYour 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-fileoption (shorthand is-f). Multiple instances of the option are allowed.Excluding modules from the checkIf 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.* sampleUsing pyproject.toml instead of requirements.txtIf your project usespyproject.tomlinstead ofrequirements.txt, you can
use an external tool likepdmto convert it torequirements.txt:# requires `pip install pdm`
pdm export --pyproject > requirements.txtThen you can usepip-missing-reqsandpip-extra-reqsas usual.With Thanks ToJosh 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 History2.5.2Performance improvements.Add preliminary support for Windows.2.5.1Fix an issue with importing__main__.Fix an issue with importing packages with periods in their names.2.5.0Support Python 3.10.Remove support for Python 3.8.Bumppiprequirement to 23.2.2.4.4Bumppackagingrequirement to >= 20.5. Older versions ofpip-check-reqsmay be broken with the previously-specified version requirements.2.4.3Improves performance on Python 3.11.2.4.2Added support for Python 3.11.Addedpython_requiresto metadata; from now on, releases ofpip-check-reqsare marked as compatible with Python 3.8.0 and up.Made–versionflag show interpretter version and path to the package which
pip-check-reqs is running from, similar to information shown bypip
–version.-Vis now an alias of–version.2.3.2Fixed support for pip < 21.32.3.1Fixed–skip-incompatibleskipping other requirements too.Support pip >= 21.32.3.0Support pip >= 21.2.12.2.2AST parsing failures will now report tracebacks with a proper filename for
the parsed frame, instead of<unknown>.2.2.1Python source is now always read using utf-8, even if default encoding for
reading files is set otherwise.2.2.0Added–skip-incompatibleflag topip-extra-reqs, which makes it ignore
requirements with environment markers that are incompatible with the current
environment.Added–requirements-fileflag topip-extra-reqsandpip-missing-reqscommands. 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-dand-vflags.2.1.1Bug 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.0Remove 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.1handled removal of normalize_name from pip.utilshandle packages with no files2.0renamed package to pip_check_reqsadded tool pip-extra-reqs to find packages installed but not used
(contributed by Josh Hesketh)1.2.1relax requirement to 6.0+1.2.0bumped pip requirement to 6.0.8+updated use of pip internals to match that version1.1.9test fixes and cleanupremove hard-coded simplejson debugging behaviour1.1.8use os.path.realpath to avoid symlink craziness on debian/ubuntu1.1.7tweak to debug output1.1.6add debug (very verbose) run output1.1.5add header to output to make it clearer when in a larger test runfix tests and self-test1.1.4add –versionremove debug print from released code lol1.1.3fix program to generate exit code useful for testing1.1.2corrected version of vendored search_packages_info() from piphandle relative imports1.1.1fixed handling of import from __future__self-tested and added own requirements.txtcleaned 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 released1.1.0implemented –ignore-module