Skip to content

Feature: pre commit improvement#170

Closed
ZzEeKkAa wants to merge 3 commits intoNVIDIA:mainfrom
ZzEeKkAa:feature/pre-commit-improvement
Closed

Feature: pre commit improvement#170
ZzEeKkAa wants to merge 3 commits intoNVIDIA:mainfrom
ZzEeKkAa:feature/pre-commit-improvement

Conversation

@ZzEeKkAa
Copy link
Contributor

@ZzEeKkAa ZzEeKkAa commented Mar 21, 2025

Description

  • Replace flake8 with ruff code style to automatically format code. ruff has same set of features as flake8, so having both linters is redundant. ruff also adds auto formatting features like black. Config was ported from .flake8 to .pre-commit-config.yaml with these differences:
    • remove ignores for W503 and W504 (line break after binary operator).
  • Add pre-commit hooks that removes trailing spaces, ensures line brakes in the end of the file, formats yaml, toml, json, prevents big files to be added to history etc
  • Run pre-commit in separate commit and add it to git blame ignore.

This PR must be merged without squash, to separate config changes (that we want in history) from formatter changes (that we do not want). If rebased, please update .git-blame-ignore-revs commit hash.

Old description

  • Add black code style to automatically format code.
  • Run pre-commit in separate commit and add it to git blame ignore.

This PR must be merged without squash!

@ZzEeKkAa
Copy link
Contributor Author

I realized the pre-commit is already run, so I'll force push to this branch to remove github action that I added.

This PR must be merged without squash!

@ZzEeKkAa ZzEeKkAa force-pushed the feature/pre-commit-improvement branch from b863570 to 82b2ac5 Compare March 21, 2025 15:00
@isVoid
Copy link
Contributor

isVoid commented Mar 21, 2025

@ZzEeKkAa what do you think of ruff v.s. black? I'm using ruff in Numbast and it's faster and usually run into fewer non-auto fixable errors than black IMO

@ZzEeKkAa
Copy link
Contributor Author

I don't have anything against ruff) Just did not use it before

@gmarkall gmarkall added the 3 - Ready for Review Ready for review by team label Mar 24, 2025
@isVoid
Copy link
Contributor

isVoid commented Mar 24, 2025

I don't have anything against ruff) Just did not use it before

I suggest using ruff - Numbast will deliver static bindings formatted with ruff and I think it should run into fewer issue if Numba also uses a ruff formatter upon re-formatting to Numba's code standard.

@gmarkall
Copy link
Contributor

This PR must be merged without squash!

Is this because of the addition of .git-blame-ignore-revs? I think even if I rebase and merge, commit hashes end up different due to something Github does. So I think to make this work correctly, I might need to "rebase and merge" then just add the .git-blame-ignore-revs in a follow-up PR afterwards.

I don't have anything against ruff) Just did not use it before

I suggest using ruff

I'm in favour of this PR (I just never had the experience of setting something up like this before or the time to figure it out) and I'm happy with either of black or ruff, whatever you (@isVoid and @ZzEeKkAa) agree on.

@leofang
Copy link
Member

leofang commented Mar 25, 2025

Let's use Ruff as it's used by all other CUDA Python projects.

@ZzEeKkAa ZzEeKkAa force-pushed the feature/pre-commit-improvement branch from 82b2ac5 to 15c31b6 Compare March 25, 2025 23:20
@ZzEeKkAa ZzEeKkAa force-pushed the feature/pre-commit-improvement branch from 15c31b6 to 6d7de70 Compare March 25, 2025 23:23
@ZzEeKkAa
Copy link
Contributor Author

This PR must be merged without squash!

Is this because of the addition of .git-blame-ignore-revs?

Yes

I think even if I rebase and merge, commit hashes end up different due to something Github does. So I think to make this work correctly, I might need to "rebase and merge" then just add the .git-blame-ignore-revs in a follow-up PR afterwards.

Idea is to keep history for the changes to pyproject.toml/.pre-commit-config.yaml and do not show commit where I run pre-commit run -a because it does not have logical sense.

So yeah, if commit will be different after rebase (not sure why it is needed for branch merge, we need to update commit hash there.

@ZzEeKkAa
Copy link
Contributor Author

Just rebased the branch to work with ruff. Should be good to go)

@ZzEeKkAa
Copy link
Contributor Author

ZzEeKkAa commented Mar 26, 2025

Numbast will deliver static bindings formatted with ruff and I think it should run into fewer issue if Numba also uses a ruff formatter upon re-formatting to Numba's code standard.

I guess it is generally a bad idea to run any linters/formatters on the generated code. But I'm all in for ruff.

Copy link
Contributor

@isVoid isVoid left a comment

Choose a reason for hiding this comment

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

I managed to give a rough pass to the code which mostly looks good to me. I went over the new ruff config v.s. the flake8 config and discovered a nice small discussion around W503 and W504 - apparently it was controversial and ruff didn't implement them:
astral-sh/ruff#4125

As for the f-string dicussion below - I realized they are unsafe fixes. They might be a nice code style improvement in a future PR if we can scrutinize into each of the fstring use case deeper. But they shouldn't block this PR.

@ZzEeKkAa What do you think the current developer should do to merge this PR into current working branches?

Comment on lines +311 to +315
newdims = (
newdims[0:unknownidx]
+ (self.size // knownsize,)
+ newdims[unknownidx + 1 :]
)
Copy link
Contributor

Choose a reason for hiding this comment

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

We even have backslash line breaks! 🤣

Comment on lines +510 to +512
mem, sz = cufunc.module.get_global_symbol(
"%s__%s__" % (cufunc.name, name)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks so much nicer, but it would be even better if ruff can auto format into f-strings.

Comment on lines +200 to +205
tid = "tid=%s" % list(self.threadIdx)
ctaid = "ctaid=%s" % list(self.blockIdx)
if str(e) == "":
msg = "%s %s" % (tid, ctaid)
else:
msg = '%s %s: %s' % (tid, ctaid, e)
msg = "%s %s: %s" % (tid, ctaid, e)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same, f-strings would be nice.

@ZzEeKkAa
Copy link
Contributor Author

I managed to give a rough pass to the code which mostly looks good to me. I went over the new ruff config v.s. the flake8 config and discovered a nice small discussion around W503 and W504 - apparently it was controversial and ruff didn't implement them: astral-sh/ruff#4125

Yes, and in flake8 those where in the ignore list, so no changes for numba-cuda by simply removing them.

As for the f-string dicussion below - I realized they are unsafe fixes. They might be a nice code style improvement in a future PR if we can scrutinize into each of the fstring use case deeper. But they shouldn't block this PR.

Yes, lets target it in another PR.

@ZzEeKkAa What do you think the current developer should do to merge this PR into current working branches?

Simple merge + resolve conflicts generally should work, otherwise it will be nice to get .pre-commit-config.yaml and pyproject.toml from this MR (or git checkout first commit from this PR), run pre-commit on changed files and merge after this.

@ZzEeKkAa
Copy link
Contributor Author

ZzEeKkAa commented Apr 7, 2025

@gmarkall could we merge this PR?

@gmarkall
Copy link
Contributor

gmarkall commented Apr 8, 2025

I just merged this, but I had to do it outside the normal PR flow because even "rebase and merge" changes the commit hashes, which would mess up the .git-blame-ignore-revs file. As such, this isn't detected as merged, and I'll close this PR.

@gmarkall gmarkall closed this Apr 8, 2025
gmarkall added a commit to gmarkall/numba-cuda that referenced this pull request Apr 22, 2025
- Locate nvvm, libdevice, nvrtc, and cudart from nvidia-*-cu12 wheels (NVIDIA#155)
- reinstate test (NVIDIA#226)
- Restore PR NVIDIA#185 (Stop Certain Driver API Discovery for "v2") (NVIDIA#223)
- Report NVRTC builtin operation failures to the user (NVIDIA#196)
- Add Module Setup and Teardown Callback to Linkable Code Interface (NVIDIA#145)
- Test CUDA 12.8. (NVIDIA#187)
- Ensure RTC Bindings Clamp to the Maximum Supported CC (NVIDIA#189)
- Migrate code style to ruff (NVIDIA#170)
- Use less GPU memory in test_managed_alloc_driver_undersubscribe. (NVIDIA#188)
- Update workflows to always use proxy cache. (NVIDIA#191)
@gmarkall gmarkall mentioned this pull request Apr 22, 2025
gmarkall added a commit that referenced this pull request Apr 22, 2025
- Locate nvvm, libdevice, nvrtc, and cudart from nvidia-*-cu12 wheels (#155)
- reinstate test (#226)
- Restore PR #185 (Stop Certain Driver API Discovery for "v2") (#223)
- Report NVRTC builtin operation failures to the user (#196)
- Add Module Setup and Teardown Callback to Linkable Code Interface (#145)
- Test CUDA 12.8. (#187)
- Ensure RTC Bindings Clamp to the Maximum Supported CC (#189)
- Migrate code style to ruff (#170)
- Use less GPU memory in test_managed_alloc_driver_undersubscribe. (#188)
- Update workflows to always use proxy cache. (#191)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 - Ready for Review Ready for review by team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants