Find packages that should or should not be in requirements for a project
Project description
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. This tool finds those modules so
you can include them in the `requirements.txt`_ for the project.
.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/
.. _`requirements.txt`: https://pip.pypa.io/en/latest/user_guide.html#requirements-files
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
.. _`sample project`: https://packaging.python.org/en/latest/tutorial.html#creating-your-own-project
Basic usage, running in your project directory::
<activate virtualenv for your project>
pip-missing-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
Release History
---------------
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
==============
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. This tool finds those modules so
you can include them in the `requirements.txt`_ for the project.
.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/
.. _`requirements.txt`: https://pip.pypa.io/en/latest/user_guide.html#requirements-files
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
.. _`sample project`: https://packaging.python.org/en/latest/tutorial.html#creating-your-own-project
Basic usage, running in your project directory::
<activate virtualenv for your project>
pip-missing-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
Release History
---------------
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
Release history Release notifications | RSS feed
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-1.2.1.tar.gz
(7.2 kB
view details)
File details
Details for the file pip_check_reqs-1.2.1.tar.gz
.
File metadata
- Download URL: pip_check_reqs-1.2.1.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ab421d445f9989fa48ecfedd7d4351b2630d16a03e6a383c4b00af4b3f49473 |
|
MD5 | 8897554de572e84a25e04c5b1a110e3b |
|
BLAKE2b-256 | ca88724dc0a30f5d6078f1dfaa88c54348ebd3009891ad5b9bf5d9194ff32928 |