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

🔧 MAINTAIN: Add isort pre-commit hook #5151

Merged
merged 11 commits into from
Sep 23, 2021
Merged

🔧 MAINTAIN: Add isort pre-commit hook #5151

merged 11 commits into from
Sep 23, 2021

Conversation

chrisjsewell
Copy link
Member

@chrisjsewell chrisjsewell commented Sep 23, 2021

To nicely sort imports: https://pycqa.github.io/isort/

I've set it as "opt-in" (via file regex) for now, so we can introduce it gradually, without introducing too many merge conflicts in existing PRs

Annoyingly, there is no specific integration with yapf (as there is for black), but from googling the configuration I added should be fine.
I added force_sort_within_sections=true to not split import a and from a import types, which I feel is nicer

@codecov
Copy link

codecov bot commented Sep 23, 2021

Codecov Report

Merging #5151 (be87298) into develop (af21ede) will decrease coverage by 0.03%.
The diff coverage is 94.63%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5151      +/-   ##
===========================================
- Coverage    80.92%   80.89%   -0.02%     
===========================================
  Files          536      536              
  Lines        37080    37019      -61     
===========================================
- Hits         30004    29944      -60     
+ Misses        7076     7075       -1     
Flag Coverage Δ
django 75.74% <87.96%> (-0.02%) ⬇️
sqlalchemy 74.89% <86.46%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ackends/djsite/db/migrations/0006_delete_dbpath.py 100.00% <ø> (ø)
...ends/djsite/db/migrations/0007_update_linktypes.py 100.00% <ø> (ø)
.../djsite/db/migrations/0008_code_hidden_to_extra.py 100.00% <ø> (ø)
...db/migrations/0009_base_data_plugin_type_string.py 100.00% <ø> (ø)
...s/djsite/db/migrations/0011_delete_kombu_tables.py 100.00% <ø> (ø)
.../backends/djsite/db/migrations/0012_drop_dblock.py 100.00% <ø> (ø)
...migrations/0014_add_node_uuid_unique_constraint.py 100.00% <ø> (ø)
...jsite/db/migrations/0015_invalidating_node_hash.py 100.00% <ø> (ø)
...jsite/db/migrations/0016_code_sub_class_of_data.py 100.00% <ø> (ø)
...ends/djsite/db/migrations/0017_drop_dbcalcstate.py 100.00% <ø> (ø)
... and 282 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 af21ede...be87298. Read the comment docs.

pyproject.toml Outdated
@@ -75,6 +75,13 @@ markers = [
"sphinx: set parameters for the sphinx `app` fixture"
]

[tool.isort]
line_length = 100
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not 120 as the rest of the code?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fine by me

Comment on lines 28 to 30
(?x)^(
aiida/common/.*py|
)$
Copy link
Contributor

Choose a reason for hiding this comment

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

I can appreciate that doing everything now would cause merge conflicts with open PRs, but I fear that in this way it is never going to get done. If we are going to add this, I prefer we bite the bullet. Since it only concerns imports, the merge conflicts should not be complicated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure ting, more lines of code attributed to me lol

pyproject.toml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
@chrisjsewell
Copy link
Member Author

right, removed the restriction on files; lets see if pre-commit.ci does its thing!

Comment on lines 69 to 70
def upgrade_schema_version(up_revision, down_revision):
from functools import partial
Copy link
Member Author

Choose a reason for hiding this comment

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

weird, only because of the extra new line, does pylint start failing it for not having a docstring 🤷 (https://github.com/aiidateam/aiida-core/runs/3690148576)

Suggested change
def upgrade_schema_version(up_revision, down_revision):
from functools import partial
def upgrade_schema_version(up_revision, down_revision):
"""Run migrations, to translate the database schema."""
from functools import partial

@chrisjsewell
Copy link
Member Author

Ok @sphuber I think this is good to go

Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

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

Looking good, thanks @chrisjsewell

@sphuber sphuber merged commit b7e37ce into develop Sep 23, 2021
@sphuber sphuber deleted the isort-hook branch September 23, 2021 17:47
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.

2 participants