Skip to content
Permalink
Browse files

Add black config to pyproject.toml (#3493)

* chore: add black config to pyproject.toml

* enhance: make files will now use settings from pyproject.toml

* docs: update CONTRIBUTING.md
  • Loading branch information
jack1142 committed Feb 8, 2020
1 parent 42a4d10 commit 84870f2fa2d9e0606552d94d66f0644fe15542d0
Showing with 25 additions and 6 deletions.
  1. +2 −2 .github/CONTRIBUTING.md
  2. +2 −2 Makefile
  3. +2 −2 make.bat
  4. +19 −0 pyproject.toml
@@ -79,7 +79,7 @@ If you're not on Windows, you should also have GNU make installed, and you can o
**Note:** If you're comfortable with setting up virtual environments yourself and would rather do it manually, just run `pip install -Ur tools/dev-requirements.txt` after setting it up.

### 4.2 Testing
We've recently started using [tox](https://github.com/tox-dev/tox) to run all of our tests. It's extremely simple to use, and if you followed the previous section correctly, it is already installed to your virtual environment.
We're using [tox](https://github.com/tox-dev/tox) to run all of our tests. It's extremely simple to use, and if you followed the previous section correctly, it is already installed to your virtual environment.

Currently, tox does the following, creating its own virtual environments for each stage:
- Runs all of our unit tests with [pytest](https://github.com/pytest-dev/pytest) on python 3.8 (test environment `py38`)
@@ -95,7 +95,7 @@ Your PR will not be merged until all of these tests pass.
### 4.3 Style
Our style checker of choice, [black](https://github.com/ambv/black), actually happens to be an auto-formatter. The checking functionality simply detects whether or not it would try to reformat something in your code, should you run the formatter on it. For this reason, we recommend using this tool as a formatter, regardless of any disagreements you might have with the style it enforces.

Use the command `black --help` to see how to use this tool. The full style guide is explained in detail on [black's GitHub repository](https://github.com/ambv/black). **There is one exception to this**, however, which is that we set the line length to 99, instead of black's default 88. When using `black` on the command line, simply use it like so: `black -l 99 -N <src>`.
Use the command `black --help` to see how to use this tool. The full style guide is explained in detail on [black's GitHub repository](https://github.com/ambv/black). **There is one exception to this**, however, which is that we set the line length to 99, instead of black's default 88. This is already set in `pyproject.toml` configuration file in the repo so you can simply format code with Black like so: `black <src>`.

### 4.4 Make
You may have noticed we have a `Makefile` and a `make.bat` in the top-level directory. For now, you can do a few things with them:
@@ -2,9 +2,9 @@ PYTHON ?= python3.8

# Python Code Style
reformat:
$(PYTHON) -m black -l 99 --target-version py38 `git ls-files "*.py"`
$(PYTHON) -m black `git ls-files "*.py"`
stylecheck:
$(PYTHON) -m black --check -l 99 --target-version py38 `git ls-files "*.py"`
$(PYTHON) -m black --check `git ls-files "*.py"`

# Translations
gettext:
@@ -14,11 +14,11 @@ for /F "tokens=* USEBACKQ" %%A in (`git ls-files "*.py"`) do (
goto %1

:reformat
black -l 99 --target-version py38 !PYFILES!
black !PYFILES!
exit /B %ERRORLEVEL%

:stylecheck
black -l 99 --check --target-version py38 !PYFILES!
black --check !PYFILES!
exit /B %ERRORLEVEL%

:newenv
@@ -1,3 +1,22 @@
[tool.black]
line-length = 99
target-version = ['py38']
include = '\.py$'
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
'''

[tool.towncrier]
package = "redbot"
filename = "CHANGELOG.rst"

0 comments on commit 84870f2

Please sign in to comment.
You can’t perform that action at this time.