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] Using Black #7769

Merged
merged 1 commit into from
Jun 25, 2019
Merged

Conversation

john-bodley
Copy link
Member

@john-bodley john-bodley commented Jun 24, 2019

CATEGORY

Choose one

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

Though for Python we currently use flake8 and pylint for linting and error checking these don't auto-format the code and thus it's still relatively hard to try to enforce a common code style/format.

There seems to be three main auto-formatters:

Here's a fairly good comparison of the three tools. Note that YAPF supports a number of styles including "pep8" (which is what autopep8 uses). The "Facebook" style is similar to Black.

Though I don't necessarily agree with all of Black's style formatting (including the 88 character line length, non-trailing commas, double-quotes, etc.) it seems this has gained popularity(it currently has over 11,000 GitHub stars) over the likes of YAPF mostly because it isn't configurable (and thus ensures consistency) which is a plus if the goal is to align on a style/format across numerous repos.

This PR performs the following:

  1. Formats all the code using the Black format.
  2. Adds a pre-commit hook to auto-format the diff using the Black format on every local commit.
  3. Adds a CI check to ensure that the code is Black format compliant.

Note the flake8 and pylint CI remains as flake8 includes checks for import ordering as well as type checking. pylint additionally checks for numerous errors. In the future there would be merit in further cleaning up the code and reducing the number of flake8 codes we ignore.

TEST PLAN

CI.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

REVIEWERS

to: @betodealmeida @michellethomas @mistercrunch @villebro

@mistercrunch
Copy link
Member

mistercrunch commented Jun 24, 2019

I've been meaning to do this for a while. Black is the way to go.

We could do a 2 phase rollout with black -S (skipping the single/vs/double quote issue) first.

Happy to just byte the bullet and go for it.

+1

@john-bodley
Copy link
Member Author

@mistercrunch I can try the two phase rollout to minimize the change. Regarding pre-commit I'm using the suggestion in the doc per here.

@john-bodley john-bodley force-pushed the john-bodley--black branch 2 times, most recently from 04c0fa7 to 83bbfab Compare June 25, 2019 04:05
@codecov-io
Copy link

codecov-io commented Jun 25, 2019

Codecov Report

Merging #7769 into master will decrease coverage by <.01%.
The diff coverage is 59.95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7769      +/-   ##
==========================================
- Coverage   65.71%   65.71%   -0.01%     
==========================================
  Files         459      459              
  Lines       21981    21980       -1     
  Branches     2415     2415              
==========================================
- Hits        14445    14444       -1     
  Misses       7415     7415              
  Partials      121      121
Impacted Files Coverage Δ
superset/models/sql_types/presto_sql_types.py 72.41% <ø> (ø) ⬆️
superset/models/sql_lab.py 94.73% <ø> (ø) ⬆️
...migrations/versions/fb13d49b72f9_better_filters.py 53.44% <ø> (ø) ⬆️
superset/views/datasource.py 95.12% <ø> (ø) ⬆️
superset/utils/import_datasource.py 100% <ø> (ø) ⬆️
superset/models/tags.py 90.09% <ø> (ø) ⬆️
superset/sql_validators/__init__.py 83.33% <ø> (ø) ⬆️
superset/sql_lab.py 76.88% <ø> (ø) ⬆️
superset/views/__init__.py 100% <ø> (ø) ⬆️
superset/views/utils.py 87.77% <ø> (ø) ⬆️
... and 125 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 0c9e6d0...0f249a4. Read the comment docs.

@mistercrunch
Copy link
Member

Now thinking about it I'm thinking making it straight black is best, two phases would just be more confusing... There will be lots of conflicts, but resolving them is easy: just run black.

@john-bodley
Copy link
Member Author

john-bodley commented Jun 25, 2019

@mistercrunch are you ok with me merging this? I realize that the PR will cause a number of conflicts in existing PRs, though as you pointed out, resolving these are trivial.

Copy link
Member

@mistercrunch mistercrunch left a comment

Choose a reason for hiding this comment

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

LGTM - deterministic code style FTW!

@john-bodley john-bodley merged commit 5c58fd1 into apache:master Jun 25, 2019
@john-bodley john-bodley deleted the john-bodley--black branch June 25, 2019 20:34
@mistercrunch
Copy link
Member

black-square

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.34.0 labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/XXL 🚢 0.34.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants