Skip to content
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

Add ruff linter #201

Merged
merged 11 commits into from
Nov 27, 2024
Merged

Add ruff linter #201

merged 11 commits into from
Nov 27, 2024

Conversation

ksimpson-work
Copy link
Contributor

@ksimpson-work ksimpson-work commented Oct 30, 2024

Add Ruff linter and format to pre-commit-hooks + make the appropriate changes in the code base so that we start with a passing commit.

some per-file ignores have been added, and some globals. I think these can be a work in progress, and I used my best judgement, but I would love to hear feedback.

Depends on #203

The only real bug this exposes is #203 which I am addressing in a separate PR and issue for cleanliness

Closes #195

Copy link

copy-pr-bot bot commented Oct 30, 2024

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@ksimpson-work
Copy link
Contributor Author

/ok to test

@ksimpson-work ksimpson-work requested review from vzhurba01, leofang and rwgk and removed request for vzhurba01 October 30, 2024 20:43
@ksimpson-work ksimpson-work marked this pull request as ready for review October 30, 2024 20:43
@ksimpson-work
Copy link
Contributor Author

The actions seem to be broken as of a long time ago. The culprit being a faulty build command which looks for setup.py in cuda-python top level directory. I'm wondering if that will be addressed by QA, or if I/someone should fix it.

@ksimpson-work ksimpson-work marked this pull request as draft October 30, 2024 20:48
Copy link
Collaborator

@vzhurba01 vzhurba01 left a comment

Choose a reason for hiding this comment

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

I couple of comments:

  1. Once you're ready, can you try testing the builds and tests across our supported Python versions (3.9 to 3.12) and 3.13? For the bindings just doing 3.9 and 3.13 is probably sufficient(?), just because the build there takes a while. In the past some of my own code formats had issues for certain versions, so some paranoia is creeping in. Surely since this is a linter all of that ought to be ok, but still 🙂.
  2. Would need a follow-up PR into the 11.8.x branch. Just an FYI for when the time comes. Actually no, this shouldn't be necessary since the only change expected on that branch are the bindings which aren't covered by the linter anyways. The only items remaining would be the tests/examples, but that is expected to stay the same.

cuda_bindings/pyproject.toml Outdated Show resolved Hide resolved
cuda_bindings/cuda/bindings/_version.py Outdated Show resolved Hide resolved
cuda_core/cuda/core/experimental/_device.py Outdated Show resolved Hide resolved
cuda_core/cuda/core/experimental/_event.py Outdated Show resolved Hide resolved
cuda_core/cuda/core/experimental/_launcher.py Outdated Show resolved Hide resolved
cuda_core/cuda/core/experimental/_stream.py Outdated Show resolved Hide resolved
cuda_core/tests/example_tests/test_basic_examples.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

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

Looks good to me, but what do you think about splitting this PR into two parts:

  1. Add tox testing only.
  2. Add ruff only with the tox testing in place already.

That would make it easier** to see what changes (if any?) are required to establish tox testing, and what changes are a consequence of introducing ruff.

easier** in the future, in case we have to backtrack for whatever reason.

.pre-commit-config.yaml Outdated Show resolved Hide resolved
@ksimpson-work
Copy link
Contributor Author

@vzhurba01 The changes have been verified against python 3.9 and 3.13 successfully.

rwgk
rwgk previously approved these changes Nov 1, 2024
Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

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

Another idea borrowed from pybind11:

https://github.com/pybind/pybind11/blob/75e48c5f959b4f0a49d8c664e059b6fb4b497102/.github/workflows/format.yml#L24-L37

This ensures that all PRs pass the pre-commit checks.

I didn't see that here. I'm not sure if you have another way of achieving the same?

@leofang leofang added this to the cuda.core beta 2 milestone Nov 2, 2024
@ksimpson-work ksimpson-work marked this pull request as ready for review November 4, 2024 17:20
@ksimpson-work ksimpson-work changed the title Ksimpson/ruff linter add ruff linter Nov 4, 2024
@ksimpson-work ksimpson-work changed the title add ruff linter Add ruff linter Nov 4, 2024
@leofang leofang added support All things related to the project that can't be categorized P0 High priority - Must do! cuda.core Everything related to the cuda.core module labels Nov 16, 2024
@ksimpson-work
Copy link
Contributor Author

Dependencies have been addressed and submitted.

rwgk
rwgk previously approved these changes Nov 20, 2024
Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

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

Looks good to me, but question: Do you want to wait merging this PR until after #249 is merged?

Minor: I think there are a couple files missing a newline at the end of the file, which can be annoying. VSCode has these settings: "Files Insert Final Newline", "Files: Trim Final Newlines", "Notebook: Insert Final Newline" that work well for me. I also have "Editor: Render Final Newline: off".

I think in another PR we should add a pre-commit checks for whitespace issues like that one.

@ksimpson-work
Copy link
Contributor Author

yeah, I am not opposed to waiting for #249. I'm wokring on a follow up to 249 that will run the testsuites against different versions of python and cuda as well. I'll look into the newline, I would expect ruff formatter to handle that.

@ksimpson-work
Copy link
Contributor Author

/ok to test

rwgk
rwgk previously approved these changes Nov 25, 2024
Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

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

Looks good to me. Keenan confirmed on chat that local testing passes for him.

Copy link
Member

@leofang leofang left a comment

Choose a reason for hiding this comment

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

LGTM overall. AI:

  • @ksimpson-work could you merge with the latest main and rerun the linter? There are merge conflicts
  • @vzhurba01 could you take one more look at cuda.bindings changes?

cuda_bindings/benchmarks/test_cupy.py Show resolved Hide resolved
cuda_core/cuda/core/experimental/_memory.py Outdated Show resolved Hide resolved
@leofang
Copy link
Member

leofang commented Nov 26, 2024

/ok to test

Copy link
Collaborator

@vzhurba01 vzhurba01 left a comment

Choose a reason for hiding this comment

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

I noticed that fixes for some older comments got reverted. Perhaps happened due to a rebase? I unresolved those that I'd like to see re-applied.

cuda_bindings/pyproject.toml Show resolved Hide resolved
cuda_core/pyproject.toml Outdated Show resolved Hide resolved
@ksimpson-work
Copy link
Contributor Author

Yes that is my bad. Rather than merge, I checked-out main and reran the linter but that reverted soem of the manual changes I forgot about. I believe everything has been addressed now.

Copy link
Collaborator

@vzhurba01 vzhurba01 left a comment

Choose a reason for hiding this comment

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

LGTM thank you @ksimpson-work!

@leofang
Copy link
Member

leofang commented Nov 27, 2024

Thanks @ksimpson-work and all! Glad this is set up. Let's get this in and follow up in new PRs if needed.

@leofang leofang merged commit fdc76e8 into main Nov 27, 2024
@leofang leofang deleted the ksimpson/ruff_linter branch November 27, 2024 02:37
@leofang
Copy link
Member

leofang commented Nov 28, 2024

FYI, I added some basic docs mentioning about pre-commit and code linting in commit 30d65ed.

@@ -2,4 +2,3 @@
#
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE

from cuda.core.experimental._memoryview import StridedMemoryView, viewable
Copy link
Member

Choose a reason for hiding this comment

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

This technically is a breaking change. It slipped the code review as it was removed right before the refresh before merging, and was not caught by the tests because we're still adding them (#247). Fixing it in b11e1ae.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cuda.core Everything related to the cuda.core module P0 High priority - Must do! support All things related to the project that can't be categorized
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce code linters to the repo
4 participants