flake8-requirements is a plugin for the flake8 static analysis tool that checks for missing or unused package requirements in Python projects. It helps maintain clean and accurate dependency lists by comparing imported modules against entries in requirements files (e.g., `requirements.txt`) or `pyproject.toml`. The current version is 2.3.0, and its release cadence is generally tied to bug fixes, new features, or compatibility updates for `flake8`.
pip install flake8-requirementsNo compatibility data collected yet for this library.
After installing `flake8-requirements`, it automatically integrates with `flake8`. Simply run `flake8` in your project directory. The plugin will check your imports against your `requirements.txt` (or a file specified by `--requirements-file`) and report missing (R001) or unused (R002) dependencies.
Ensure your project runs on Python 3.8 or newer. Update your flake8 configuration to use `--always-assume-pip-installed` if you previously used the old flag. Review your dependencies for any R003 issues, which must now be handled manually.
Always specify the correct path to your requirements file using the `--requirements-file` option (e.g., `flake8 --requirements-file requirements/prod.txt`) or ensure your `pyproject.toml` is configured correctly if using that format.
For packages that are legitimately required but trigger R002, consider adding them to a development-specific requirements file that is not checked, or ignore the specific R002 error for those packages if you're certain they are needed.
Simplify complex requirements entries where possible. For advanced cases, you might need to manually verify the dependencies or use the `--always-assume-pip-installed` option carefully. Check the project's GitHub issues for known parsing limitations.
Add `<package_name>` to your `requirements.txt` (or equivalent file) or ensure that the correct requirements file is being checked with `--requirements-file`.
Verify if `<package_name>` is truly unused. If so, remove it from your requirements file. If it's used indirectly (e.g., via a framework, dev tool, or as a plugin), you may need to ignore this specific error or reconsider your dependency strategy.
Examine the requirements file (especially the line indicated by the error if available) and correct any syntax errors or non-standard entries. Refer to `pip`'s documentation on requirements file format.
Create a `requirements.txt` file in your project's root directory, or use the `--requirements-file path/to/your/reqs.txt` option to point to the correct file location and name.