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

Fade to black #314

Merged
merged 20 commits into from
Dec 17, 2019
Merged

Fade to black #314

merged 20 commits into from
Dec 17, 2019

Conversation

wsanchez
Copy link
Member

@wsanchez wsanchez commented Dec 10, 2019

This PR will adopt black code formatting for Klein.

Note that I have not checked in any of the reformatted files yet, because if I do, merging this after some other PR gets merged will be nutso. So this is currently just checking to see if people agree with this configuration change.

To see what the code changes look like, check out this branch and run:

tox -e black-reformat

At that point the flake8 and black Tox environments should pass.

@wsanchez wsanchez self-assigned this Dec 10, 2019
@@ -102,8 +104,8 @@ matrix:


install:
- ./.travis/install
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script doesn't do anything useful any more; tossing it.



script:
- ./.travis/run tox
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script doesn't do anything useful any more; tossing it.

@wsanchez
Copy link
Member Author

@glyph @twm @hawkowl @moshez thoughts?

Comment on lines 939 to 943
(
"Request.finish called on a request after its connection "
"was lost; use Request.notifyFinish to keep track of this."
)
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so that when black reformats it, we stay within max line length.

store.newSession(True, SessionMechanism.Header)
)
),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so that when black reformats it, we the # type: ignore comment for ISession stays with it.

Comment on lines +164 to +167
u"Can't initialize a session on a "
u"{method} request.".format(
method=request.method.decode("ascii")
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so that when black reformats it, we stay within max line length.

Comment on lines -4 to -10
/.coverage
/.coverage.*
/.eggs
/.hypothesis/
/.mypy_cache
/.tox/
/_trial_temp/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These scribble into ./.tox/

docs, docs-linkcheck
packaging

skip_missing_interpreters = {tty:True:False}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True only in interactive shells

skip_missing_interpreters = {tty:True:False}


[default]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This environment holds values that can be reused later, allowing use to set them in one place.


skip_missing_interpreters = {env:TOX_SKIP_MISSING_INTERPRETERS:True}
PYTHONPYCACHEPREFIX={envtmpdir}/pycache
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write __pycache__ in ./tox/ to reduce the number of build artifacts left in the source tree.

Comment on lines -66 to -71
passenv =
# See https://github.com/codecov/codecov-python/blob/5b9d539a6a09bc84501b381b563956295478651a/README.md#using-tox
codecov: TOXENV
codecov: CI
codecov: TRAVIS TRAVIS_*

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved down to codecov environment.

Comment on lines -73 to -74
PIP_DISABLE_PIP_VERSION_CHECK=1
VIRTUALENV_NO_DOWNLOAD=1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't necessary any more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to tox-dev/tox#448 shipped in Tox v3.10.0. Perhaps we should set [tox] minversion = 3.10.0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to that, but I wouldn't do that based on just these, since I think Tox still works (in most situations) if pip and virtualenv do these goofy things.


# Run trial with coverage
coverage: coverage run -p "{envbindir}/trial" --random=0 --logfile="{envlogdir}/trial.log" --temp-directory="{envlogdir}/trial.d" {posargs:klein}
coverage: coverage run --source {env:PY_MODULE} "{envdir}/bin/trial" --random=0 --logfile="{envlogdir}/trial.log" --temp-directory="{envlogdir}/trial.d" {posargs:{env:PY_MODULE}}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds --source and uses {env:PY_MODULE}

coverage: coverage run --source {env:PY_MODULE} "{envdir}/bin/trial" --random=0 --logfile="{envlogdir}/trial.log" --temp-directory="{envlogdir}/trial.d" {posargs:{env:PY_MODULE}}

# Run coverage reports, ignore exit status
coverage: - coverage report --skip-covered
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notes uncovered code for this environment.

black {env:BLACK_LINT_ARGS:} src


[testenv:black-reformat]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one actually reformats the code in place.

tox.ini Outdated
Comment on lines 164 to 196
######## WARNINGS BELOW SHOULD BE FIXED ########

# Missing docstring in public module
D100,

# Missing docstring in public class
D101,

# Missing docstring in public method
D102,

# Missing docstring in public function
D103,

# Missing docstring in public package
D104,

# Missing docstring in magic method
D105,

# too many blank lines
E302,
# Missing docstring in __init__
D107,

# too many blank lines
E303,
# Use """triple double quotes"""
D300,

# expected 2 blank lines after class or function definition
E305,
# First word of the first line should be properly capitalized
D403,

# Additional newline in a group of imports
I202,

######## WARNINGS ABOVE SHOULD BE FIXED ########
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are newly-enabled warnings that should be addressed in other PRs.

@@ -174,17 +258,13 @@ max-complexity = 60

description = run Mypy (static type checker)

basepython = python3.8

skip_install = True
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't skip installing the project (and dependencies) because that's how you get type stubs from dependencies.


description = generate coverage report

depends = {test,coverage}-py{27,35,36,37,38,py2,py3}-tw{171,184,current,trunk}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait for test environments to complete before running this one (only matters if you run them in parallel).

Copy link
Contributor

@twm twm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking forward to stealing much of this for Twisted and treq!

include LICENSE
include README.rst
include .coveragerc
include .travis/twistedchecker-diff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to include this in distributions? It's not useful out of VCS, is it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think .coveragerc should be included, so you can run Tox from a source distribution and get the same results we get in development.

twistedchecker-diff should go away entirely… I'll submit a PR for that.

Comment on lines -73 to -74
PIP_DISABLE_PIP_VERSION_CHECK=1
VIRTUALENV_NO_DOWNLOAD=1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to tox-dev/tox#448 shipped in Tox v3.10.0. Perhaps we should set [tox] minversion = 3.10.0?

@hawkowl hawkowl self-requested a review December 15, 2019 19:57
@hawkowl
Copy link
Member

hawkowl commented Dec 15, 2019

The travis envs fail because codecov got moved around, but otherwise, looks good. If you can fix that, run black, and verify that everything that's green in travis should be, go for it.

@hawkowl
Copy link
Member

hawkowl commented Dec 15, 2019

as an aside, we use this flake8 configuration on synapse:

[flake8]
# see https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
# for error codes. The ones we ignore are:
#  W503: line break before binary operator
#  W504: line break after binary operator
#  E203: whitespace before ':' (which is contrary to pep8?)
#  E731: do not assign a lambda expression, use a def
#  E501: Line too long (black enforces this for us)
ignore=W503,W504,E203,E731,E501

I'd go with just these, tbh, and see how they go?

@codecov
Copy link

codecov bot commented Dec 17, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@889ae4d). Click here to learn what that means.
The diff coverage is 98.93%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #314   +/-   ##
=========================================
  Coverage          ?   98.15%           
