So you want to help out? Awesome. Go you!
We use GitHub. To get started I'd suggest visiting https://guides.github.com/
Please make sure you system has the following:
- Python 3.8.0 or greater
- git cli client
Also ensure you can authenticate with GitHub via SSH Keys or HTTPS.
Lets now cd to where we want the code and clone the repo:
Remember to fork the repo for your PR via the UI or other means (cli).
cd somewheregit clone git@github.com:YOUR_USERNAME/flake8-bugbear.git
One way to develop and install all the dependencies is to use a venv.
- Lets create one and upgrade
pip
python3 -m venv /path/to/venv
/path/to/venv/bin/pip install --upgrade pip setuptools wheel- Then we install flake8-bugbear with the dev dependencies
cd flake8-bugbear
/path/to/venv/bin/pip install -e '.[dev]'flake8-bugbear has a test runner that will go through all files in tests/eval_files/, run them through the linter, and check that they emit the appropriate error messages.
The expected errors are specified by adding comments on the line where the error is expected. The format consists of the error code, followed by a comma-separated list of the col_offset as well as vars that are used when str.formating the full error message.
x = ++n # B002: 4
try:
...
except* (ValueError,): # B013: 0, "ValueError", "*"
...The error code should be in the error_codes dict, and the other values are eval'd as if in a tuple and should be valid python objects. (I.e. remember to quote strings)
You can also specify options to be passed to BugBearChecker with an # OPTIONS comments
# OPTIONS: extend_immutable_calls=["fastapi.Depends", "fastapi.Query"]
# OPTIONS: classmethod_decorators=["mylibrary.makeclassmethod", "validator"], select=["B902"]If you specify a python version somewhere in the file name with _pyXX, the file will be skipped on smaller versions. Otherwise the name has no impact on the test, and you can test multiple errors in the same file.
The infrastructure is based on the test runner in https://github.com/python-trio/flake8-async which has some additional features that can be pulled into flake8-bugbear when desired.
flake8-bugbear uses coverage to run standard unittest tests.
/path/to/venv/bin/coverage run -m pytest tests/test_bugbear.pyYou can also use tox to test with multiple different python versions, emulating what the CI does.
/path/to/venv/bin/toxwill by default run all tests on python versions 3.10 through 3.14. If you only want to test a specific version you can specify the environment with -e
/path/to/venv/bin/tox -e py313We format the code with black and isort. You can run those using pre-commit.
pre-commit run --all-filesOr you install the pre-commit hooks to run on every commit:
pre-commit install