10BC0 Add support for UV & Ruff by szaher · Pull Request #38 · kubeflow/sdk · GitHub
[go: up one dir, main page]

Skip to content

Conversation

szaher
Copy link
Member
@szaher szaher commented Jul 4, 2025

What this PR does / why we need it:

  • Use UV as dependency manager
  • Use ruff for linting
  • update pyproject.toml to include directives for uv support
  • Add lint CI job

Which issue(s) this PR fixes (optional, in Fixes #<issue number>, #<issue number>, ... format, will close the issue(s) when PR gets merged):

Fixes #

Checklist:

  • Docs included if any changes are user facing

Signed-off-by: Saad Zaher <szaher@redhat.com>
szaher added 3 commits July 5, 2025 00:14
Signed-off-by: Saad Zaher <szaher@redhat.com>
Signed-off-by: Saad Zaher <szaher@redhat.com>
Signed-off-by: Saad Zaher <szaher@redhat.com>
Copy link
Member
@andreyvelich andreyvelich left a comment

Choose a reason for hiding this comment

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

Thanks for this @szaher

Comment on lines +64 to +65
[tool.hatch.build.targets]
packages = ["kubeflow"]
Copy link
Member

Choose a reason for hiding this comment

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

Given that we only have one target, do we need it ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it was in the file already
https://github.com/kubeflow/sdk/blob/main/python/pyproject.toml#L43-L44

we can remove it if not required

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we can remove this one.

Choose a reason for hiding this comment

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

agreed.

path = "kubeflow/trainer/__init__.py"

[tool.ruff]
line-length = 100
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

yes
image

Comment on lines +57 to +58
[tool.uv]
package = true
Copy link
Member

Choose a reason for hiding this comment

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

Is this required ?

Copy link
Member Author

Choose a reason for hiding this comment

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

since we have [build-system] we can drop this one

- repo: https://github.com/psf/black
rev: 25.1.0
hooks:
- id: black
Copy link
Member

Choose a reason for hiding this comment

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

Does ruff also replace black and isort ?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it does replace black and isort

Copy link
Member

Choose a reason for hiding this comment

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

@szaher In that case, let's remove them from the pre-commit and other configs.

@@ -0,0 +1,30 @@
name: Lint
Copy link
Member

Choose a reason for hiding this comment

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

I would move this GitHub action under test-python.yaml, with the similar name as here: https://github.com/kubeflow/trainer/blob/master/.github/workflows/test-python.yaml#L1

In that test, we can just run make verify which verifies Python code, and run make test-unit which runs unit tests.

Removing number of parallel GitHub actions will help our CI to execute faster, given that we have limitations for concurrent runs.

Comment on lines 19 to 30
- name: Install uv
run: pip install uv

- name: Install dependencies
run: |
cd python
uv sync
- name: Run ruff
run: |
cd python
uv run ruff check
Copy link
Member

Choose a reason for hiding this comment

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

We can move all of this to the Makefile for make verify instruction.

Copy link
Member Author
@szaher szaher left a comment

Choose a reason for hiding this comment

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

Thanks @andreyvelich for your review

- repo: https://github.com/psf/black
rev: 25.1.0
hooks:
- id: black
Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it does replace black and isort

path = "kubeflow/trainer/__init__.py"

[tool.ruff]
line-length = 100
Copy link
Member Author

Choose a reason for hiding this comment

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

yes
image

Comment on lines +57 to +58
[tool.uv]
package = true
Copy link
Member Author

Choose a reason for hiding this comment

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

since we have [build-system] we can drop this one

Comment on lines +64 to +65
[tool.hatch.build.targets]
packages = ["kubeflow"]
Copy link
Member Author

Choose a reason for hiding this comment

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

I think it was in the file already
https://github.com/kubeflow/sdk/blob/main/python/pyproject.toml#L43-L44

we can remove it if not required

Copy link
@syntaxsdev syntaxsdev 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, similar concerns as Andrey

@andreyvelich
Copy link
Member

@szaher Did you get a chance to address the remaining comments, so we can merge this PR ?

Signed-off-by: Saad Zaher <szaher@redhat.com>
@google-oss-prow google-oss-prow bot added size/XL and removed size/L labels Jul 16, 2025
szaher added 4 commits July 17, 2025 00:54
Signed-off-by: Saad Zaher <szaher@redhat.com>
Signed-off-by: Saad Zaher <szaher@redhat.com>
Signed-off-by: Saad Zaher <szaher@redhat.com>
Signed-off-by: Saad Zaher <szaher@redhat.com>
Comment on lines 19 to 20
- name: Install bash
run: sudo apt-get update && sudo apt-get install -y bash
Copy link
Member

Choose a reason for hiding this comment

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

bash should be installed on this runner.
We didn't install it here: https://github.com/kubeflow/trainer/blob/master/.github/workflows/test-python.yaml
However, we still use it in the Makefile: https://github.com/kubeflow/trainer/blob/master/Makefile#L11

Copy link
Member Author

Choose a reason for hiding this comment

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

I was testing since I was getting errors from .ONESHELL

Makefile Outdated
@cd $(PY_DIR) && uvx ruff check --show-fixes

.PHONY: verify
verify: verify-lock verify-ruff ## Verify everything is Ok for python sdk
Copy link
Member

Choose a reason for hiding this comment

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

Can you just run all instructions under verify to install tools if that is required, similar to this: https://github.com/kubeflow/trainer/blob/master/Makefile#L158
E.g.:

UV := $(shell which uv)
uv:
ifeq ($(UV),)
  curl -LsSf https://astral.sh/uv/$(UV_VERSION)/install.sh | sh
  $(info uv has been installed)
endif

verify: uv ruff # install all required tools
  @cd $(PY_DIR) && uv lock --check
  @cd $(PY_DIR) && uvx ruff check --show-fixes

Copy link
Member Author
@szaher szaher Jul 17, 2025

Choose a reason for hiding this comment

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

Thanks Andrey!
done

Makefile Outdated
Comment on lines 35 to 36
UV_VERSION=0.7.2
RUFF_VERSION=0.12.3
Copy link
Member

Choose a reason for hiding this comment

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

Is that important which version of uv and ruff we run ?
We can consider to place them under bin/ if specific version is required.

Copy link
C02E Member Author

Choose a reason for hiding this comment

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

not really required. I will install the latest

szaher added 2 commits July 17, 2025 02:22
Signed-off-by: Saad Zaher <szaher@redhat.com>
Signed-off-by: Saad Zaher <szaher@redhat.com>
@@ -0,0 +1,26 @@
name: Lint
Copy link
Member

Choose a reason for hiding this comment

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

@szaher Shall we just name this Workflow and rename file to test-python.yaml:

Suggested change
name: Lint
name: Unit Test - Python

Similar to Trainer test: https://github.com/kubeflow/trainer/blob/master/.github/workflows/test-python.yaml#L14, we can just run 2 jobs: pre-commit + test

Signed-off-by: Saad Zaher <szaher@redhat.com>
Makefile Outdated

PY_DIR := $(PROJECT_DIR)/python

REPO := github.com/kubeflow/sdk
Copy link
4B92 Member

Choose a reason for hiding this comment

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

This is unused

Suggested change
REPO := github.com/kubeflow/sdk

Makefile Outdated
Comment on lines 48 to 49
.PHONY: deps
deps:
Copy link
Member

Choose a reason for hiding this comment

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

C02E

Can you rename it to uv, it is better to keep instructions with the same name as binaries we install.

Suggested change
.PHONY: deps
deps:
.PHONY: uv
uv:

szaher added 3 commits July 17, 2025 02:44
Signed-off-by: Saad Zaher <szaher@redhat.com>
Signed-off-by: Saad Zaher <szaher@redhat.com>
Signed-off-by: Saad Zaher <szaher@redhat.com>
@szaher
Copy link
Member Author
szaher commented Jul 17, 2025

@andreyvelich one more review please :)

szaher and others added 4 commits July 17, 2025 03:13
Co-authored-by: Andrey Velichkevich <andrey.velichkevich@gmail.com>
Signed-off-by: Saad Zaher <szaher@redhat.com>
Co-authored-by: Andrey Velichkevich <andrey.velichkevich@gmail.com>
Signed-off-by: Saad Zaher <szaher@redhat.com>
Signed-off-by: Saad Zaher <szaher@redhat.com>
Signed-off-by: Saad Zaher <szaher@redhat.com>
Copy link
Member
@andreyvelich andreyvelich left a comment

Choose a reason for hiding this comment

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

Thank you for this great contribution @szaher!
/lgtm
/approve

Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andreyvelich

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow bot merged commit acabc71 into kubeflow:main Jul 17, 2025
3 checks passed
@google-oss-prow google-oss-prow bot added this to the v0.1 milestone Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0