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
Merged

Conversation

sloria
Copy link
Member

@sloria sloria 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 Compare July 9, 2018 03:42
@sloria
Copy link
Member Author

sloria commented Jul 9, 2018

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

Copy link

@asottile asottile left a comment

Choose a reason for hiding this comment

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

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

docs/conf.py Outdated
sys.path.insert(0, os.path.abspath('..'))
import webargs
sys.path.insert(0, os.path.abspath(".."))
import webargs # flake8: noqa
Copy link

Choose a reason for hiding this comment

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

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)

Copy link
Member Author

Choose a reason for hiding this comment

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

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
Copy link

Choose a reason for hiding this comment

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

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

Copy link
Member

@lafrech lafrech Jul 9, 2018

Choose a reason for hiding this comment

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

Is it possible to use explicit names in there?

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

Copy link

Choose a reason for hiding this comment

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

unfortunately not -- pylint has this but flake8 does not

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

Copy link

Choose a reason for hiding this comment

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

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

Copy link
Member Author

Choose a reason for hiding this comment

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

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)
Copy link

Choose a reason for hiding this comment

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

--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
Copy link
Member

lafrech 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
Copy link

asottile 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
Copy link
Member Author

sloria 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
Copy link
Member

lafrech 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
Copy link
Member Author

sloria 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

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.

3 participants