-
Notifications
You must be signed in to change notification settings - Fork 49
Python tidy and formatter #1978
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
f3a4103
to
6b3a3ac
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1978 +/- ##
===========================================
+ Coverage 79.50% 79.62% +0.11%
===========================================
Files 100 102 +2
Lines 31016 31910 +894
Branches 4819 5047 +228
===========================================
+ Hits 24659 25406 +747
- Misses 4245 4312 +67
- Partials 2112 2192 +80
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
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.
Pull Request Overview
This PR introduces Python code formatting and linting infrastructure for the rocMLIR repository, implementing both CI automation and local development tooling to enforce consistent Python code style.
- Adds GitHub Actions CI workflow for automated Python code quality checks on pull requests and pushes
- Configures pre-commit hooks with YAPF formatter and Flake8 linter for local development
- Sets up YAPF style configuration based on PEP8 with project-specific customizations
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
pip_requirements.txt | Adds Python formatting and linting dependencies |
.github/workflows/ci.yml | Implements CI workflow for Python code quality checks |
.pre-commit-config.yaml | Configures local pre-commit hooks for YAPF and Flake8 |
.style.yapf | Defines YAPF formatting style configuration |
mlir/utils/performance/dummyfile.py | Test file with intentional formatting issues for CI validation |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
please, can you reformat all existing python files in this PR? |
.github/workflows/ci.yml
Outdated
|
||
on: | ||
pull_request: | ||
branches: [develop] |
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.
Add release branches too ?
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.
@umangyadav one check, it would be all from release/* ?
.pre-commit-config.yaml
Outdated
exclude: '^external/.*' | ||
|
||
repos: | ||
- repo: https://github.com/google/yapf |
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.
Because it is pre-commit hook, does it mean we need to update our docker locally for this to work ? You may want to notify team about this once this is merged.
@@ -0,0 +1,4 @@ | |||
[style] | |||
based_on_style = google | |||
column_limit = 79 |
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.
why 79? . it's an odd number.
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.
it's flake8's default, but we can change it here and on flake's as well if you want
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.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
.github/workflows/ci.yml
Outdated
id: changes | ||
shell: bash | ||
run: | | ||
BASE_SHA="${{ github.event.pull_request.base.sha }}" |
Copilot
AI
Sep 19, 2025
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.
The BASE_SHA will be empty for push events since github.event.pull_request doesn't exist. This will cause the git diff command to fail. Use a conditional to handle both pull request and push events differently, or use github.event.before for push events.
BASE_SHA="${{ github.event.pull_request.base.sha }}" | |
if [ "${{ github.event_name }}" = "pull_request" ]; then | |
BASE_SHA="${{ github.event.pull_request.base.sha }}" | |
else | |
BASE_SHA="${{ github.event.before }}" | |
fi |
Copilot uses AI. Check for mistakes.
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.
@dorde-antic this comment looks like a valid issue. can you check ?
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.
Yes, btw one thing about push events is that we didn't test them (since it would mean pushing to develop to try it) do you want that we keep push events as well? I think it make sense to have them since code can be changed that way too, the only thing is I'm not sure how to test it without spamming the commit history on develop
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.
We can skip testing on push for now (you can monitor for a few pushes later) but my concern is that we should include path to get SHA for the push events as the copilot suggested.
set -eou pipefail | ||
|
||
NEED_POP=0 | ||
if ! git diff --quiet || ! git diff --quiet -- .; then |
Copilot
AI
Sep 19, 2025
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.
The condition ! git diff --quiet -- .
is redundant since ! git diff --quiet
already checks the entire working directory. The second condition can be removed.
if ! git diff --quiet || ! git diff --quiet -- .; then | |
if ! git diff --quiet; then |
Copilot uses AI. Check for mistakes.
Motivation
This PR introduces tooling to enforce consistent Python formatting and linting within the rocMLIR repository. Resolves https://github.com/ROCm/rocMLIR-internal/issues/1872/
Technical Details
Added
.github/workflows/ci.yml
to implement a GitHub Actions workflow that runs on develop for both pushes and pull requests. The workflow installs flake8, yapf, and pep8-naming, then runs:flake8
, excluding theexternal/
directoryyapf --dry-run
, excludingexternal/**/*.py
, and reporting format issuesAdded .pre-commit-config.yaml to configure local pre-commit hooks with:
Added
.style.yapf
to define YAPF formatting preferences.Test Plan
1. Github Actions CI Testing
Temporarily adding different types python files to test if they trigger Github Actions and if the CI works properly.
I'll try more cases with different py files (some that should pass checks and some that should fail)
Warning
Do not merge with python files from this PR since they are used for testing
2. Local Testing
3. Github Actions CI + pre-commit
Confirm that if pre-commit made changes, it made them in a way that they will pass the Github Actions check.
Test Result
In progress ⏳
Submission Checklist