-
Notifications
You must be signed in to change notification settings - Fork 88
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
Use Ruff to do import sorting #340
base: main
Are you sure you want to change the base?
Conversation
I do not experience this bahaviour (the automatic pre-commit ruff linting does sort my imports). (cuda_py) ksimpson@NV-3KWHSV3:~/dev/cuda-python/cuda_core$ git commit -m 'test'
Fixed 1 error:
Found 1 error (1 fixed, 0 remaining). ruff-format..............................................................Passed |
To clarify, what was the expected behaviour here? (i.e., which file had unsorted imports?) |
I just moved an "import pytest" after the cuda core experiemental imports in test_linker.py to observe that ruff would resort it after the commit |
From the output, it looks like indeed ruff did sort it back to correct order:
was that not actually the case? |
I might not correctly follow what you described above. My understanding is that when you make a commit, you are finding that ruff does not sort imports unless ytou trigger it manually. Is that correct? |
Oh, I see - you are doing all this on |
yes this is on main |
Understood - yeah you're absolutely right. It looks like Apologies, I assumed this wasn't the case based on Leo's comment here. -- I think perhaps I misunderstood Leo's ask, which may be about using a top-level |
No need to apologize! Thanks for looking into it. Let's see what leo says. |
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.
Thanks, guys! Sorry for my late reply...
I think perhaps I misunderstood Leo's ask, which may be about using a top-level
pyproject.toml
specifying the ruff config, that bothcuda.core
andcuda.bindings
can inherit (same as we are doing in CCCL). @leofang could you confirm?
Yes. What I had in mind was:
- Have a root
pyproject.toml
that's inherited by all of our namespace packages - Gradually sync up all Python configs across the two repos (cuda-python & cccl), starting with Ruff but eventually we want to cover everything (ex: mypy CI: Enforce type checks #312).
WDYT?
# Copyright (c) 2025, NVIDIA CORPORATION. | ||
|
||
[tool.ruff] | ||
target-version = "py310" |
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.
copied from CCCL root toml:
target-version = "py310" | |
target-version = "py310" | |
fix = true | |
show-fixes = true |
@@ -98,3 +99,6 @@ exclude = ["cuda/bindings/_version.py"] | |||
"UP022", | |||
"E402", # module level import not at top of file | |||
"F841"] # F841 complains about unused variables, but some assignments have side-effects that could be useful for tests (func calls for example) | |||
|
|||
[tool.ruff.lint.isort] | |||
known-first-party = ["cuda.parallel"] |
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.
Not sure if this is how it works? My intention is to spell out the old and new layouts:
known-first-party = ["cuda.parallel"] | |
known-first-party = ["cuda.cuda", "cuda.cudart", "cuda.nvrtc", "cuda.bindings"] |
Another question: This PR does not generate any diff that touches the code? Asking because previously @vzhurba01 had some requirements for how cuda.bindings should be formatted (for example, we should not format code that's autogenerated), and we'd like to preserve the requirements during code review (or, even better, through automated tools). |
Sort imports using Ruff (invoking
ruff linter
will now sort imports in addition to existing linting).It looks like so far, imports have been kept sorted by manual invocations of
ruff
(orisort
). This PR makes it so that the existing pre-commit hook will also take care of sorting imports.This PR is based on the feedback/discussion in NVIDIA/cccl#3230.