-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch out tox for nox #2857
Switch out tox for nox #2857
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,44 @@ | ||
.venv | ||
# Testing, packaging, and documentation artifacts | ||
.coverage | ||
.coverage.* | ||
_build | ||
.DS_Store | ||
.vscode | ||
docs/_static/pypi.svg | ||
.tox | ||
__pycache__ | ||
|
||
# Packaging artifacts | ||
black.egg-info | ||
black.dist-info | ||
docs/_build/ | ||
docs/build/ | ||
build/ | ||
dist/ | ||
black.egg-info | ||
black.dist-info/ | ||
pip-wheel-metadata/ | ||
.eggs | ||
.eggs/ | ||
wheels/ | ||
|
||
src/_black_version.py | ||
.idea | ||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Virtual environments | ||
env | ||
venv | ||
.env | ||
.venv | ||
.nox | ||
.tox | ||
|
||
# Caches / temporary files | ||
.mypy_cache/ | ||
.dmypy.json | ||
*.swp | ||
.hypothesis/ | ||
venv/ | ||
.ipynb_checkpoints/ | ||
__pycache__/ | ||
|
||
# Black autogenerated files | ||
docs/_static/pypi.svg | ||
src/_black_version.py | ||
|
||
# Personal developer files | ||
.vscode/ | ||
.editorconfig | ||
.DS_Store | ||
.idea |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,65 +7,141 @@ An overview on contributing to the _Black_ project. | |||||||||||||||||
Development on the latest version of Python is preferred. As of this writing it's 3.9. | ||||||||||||||||||
You can use any operating system. | ||||||||||||||||||
|
||||||||||||||||||
Install development dependencies inside a virtual environment of your choice, for | ||||||||||||||||||
example: | ||||||||||||||||||
Most development tasks are automated by [nox][nox] which automatically creates virtual | ||||||||||||||||||
environments and running the right commands. You'll most likely run the test suite, | ||||||||||||||||||
build docs, etc. using nox. Often, you can run `python -m pip install nox` to install | ||||||||||||||||||
and use it. | ||||||||||||||||||
|
||||||||||||||||||
```{tip} | ||||||||||||||||||
If you're on Linux or MacOS you might want to use [pipx][pipx] to install nox (and | ||||||||||||||||||
optionally pre-commit) to avoid interfering with the system Python installation. | ||||||||||||||||||
|
||||||||||||||||||
Alternatively install them into the virtual environment you'll be setting up below. | ||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
### Running black from source tree | ||||||||||||||||||
|
||||||||||||||||||
To run the `black` executable from your source tree during development, install _Black_ | ||||||||||||||||||
locally using editable installation (inside a virtual environment). You can then invoke | ||||||||||||||||||
your local source tree _Black_ normally. | ||||||||||||||||||
|
||||||||||||||||||
**Linux / MacOS** | ||||||||||||||||||
|
||||||||||||||||||
```console | ||||||||||||||||||
$ python3 -m venv .venv | ||||||||||||||||||
$ source .venv/bin/activate | ||||||||||||||||||
(.venv)$ pip install -r test_requirements.txt | ||||||||||||||||||
(.venv)$ pip install -e .[d] | ||||||||||||||||||
(.venv)$ pre-commit install | ||||||||||||||||||
(.venv)$ pip install -e .[d,jupyter] | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about creating a
Suggested change
The simple quotes are much more likely to work, bash/zsh will likely try to do some completion magic otherwise. |
||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
Before submitting pull requests, run lints and tests with the following commands from | ||||||||||||||||||
the root of the black repo: | ||||||||||||||||||
**Windows** | ||||||||||||||||||
|
||||||||||||||||||
```console | ||||||||||||||||||
# Linting | ||||||||||||||||||
(.venv)$ pre-commit run -a | ||||||||||||||||||
$ py -m venv .venv | ||||||||||||||||||
$ .venv\Scripts\activate | ||||||||||||||||||
(.venv)$ python -m pip install -e .[d,jupyter] | ||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
### Running linters | ||||||||||||||||||
|
||||||||||||||||||
# Unit tests | ||||||||||||||||||
(.venv)$ tox -e py | ||||||||||||||||||
_Black_ uses [pre-commit][pre-commit] to manage linting. It has been configured with a | ||||||||||||||||||
list of _pre-commit hooks_ that each check a certain aspect of the codebase. | ||||||||||||||||||
|
||||||||||||||||||
# Optional Fuzz testing | ||||||||||||||||||
(.venv)$ tox -e fuzz | ||||||||||||||||||
```console | ||||||||||||||||||
$ nox -s lint | ||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
### News / Changelog Requirement | ||||||||||||||||||
You can also setup pre-commit to automatically run before committing. First, install | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
pre-commit similarly to nox and install the Git pre commit hook: | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
`Black` has CI that will check for an entry corresponding to your PR in `CHANGES.md`. If | ||||||||||||||||||
you feel this PR does not require a changelog entry please state that in a comment and a | ||||||||||||||||||
maintainer can add a `skip news` label to make the CI pass. Otherwise, please ensure you | ||||||||||||||||||
have a line in the following format: | ||||||||||||||||||
```console | ||||||||||||||||||
$ python -m pip install pre-commit | ||||||||||||||||||
$ pre-commit install | ||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
```md | ||||||||||||||||||
- `Black` is now more awesome (#X) | ||||||||||||||||||
### Running tests | ||||||||||||||||||
|
||||||||||||||||||
Before opening a pull request that involves code, please run the test suite to verify | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm actually not sure we should recommend this. Local tests are often annoying and finicky to set up, so why not just rely on our CI? |
||||||||||||||||||
the changes didn't break anything. | ||||||||||||||||||
|
||||||||||||||||||
```console | ||||||||||||||||||
$ nox -s tests-3.9 | ||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
Note that X should be your PR number, not issue number! To workout X, please use | ||||||||||||||||||
[Next PR Number](https://ichard26.github.io/next-pr-number/?owner=psf&name=black). This | ||||||||||||||||||
is not perfect but saves a lot of release overhead as now the releaser does not need to | ||||||||||||||||||
go back and workout what to add to the `CHANGES.md` for each release. | ||||||||||||||||||
The example above runs tests against Python 3.9. You can also use other versions like | ||||||||||||||||||
`3.7` and `pypy3`. If you don't specify a Python version, nox will look for Python | ||||||||||||||||||
installations for all the versions _Black_ supports and run the suite for each! | ||||||||||||||||||
|
||||||||||||||||||
### Style Changes | ||||||||||||||||||
By default, the test suite is ran with coverage and parallelization enabled, but you can | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
disable them if they're causing you trouble: | ||||||||||||||||||
|
||||||||||||||||||
```console | ||||||||||||||||||
# to disable parallelization | ||||||||||||||||||
$ nox -s tests-3.9 -- --no-xdist | ||||||||||||||||||
# to disable coverage | ||||||||||||||||||
$ nox -s tests-3.9 -- --no-cov | ||||||||||||||||||
# to disable both | ||||||||||||||||||
$ nox -s tests-3.9 -- --no-cov --no-xdist | ||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
If you need to run the test suite manually, install the test dependencies in the virtual | ||||||||||||||||||
environment you've [previously set up](#running-black-from-source-tree) and then run | ||||||||||||||||||
pytest: | ||||||||||||||||||
|
||||||||||||||||||
**Linux / MacOS** | ||||||||||||||||||
|
||||||||||||||||||
```console | ||||||||||||||||||
(.venv)$ pip install -r tests/requirements.txt | ||||||||||||||||||
(.venv)$ pytest | ||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
**Windows** | ||||||||||||||||||
|
||||||||||||||||||
```console | ||||||||||||||||||
(.venv)$ python -m pip install -r tests\requirements.txt | ||||||||||||||||||
(.venv)$ pytest | ||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
### Building documentation | ||||||||||||||||||
|
||||||||||||||||||
If you make changes to docs, you can test they still build locally too. | ||||||||||||||||||
|
||||||||||||||||||
```console | ||||||||||||||||||
$ nox -s docs | ||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
If you are making many changes to docs, you may find it helpful to use the `docs-live` | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this sounds awesome |
||||||||||||||||||
session. Each time you make a change to the docs they're rebuilt and the browser tab | ||||||||||||||||||
reloads. | ||||||||||||||||||
|
||||||||||||||||||
```console | ||||||||||||||||||
$ nox -s docs-live | ||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
## Style changes | ||||||||||||||||||
|
||||||||||||||||||
If a change would affect the advertised code style, please modify the documentation (The | ||||||||||||||||||
_Black_ code style) to reflect that change. Patches that fix unintended bugs in | ||||||||||||||||||
formatting don't need to be mentioned separately though. If the change is implemented | ||||||||||||||||||
with the `--preview` flag, please include the change in the future style document | ||||||||||||||||||
instead and write the changelog entry under a dedicated "Preview changes" heading. | ||||||||||||||||||
with the `--preview` flag, please include the change in | ||||||||||||||||||
{doc}`/the_black_code_style/future_style` instead and write the changelog entry under a | ||||||||||||||||||
dedicated "Preview changes" heading. | ||||||||||||||||||
|
||||||||||||||||||
### Docs Testing | ||||||||||||||||||
## Changelog requirement | ||||||||||||||||||
|
||||||||||||||||||
If you make changes to docs, you can test they still build locally too. | ||||||||||||||||||
_Black_ has CI that will check for an entry corresponding to your PR in `CHANGES.md`. If | ||||||||||||||||||
you feel this PR does not require a changelog entry please state that in a comment and a | ||||||||||||||||||
maintainer can add a `skip news` label to make the CI pass. Otherwise, please ensure you | ||||||||||||||||||
have a line in the following format: | ||||||||||||||||||
|
||||||||||||||||||
```console | ||||||||||||||||||
(.venv)$ pip install -r docs/requirements.txt | ||||||||||||||||||
(.venv)$ pip install [-e] .[d] | ||||||||||||||||||
(.venv)$ sphinx-build -a -b html -W docs/ docs/_build/ | ||||||||||||||||||
```md | ||||||||||||||||||
- `Black` is now more awesome (#X) | ||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
Note that X should be your PR number, not issue number! To workout X, please use | ||||||||||||||||||
[Next PR Number](https://ichard26.github.io/next-pr-number/?owner=psf&name=black). This | ||||||||||||||||||
is not perfect but saves a lot of release overhead as now the releaser does not need to | ||||||||||||||||||
go back and workout what to add to the `CHANGES.md` for each release. | ||||||||||||||||||
Comment on lines
+140
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
No need to apologize here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That said, wouldn't it be worth implementing this as a pre-commit script or GHA ? (not necessarily in this PR) "If the diff in CHANGES.md is a single added line, then add |
||||||||||||||||||
|
||||||||||||||||||
## Hygiene | ||||||||||||||||||
|
||||||||||||||||||
If you're fixing a bug, add a test. Run it first to confirm it fails, then fix the bug, | ||||||||||||||||||
|
@@ -77,4 +153,9 @@ any large feature, first open an issue for us to discuss the idea first. | |||||||||||||||||
## Finally | ||||||||||||||||||
|
||||||||||||||||||
Thanks again for your interest in improving the project! You're taking action when most | ||||||||||||||||||
people decide to sit and watch. | ||||||||||||||||||
people decide to sit and watch. If you ever need help feel free to ask on the relevant | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
issue or chat with us in the [Python Discord server](https://discord.gg/RtVdv86PrH). | ||||||||||||||||||
|
||||||||||||||||||
[nox]: https://nox.thea.codes/en/stable/ | ||||||||||||||||||
[pipx]: https://pypa.github.io/pipx/ | ||||||||||||||||||
[pre-commit]: https://pre-commit.com/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.