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

Format code and docs with black+blacken-docs+pre-commit #244

Merged
merged 2 commits into from Jul 10, 2018

Conversation

@sloria
Copy link
Member

commented Jul 9, 2018

  • Format code with black
  • Format doc code blocks with blacken-docs. This uncovered a number of syntax issues in the docs.
  • Run both with pre-commit

@sloria sloria force-pushed the precommit branch 4 times, most recently from c2574cb to ff77a97 Jul 9, 2018

@sloria

This comment has been minimized.

Copy link
Member Author

commented Jul 9, 2018

@asottile If you're feeling generous, feel free to give this a drive-by =).

@asottile
Copy link

left a comment

Looks good! Just a few small things I noticed :)

sys.path.insert(0, os.path.abspath('..'))
import webargs
sys.path.insert(0, os.path.abspath(".."))
import webargs # flake8: noqa

This comment has been minimized.

Copy link
@asottile

asottile Jul 9, 2018

fun story about # flake8: noqa

I believe you want # noqa here (or # flake8: noqa on a line by itself if you actually don't want to lint this file)

This comment has been minimized.

Copy link
@sloria

sloria Jul 9, 2018

Author Member

Ah, TIL. Thanks.

setup.cfg Outdated
max-line-length = 100
exclude = .git,.ropeproject,.tox,build,.direnv,__pycache__
ignore = E203, E266, E501, W503, E302
max-line-length = 80

This comment has been minimized.

Copy link
@asottile

asottile Jul 9, 2018

black I believe uses 88, though I see you've ignored E501 so I guess this line does nothing! :D

This comment has been minimized.

Copy link
@lafrech

lafrech Jul 9, 2018

Member

Is it possible to use explicit names in there?

-ignore = E203, E266, E501, W503, E302
+ignore = rule-number-one, another-rule

This comment has been minimized.

Copy link
@asottile

asottile Jul 9, 2018

unfortunately not -- pylint has this but flake8 does not

This comment has been minimized.

Copy link
@sloria

sloria Jul 9, 2018

Author Member

black I believe uses 88, though I see you've ignored E501 so I guess this line does nothing! :D

This is from the recommended flake8 config from black. E501 is ignored, but Bugbear's B901 is enabled, which will warn when the max-line-length exceeds 10% of max-line-length.

This comment has been minimized.

Copy link
@asottile

asottile Jul 9, 2018

are you using flake8-bugbear? I don't see it installed

This comment has been minimized.

Copy link
@sloria

sloria Jul 9, 2018

Author Member

Ah, woops. Forgot to add that to dev-requirements.txt. Will fix this up after work today.

tasks.py Outdated

@task
def precommit(ctx):
ctx.run("pre-commit run --all-files", echo=True)

This comment has been minimized.

Copy link
@asottile

asottile Jul 9, 2018

--show-diff-on-failure is usually a good option for CI's sake (helps drive-by contributors that might not have set up the linting locally)

@lafrech

This comment has been minimized.

Copy link
Member

commented Jul 9, 2018

Black can be installed by running pip install black. It requires Python 3.6.0+ to run but you can reformat Python 2 code with it, too.

My local environment is Python 3.5. Will this make pre-commit fail?

@asottile

This comment has been minimized.

Copy link

commented Jul 9, 2018

My local environment is Python 3.5. Will this make pre-commit fail?

Not necessarily, the hooks here are configured with language_version: python3.6 so pre-commit will attempt to instantiate hook environments using that interpreter -- if there's no python3.6 then yes it will fail hook installation and tell you so.

@sloria sloria force-pushed the precommit branch from ff77a97 to 4f90d2f Jul 9, 2018

@sloria sloria force-pushed the precommit branch from 4f90d2f to cd55fe7 Jul 9, 2018

@sloria

This comment has been minimized.

Copy link
Member Author

commented Jul 9, 2018

Addressed @asottile 's comments and also added some notes in CONTRIBUTING.rst about needing the python3.6 interpreter for pre-commit to work properly. If you don't have it installed, you can still run tests with

inv test --no-syntax
@lafrech

This comment has been minimized.

Copy link
Member

commented Jul 9, 2018

OK. This means that all contributors on Python 3.5 won't be able to use pre-commit anymore.

There's a trade-off, here. This commit adds more features to pre-commit but prevents part of the contributors to use it at all. I don't have stats on who uses 3.5 or 3.6. Using Debian Stable, I'll probably be using 3.5 for a while.

No big deal. If I can't run it locally, Travis will complain and I'll use my special ability (git push -f) to fix my mess.

@sloria

This comment has been minimized.

Copy link
Member Author

commented Jul 9, 2018

@lafrech You can use Python 3.5 in your virtualenv and still use pre-commit as long as you have the python3.6 interpreter globally.

With pyenv:

pyenv install 3.6.5
pyenv global system 3.6.5

@sloria sloria force-pushed the precommit branch from e11b7c0 to fe7faa9 Jul 9, 2018

@sloria sloria force-pushed the precommit branch from fe7faa9 to c108759 Jul 9, 2018

@sloria sloria merged commit 30988aa into dev Jul 10, 2018

3 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
pyup.io/safety-ci No dependencies with known security vulnerabilities.
Details

@sloria sloria deleted the precommit branch Jul 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.