Skip to content
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 to black #768

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 0 additions & 185 deletions .style.yapf

This file was deleted.

4 changes: 2 additions & 2 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -ex
EXIT_STATUS=0

# Autoformatter *first*, to avoid double-reporting errors
yapf -rpd setup.py trio \
black --diff setup.py trio \
|| EXIT_STATUS=$?

# Run flake8 without pycodestyle and import-related errors
Expand All @@ -23,7 +23,7 @@ Problems were found by static analysis (listed above).
To fix formatting and see remaining errors, run

pip install -r test-requirements.txt
yapf -rpi setup.py trio
black setup.py trio
./check.sh

in your local checkout.
Expand Down
24 changes: 10 additions & 14 deletions docs/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ in separate sections below:
adding a test to make sure it stays fixed.

* :ref:`pull-request-formatting`: If you changed Python code, then did
you run ``yapf -rpi setup.py trio``? (Or for other packages, replace
you run ``black setup.py trio``? (Or for other packages, replace
``trio`` with the package name.)

* :ref:`pull-request-release-notes`: If your change affects
Expand Down Expand Up @@ -273,31 +273,27 @@ of eyes can be helpful when trying to come up with devious tricks.
Code formatting
~~~~~~~~~~~~~~~

Instead of wasting time arguing about code formatting, we use `yapf
<https://github.com/google/yapf>`__ to automatically format all our
Instead of wasting time arguing about code formatting, we use black`
<https://github.com/ambv/black>`__ to automatically format all our
code to a standard style. While you're editing code you can be as
sloppy as you like about whitespace; and then before you commit, just
run::

pip install -U yapf
yapf -rpi setup.py trio
pip install -U black
black setup.py trio

to fix it up. (And don't worry if you forget – when you submit a pull
request then we'll automatically check and remind you.) Hopefully this
will let you focus on more important style issues like choosing good
names, writing useful comments, and making sure your docstrings are
nicely formatted. (Yapf doesn't reformat comments or docstrings.)
nicely formatted. (black doesn't reformat comments or docstrings.)

Very occasionally, yapf will generate really ugly and unreadable
formatting (usually for large literal structures like dicts nested
inside dicts). In these cases, you can add a ``# yapf: disable``
comment to tell it to leave that particular statement alone.
If you want to see what changes black will make, you can use::

If you want to see what changes yapf will make, you can use::
black --diff setup.py trio

yapf -rpd setup.py trio

(``-d`` displays a diff, versus ``-i`` which fixes files in-place.)
(``--diff`` displays a diff, versus the default mode which fixes files
in-place.)


.. _pull-request-release-notes:
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"sniffio",
# PEP 508 style, but:
# https://bitbucket.org/pypa/wheel/issues/181/bdist_wheel-silently-discards-pep-508
#"cffi; os_name == 'nt'", # "cffi is required on windows"
# "cffi; os_name == 'nt'", # "cffi is required on windows"
],
# This means, just install *everything* you see under trio/, even if it
# doesn't look like a source file, so long as it appears in MANIFEST.in:
Expand All @@ -93,7 +93,7 @@
# recent
extras_require={
":os_name == 'nt'": ["cffi"], # "cffi is required on windows",
":python_version < '3.7'": ["contextvars>=2.1"]
":python_version < '3.7'": ["contextvars>=2.1"],
},
python_requires=">=3.5",
keywords=["async", "io", "networking", "trio"],
Expand Down
2 changes: 1 addition & 1 deletion test-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pylint # for pylint finding all symbols tests
jedi # for jedi code completion tests

# Tools
yapf == 0.24.0 # formatting
black;python_version>="3.6" # formatting
flake8

# https://github.com/python-trio/trio/pull/654#issuecomment-420518745
Expand Down
8 changes: 6 additions & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
#
# pip-compile --output-file test-requirements.txt test-requirements.in
#
appdirs==1.4.3 # via black
appnope==0.1.0 # via ipython
asn1crypto==0.24.0 # via cryptography
astroid==2.0.4 # via pylint
atomicwrites==1.2.1 # via pytest
attrs==18.2.0 # via pytest
attrs==18.2.0 # via black, pytest
backcall==0.1.0 # via ipython
black==18.9b0 ; python_version >= "3.6"
cffi==1.11.5 # via cryptography
click==7.0 # via black
coverage==4.5.1 # via pytest-cov
cryptography==2.3.1 # via pyopenssl, trustme
decorator==4.3.0 # via ipython, traitlets
Expand Down Expand Up @@ -39,9 +43,9 @@ pytest-cov==2.6.0
pytest-faulthandler==1.5.0
pytest==3.10.0
six==1.11.0 # via astroid, cryptography, more-itertools, prompt-toolkit, pyopenssl, pytest, traitlets
toml==0.10.0 # via black
traitlets==4.3.2 # via ipython
trustme==0.4.0
typed-ast==1.1.0 ; python_version < "3.7" and implementation_name == "cpython"
wcwidth==0.1.7 # via prompt-toolkit
wrapt==1.10.11 # via astroid
yapf==0.24.0
Loading