OpenStack Hacking Guideline Enforcement
Hacking is an OpenStack project that provides a set of Flake8 plugins to enforce the OpenStack Hacking Guidelines for Python code. It helps developers maintain consistent code style and identify common pitfalls specific to the OpenStack development community. The current version is 8.0.0, and it follows a release cadence tied to OpenStack cycles, with updates typically occurring every few months or as new guideline enforcement is required.
Common errors
-
ImportError: No module named 'hacking'
cause Attempting to import `hacking` directly into a Python script.fix`hacking` is a `flake8` plugin, not a library for direct import. Ensure it's installed (`pip install hacking`) and then run `flake8` from your terminal. -
flake8: error: unrecognized arguments: --select H301
cause Trying to explicitly enable or select `hacking` checks (e.g., H301) via command-line arguments, which are already integrated by `hacking`.fixRemove `--select Hxxx` arguments. `hacking` checks are automatically included. If you need to enable/disable specific checks, use a `.flake8` or `pyproject.toml` configuration file (e.g., `[flake8]\nignore = H301` to ignore).
Warnings
- breaking `hacking` version 8.0.0 and newer requires Python 3.10 or higher. Projects on older Python versions must use an older `hacking` release.
- breaking `hacking` version 8.0.0 and newer requires `flake8` version 6.0.0 or higher. Older `flake8` versions are incompatible.
- gotcha The `hacking` library is a `flake8` plugin and is not designed for direct import and usage in Python code. Its checks are automatically discovered and applied by `flake8`.
Install
-
pip install flake8 hacking
Quickstart
mkdir my_project cd my_project echo "def my_func( value ):\n # H301: no space after parameters\n pass" > app.py pip install flake8 hacking flake8 app.py