-
Notifications
You must be signed in to change notification settings - Fork 84
Formatting with black and isort #189
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
Draft
max-models
wants to merge
4
commits into
fortran-lang:master
Choose a base branch
from
max-forks:formatting-with-black-and-isort
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,072
−1,024
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| name: Static analysis | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| - devel | ||
| pull_request: | ||
| branches: | ||
| - master | ||
| - devel | ||
|
|
||
| defaults: | ||
| run: | ||
| shell: bash | ||
|
|
||
| jobs: | ||
|
|
||
| black: | ||
| runs-on: ubuntu-latest | ||
| continue-on-error: true | ||
| steps: | ||
| - name: Checkout the code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Code formatting with black | ||
| run: | | ||
| pip install black "black[jupyter]" | ||
| black --check . | ||
| isort: | ||
| runs-on: ubuntu-latest | ||
| continue-on-error: true | ||
| steps: | ||
| - name: Checkout the code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Code formatting with isort | ||
| run: | | ||
| pip install isort | ||
| isort --check . | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| repos: | ||
| # https://black.readthedocs.io/en/stable/integrations/source_version_control.html# | ||
| - repo: https://github.com/psf/black-pre-commit-mirror | ||
| rev: 25.11.0 | ||
| hooks: | ||
| - id: black | ||
| files: \.py$ | ||
|
|
||
| # https://pycqa.github.io/isort/docs/configuration/pre-commit.html | ||
| - repo: https://github.com/PyCQA/isort | ||
| rev: 7.0.0 | ||
| hooks: | ||
| - id: isort | ||
| files: \.py$ | ||
| args: [--profile=black] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this CI workflow can largely be discarded in favour of pre-commit CI. I would only have to enable the webhook in the Settings and make it a mandatory check for the branch ruleset.
(Some others mentioned pre-commit in the discussion). Generally, it's a good idea to define your linting, formating, etc. in one place and then have pre-commit hooks locally and on the CI use them.
Less maintenance work, overall.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hear you, it's a preference I guess. I prefer to avoid pre-commit hooks because they sometimes just gets in the way. Also, I tend to not always have them activated, and I see the same tendency among many others. As soon as they cause a moment of annoyance, people turn them off and then the formatting goes out the window. I feel like it's simpler to just let the developers choose themselves at which stage they would like to do the formatting. The pre-commit config file is there for anyone to activate if they would like, isn't that enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
people can do as they wish on their machines, having a pre-commit yaml config does not change that.
The yaml config is what is read from the pre-commit.ci which will then automatically run the checks on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok sorry I see what you mean now, I didn't know this was possible. I can update the CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah so basically how this is done is:
Now every commit that is pushed on GitHub will be passed through isort/black/etc. and it will fail if any of the linters/formatter fail. You only have a single source of truth to worry about (the pre-commit config).
That being said for large projects, even locally, I find that it helps developing in an organised clean manner (abiding by linters, formatters, making atomic commits etc.), so I will almost certainly use pre-commit and run tests, when I commit and definitely before I push.