Metadata-Version: 2.1
Name: check-requirements-txt
Version: 1.2.2
Summary: Check the missing packages in requirements.txt
Project-URL: Documentation, https://github.com/ferstar/check-requirements-txt#readme
Project-URL: Issues, https://github.com/ferstar/check-requirements-txt/issues
Project-URL: Source, https://github.com/ferstar/check-requirements-txt
Author-email: ferstar <zhangjianfei3@gmail.com>
License-Expression: MIT
License-File: LICENSE.txt
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.8
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 :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.8
Requires-Dist: stdlib-list; python_version < '3.10'
Description-Content-Type: text/markdown

# check-requirements-txt

A tool (and also a pre-commit hook) to automatically check the missing packages in requirements.txt.

[![PyPI - Version](https://img.shields.io/pypi/v/check-requirements-txt.svg)](https://pypi.org/project/check-requirements-txt)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/check-requirements-txt.svg)](https://pypi.org/project/check-requirements-txt)

-----

**Table of Contents**

- [Installation](#Installation)
- [License](#License)

## Installation

First install this package into current python env

```console
pip install check-requirements-txt
```

Then set up `pre-commit` hooks

See [pre-commit](https://github.com/pre-commit/pre-commit) for instructions

Sample `.pre-commit-config.yaml`:

> NOTE: 
> 
> Due to the pre-commit isolated pyenv runtime, this package can't be act as a normal git repo pre-commit hooks.
> 
> If the project's requirements.txt does not match pattern `*requirement*.txt`, you'll need to specify it.

```yaml
default_stages: [commit]

repos:
  - repo: local
    hooks:
      - id: check-requirements-txt
        name: check-requirements-txt
        description: Check the missing packages in requirements.txt.
        entry: check-requirements-txt
        args: ['--dst_dir', '.', '--ignore', 'pip,whatever,modules,you,want,to,ignore,with,comma,separated']
        language: python
        types: [python]
```

`check-requirements-txt` can be used as a normal cli tool, see `check-requirements-txt --help` for more details.

## Output sample

```shell
Bad import detected: "bs4"
/Users/ferstar/PycharmProjects/xxx_demo/xxx_spider.py:12
Bad import detected: "requests"
/Users/ferstar/PycharmProjects/xxx_demo/xxx_handler.py:17
"numpy" required by: {'numpy', 'scikit-learn', 'tensorflow', 'pandas'}
# NOTE: the output of cli is the total bad import count
~ echo $?
~ 2
```

## License

`check-requirements-txt` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
