-
Notifications
You must be signed in to change notification settings - Fork 3
Initial ruff config and azure setup #74
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
Conversation
|
I don't know if there's appetite to move these "quick" CI checks to GHA but that may offer easier maintainability + slightly faster spoolup. Then we could also remove them from Azure so we aren't maintaining both CI workflows. |
Oh yeah for sure, we can skip the overhead of the docker image setup and the avoid taking up the limited runners we have for private repos. Is there actually a way we can define the actions in this repo and then use them in our other repos though? |
nvm, I am very dumb and didn't realise we already have a bunch of GHA workflows setup exactly like this |
|
See mdolab/baseclasses#100 for an example of a working GHA check using pre-commit |
|
@eirikurj @ewu63 is it necessary for us to repeat the check with two different target versions? I had just copied that from our flake8 workflow, but since |
|
It would be great if we could get this merged by the end of this week. We're having the lab workshop next week and I was hoping to introduce the new students to our development process by having them open PRs on our repos to update their formatting. |
That logic makes sense to me. |
|
The impl looks okay, I'll defer to others for hashing out the exact set of checks to run with ruff. What is the plan with GHA/Azure? Do you plan to deprecate the Azure jobs for flake8/black/isort? I imagine you'd still want to keep pylint right? Since it in theory covers separate cases. |
I would vote to just remove the Azure flake8 and black checks. I think we were planning on keeping isort separate since not all our repos use it, and with ruff you need to edit the config to enable/disable it. I'm happy to keep our current pylint setup, which repos actually use it though? My suggestion for next steps would be:
|
|
Hmm any reason we're not running |
From what I can tell from the docs, it is not necessary. You specify the minimum version you want to support (currently in our case 3.9) and it should run on everything above it. Using newer python syntax will get flagged.
I agree that we should run this by default. However, currently this option is by default We should work more on the Regarding next steps or a plan, I think the proposed plan is fine except I would prefer to have an active and non-failing linting/formatting checks in place. Otherwise, we will have failing Another option is (this may be overly cautious) is to run |
|
Need to implement ability to combine the .github ruff config with any local ruff.toml, like we currently do for flake8 conflict |
Haven't tried but this can be used? https://docs.astral.sh/ruff/settings/#extend This would probably require people to have .github/ruff.toml in the exact path specified in local ruff.tomls which might not be ideal |
Good call, I ended up using that option here, kind of similar to what this repo currently does to handle repo-specific flake8 configuration files. |
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.
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: 3.12 | ||
| # Change ruffConfig to main before merge |
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.
commenting so we don't forget this
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.
Done
eirikurj
left a comment
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 looked at the output for the PRs that are up (added a link here also in the description above). I think we are getting close with the config, but I added a few comments.
| if [[ -f "ruff.toml-project" ]]; then | ||
| sed -i '1s/^/extend = "ruff.toml-project" \n/' ruff.toml | ||
| fi | ||
| echo "Ruff config:" |
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.
Related to the above comment, for users that are developing locally and want to run the same thing, its seems like they would need to manually add extend = <path-to-global-ruff.toml> to all project files? We could add/have a script that does this automatically that could be used both here and locally.
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, it's annoying, but currently they'd have to do the same thing for our repos with local flake8 configs so I don't think this is any worse.
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.
Its not quite as difficult with flake8 since on the CLI you can just add the --append-config flag with the extra config file. No file editing needed. This does not seem to exist in ruff.
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v6.0.0 | ||
| hooks: | ||
| - id: trailing-whitespace |
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.
Is the idea that we check all files with all these? This seems to be going through everything, including fortran files and other source and config files, generating loads of errors. Maybe this is fine since these are mostly whitespace issues, but ideally we should have tools specifically for fortran to avoid any clashes.
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 I think we should be running this on all files. I often find myself unwittingly commiting a bunch of whitespace changes to files I didn't mean to edit because my editor automatically trims whitespace and fixes the ends of files. Enforcing these checks will avoid that.
.pre-commit-config.yaml
Outdated
| - id: ruff-format | ||
| # Run the linter. | ||
| - id: ruff-check | ||
| args: [ --fix ] |
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.
Fixing is useful for local development, but as part of CI its not since we do want the issues to be reported.
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 believe that pre-commit flags a check as failed if any files are modified, even if the check returns a zero exit code. So I believe this would work as is, even if all the issues ruff check finds are fixable. Just to be sure, I added the --exit-non-zero-on-fix flag to make sure we get a non-zero exit code even if all the issues found are fixable.
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.
Here I was not thinking about the exit code. We should not have it auto-fix since we want to see what linting codes are triggered. The dig diff output at the end is not sufficient for this.
I would vote we remove the ruff Azure checks altogether and run them via GHA for all repos. I'd also like to move our other formatting/style checks (basically anything quick that doesn't require spinning up our docker images) from Azure to GHA as well. But we should save that for another PR. I have removed the Azure ruff check, but you can |
|
Overall, I think I am satisfied with the On Azure or GHA I am favoring Azure at the moment due to a couple of reasons.
Are there any benefits moving from Azure to GHA that I am missing? I dont mind moving to GHA, I just want to make sure we are not limiting us in any way. Let me know what you think. Curious to hear from others as well @kanekosh @ewu63. |
This reverts commit c0c2e18.
These are good points, I forgot about the limits for GHA on private repos. I think since we are technically under the UM enterprise GitHub our limit is something like 50,000 minutes per month, so we'd never come anywhere near it with just these formatting checks, but good to not be beholden to the whims of GitHub anyway. I'll add back the Azure config and then I'll go ahead and merge this so that our repos starting running the ruff checks on Azure. |
|
I'm ok with either tools. One thing I like about GHA is that it is easier (less clicks) to see what failed from a Github PR tab. |
|
Some quick thoughts here
|
Purpose
This PR holds the initial
ruff.tomlconfig and Azure setup.Feel free to commit and update as needed.
Addresses #73
Open PRs testing this config
Expected time until merged
Type of change
Testing
Checklist
flake8andblackto make sure the Python code adheres to PEP-8 and is consistently formattedfprettifyor C/C++ code withclang-formatas applicable