=========================================
  Files             ?       48           
  Lines             ?     3903           
  Branches          ?      259           
=========================================
  Hits              ?     3831           
  Misses            ?       55           
  Partials          ?       17
Impacted Files Coverage Δ
src/klein/test/_trial.py 75% <ø> (ø)
src/klein/_headers_compat.py 100% <ø> (ø)
src/klein/test/py3_test_resource.py 74.07% <ø> (ø)
src/klein/_iapp.py 100% <ø> (ø)
src/klein/_isession.py 100% <ø> (ø)
src/klein/__init__.py 100% <ø> (ø)
src/klein/_typing.py 100% <ø> (ø)
src/klein/_request_compat.py 100% <ø> (ø)
src/klein/test/test_headers_compat.py 100% <ø> (ø)
src/klein/storage/memory.py 100% <ø> (ø)
... and 35 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 889ae4d...cae339e. Read the comment docs.

@wsanchez wsanchez merged commit eb673fd into master Dec 17, 2019
@wsanchez wsanchez deleted the black branch December 17, 2019 19:30
@glyph
Copy link
Member

glyph commented Dec 18, 2019

Hey @ambv FYI

@wsanchez
Copy link
Member Author

as an aside, we use this flake8 configuration on synapse:

[flake8]
# see https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
# for error codes. The ones we ignore are:
#  W503: line break before binary operator
#  W504: line break after binary operator
#  E203: whitespace before ':' (which is contrary to pep8?)
#  E731: do not assign a lambda expression, use a def
#  E501: Line too long (black enforces this for us)
ignore=W503,W504,E203,E731,E501

I'd go with just these, tbh, and see how they go?

I didn't mention this, but all of the muted warnings in the config right now would cause an error if removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants