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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use black code formatter #3852

Merged
merged 18 commits into from May 9, 2019
Merged

Use black code formatter #3852

merged 18 commits into from May 9, 2019

Conversation

krzysztofwolski
Copy link
Member

@krzysztofwolski krzysztofwolski commented Mar 19, 2019

I want to merge this change because... ref #3846

Screenshots

All done! 馃挜 馃挃 馃挜
644 files would be reformatted, 89 files would be left unchanged.

Todo

  • Rebase on latest master
  • Reapply black
  • Add black CI
  • Add pre-commit to the development dependencies
  • Fix conflicts between isort and black
  • Fix issues with isort unable to pass in pre-commit
  • Update docs
    • We use black
    • We use a 88 character limit

Pull Request Checklist

  1. Privileged views and APIs are guarded by proper permission checks.
  2. All visible strings are translated with proper context.
  3. All data-formatting is locale-aware (dates, numbers, and so on).
  4. Database queries are optimized and the number of queries is constant.
  5. Database migration files are up to date.
  6. The changes are tested.
  7. The code is documented (docstrings, project documentation).
  8. GraphQL schema and type definitions are up to date.
  9. Changes are mentioned in the changelog.

[tool.black]
target_version = ['py36', 'py37', 'py38']
include = '\.pyi?$'
exclude = '''
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've extended default exclude list for faster file discovery. We don't need to format cache dirs.

Copy link
Member

Choose a reason for hiding this comment

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

Is it really needed to include .pyi stub files?

@codecov
Copy link

codecov bot commented Mar 19, 2019

Codecov Report

Merging #3852 into master will increase coverage by 0.05%.
The diff coverage is 89.08%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3852      +/-   ##
==========================================
+ Coverage   91.56%   91.62%   +0.05%     
==========================================
  Files         277      277              
  Lines       15106    15108       +2     
  Branches     1474     1474              
==========================================
+ Hits        13832    13842      +10     
+ Misses        877      868       -9     
- Partials      397      398       +1
Impacted Files Coverage 螖
saleor/graphql/core/filters.py 86.66% <酶> (酶) 猬嗭笍
saleor/core/utils/text.py 100% <酶> (酶) 猬嗭笍
saleor/graphql/discount/resolvers.py 100% <酶> (酶) 猬嗭笍
saleor/account/validators.py 100% <酶> (酶) 猬嗭笍
saleor/graphql/order/schema.py 100% <酶> (酶) 猬嗭笍
saleor/graphql/product/scalars.py 52.63% <酶> (酶) 猬嗭笍
saleor/checkout/urls.py 100% <酶> (酶) 猬嗭笍
saleor/dashboard/taxes/forms.py 100% <酶> (酶) 猬嗭笍
saleor/dashboard/customer/urls.py 100% <酶> (酶) 猬嗭笍
saleor/account/urls.py 100% <酶> (酶) 猬嗭笍
... and 322 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 3959599...c1d952a. Read the comment docs.

Pipfile Show resolved Hide resolved
Pipfile Show resolved Hide resolved
@maarcingebala
Copy link
Member

With this PR we're adding .toml file which is yet another configuration Python file in our repo. Since .toml files are supposed to become a standard in Python, it would be nice to migrate to toml entirely. This is obviously beyond the scope of this PR but it's something to consider. I don't know if pipenv supports toml, maybe having only one configuration file would be only possible if we migrated to Poetry.

@jxltom
Copy link
Contributor

jxltom commented Mar 20, 2019

Pipfile is actually toml format, but pipenv iteself doesn't support pyproject.toml yet.

@krzysztofwolski
Copy link
Member Author

krzysztofwolski commented Mar 20, 2019

Depending on psf/black#759
Without that black produces code unsupported by py3.5

@jxltom
Copy link
Contributor

jxltom commented Mar 20, 2019

Plus, psf/black#763 should fix this issue.

@maarcingebala
Copy link
Member

We have to put this PR on hold until the next version of Black is released. This is supposed to happen in April (no exact date yet).

@jxltom
Copy link
Contributor

jxltom commented Mar 26, 2019

As psf/black#763 is merged, and Pipenv supports pin any package via git commit, if we don't want to wait for black's release, black = {git = "https://github.com/ambv/black@cea13f4", editable = true} can be used in Pipfile for patched black version.

@maarcingebala
Copy link
Member

@jxltom It would be great to migrate to Black as soon as possible. What's your opinion on relying on an unreleased version of a library @patrys @krzysztofwolski ?

@patrys
Copy link
Member

patrys commented Mar 26, 2019

I'd rather wait for it to be released as I fear people would still use released versions and we'd end up changing the formats back and forth.

@jxltom
Copy link
Contributor

jxltom commented Mar 27, 2019

It won't be a problem if users install packages via our requirements_dev.txtby pip install -r requirements_dev.txt or Pipfile.lock by pipenv install --dev since Pipenv has already locked the version of black.

Besides, I waited for a released version of black for half a year via psf/black#517, but there still has no release. Hope it can be released in early April.

@krzysztofwolski
Copy link
Member Author

I would rather not use an unreleased version of the software which calls itself This is a beta product ;)
I agree with @patrys

Copy link
Member

@NyanKiyoshi NyanKiyoshi left a comment

Choose a reason for hiding this comment

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

Note that if we change the line length, we have to update .editorconfig

@krzysztofwolski
Copy link
Member Author

re migration to toml: our tools slowly migrate to "new" format https://gitlab.com/pycqa/flake8/issues/428 and toml libs seem to be an issue. Shame it's not JSON.

@maarcingebala
Copy link
Member

I just realized that in PR #4028 we're removing support for Python 3.5 which means we'll be no longer blocked by the issue in Black 馃帀 .

@krzysztofwolski
Copy link
Member Author

@maarcingebala this week I'll update PR 馃帀

@NyanKiyoshi NyanKiyoshi self-assigned this May 8, 2019
@NyanKiyoshi
Copy link
Member

Exclude C0330 from pylint checks
Pylint produces false positives for C0330 which makes it harder to pass the codeclimate checks with black. In anyway, black is supposed to detect any bad continuation. Thus replacing C0330.

Refering to pylint-dev/pylint#289 (open since 2014).

@NyanKiyoshi
Copy link
Member

I updated the docs to mention pre-commit & black and added a black badge to the readme.

@maarcingebala maarcingebala merged commit de5784b into saleor:master May 9, 2019
@maarcingebala maarcingebala mentioned this pull request May 9, 2019
@NyanKiyoshi NyanKiyoshi deleted the paint-it-black branch May 9, 2019 09:20
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.

None yet

6 participants