Metadata-Version: 2.4
Name: pip-check-reqs
Version: 2.5.5
Summary: Find packages that should or should not be in requirements for a project
Author-email: Adam Dangoor <adamdangoor@gmail.com>, Richard Jones <r1chardj0n3s@gmail.com>
Maintainer-email: Adam Dangoor <adamdangoor@gmail.com>, Richard Jones <r1chardj0n3s@gmail.com>
License: The MIT License (MIT)
        
        Copyright (c) 2015 Richard Jones
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Changelog, https://github.com/adamtheturtle/pip-check-reqs/blob/master/CHANGELOG.rst
Project-URL: Homepage, https://github.com/adamtheturtle/pip-check-reqs
Keywords: lint,pip
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Build Tools
Requires-Python: >=3.9
Description-Content-Type: text/x-rst
License-File: LICENSE
Requires-Dist: packaging>=22
Requires-Dist: pip>=23.2
Provides-Extra: dev
Requires-Dist: actionlint-py==1.7.7.23; extra == "dev"
Requires-Dist: mypy==1.15.0; extra == "dev"
Requires-Dist: pyenchant==3.2.2; extra == "dev"
Requires-Dist: pylint==3.3.7; extra == "dev"
Requires-Dist: pyproject-fmt==2.6.0; extra == "dev"
Requires-Dist: pyright==1.1.400; extra == "dev"
Requires-Dist: pyroma==4.2; extra == "dev"
Requires-Dist: pytest==8.3.5; extra == "dev"
Requires-Dist: pytest-cov==6.1.1; extra == "dev"
Requires-Dist: ruamel.yaml==0.18.10; extra == "dev"
Requires-Dist: ruff==0.11.11; extra == "dev"
Dynamic: license-file

|Build Status| |PyPI|

.. |Build Status| image:: https://github.com/r1chardj0n3s/pip-check-reqs/workflows/CI/badge.svg
   :target: https://github.com/r1chardj0n3s/pip-check-reqs/actions
.. |PyPI| image:: https://badge.fury.io/py/pip-check-reqs.svg
   :target: https://badge.fury.io/py/pip-check-reqs

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.

.. _`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

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


Using pyproject.toml instead of requirements.txt
------------------------------------------------

If your project uses ``pyproject.toml``, there are multiple ways to use ``pip-check-reqs`` with it.

One way is to use an external tool to convert ``pyproject.toml`` to ``requirements.txt``::

    # requires `pip install pdm`
    pdm export --pyproject > requirements.txt

    # or, if you prefer uv, `pip install uv`
    uv pip compile --no-deps pyproject.toml > requirements.txt

Then you can use ``pip-missing-reqs`` and ``pip-extra-reqs`` as usual.

Another way is to use a ``requirements.txt`` file within your ``pyproject.toml`` file,
for example with the `setuptools` build backend:

.. code:: toml

   [build-system]
   build-backend = "setuptools.build_meta"
   requires = [
     "setuptools",
   ]

   [project]
   ...
   dynamic = ["dependencies"]

   [tool.setuptools.dynamic]
   dependencies = { file = "requirements.txt" }


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.
