Skip to content

Commit acabc71

Browse files
szaherandreyvelich
andauthored
Add support for UV & Ruff (kubeflow#38)
* Add support for UV & Ruff Signed-off-by: Saad Zaher <[email protected]> * use correct path before installing deps Signed-off-by: Saad Zaher <[email protected]> * Remove unwanted uv install Signed-off-by: Saad Zaher <[email protected]> * add require-python directive to pyproject.toml Signed-off-by: Saad Zaher <[email protected]> * Add Makefile Signed-off-by: Saad Zaher <[email protected]> * Remove isort, black from precommit Signed-off-by: Saad Zaher <[email protected]> * Remove extra arg from make shell Signed-off-by: Saad Zaher <[email protected]> * Fix shell args Signed-off-by: Saad Zaher <[email protected]> * Make sure bash is installed Signed-off-by: Saad Zaher <[email protected]> * Remove unnecessary makefile commands Signed-off-by: Saad Zaher <[email protected]> * put all commands under verify Signed-off-by: Saad Zaher <[email protected]> * Update makefile to install ruff when needed Signed-off-by: Saad Zaher <[email protected]> * rename CI job name Signed-off-by: Saad Zaher <[email protected]> * remove unused vars in Makefile Signed-off-by: Saad Zaher <[email protected]> * rename CI job to only unit test - python Signed-off-by: Saad Zaher <[email protected]> * Update Makefile Co-authored-by: Andrey Velichkevich <[email protected]> Signed-off-by: Saad Zaher <[email protected]> * Update .github/workflows/test-python.yaml Co-authored-by: Andrey Velichkevich <[email protected]> Signed-off-by: Saad Zaher <[email protected]> * remove hatch.build.target directive from pyproject.toml Signed-off-by: Saad Zaher <[email protected]> * add uv section to Makefile Signed-off-by: Saad Zaher <[email protected]> --------- Signed-off-by: Saad Zaher <[email protected]> Co-authored-by: Andrey Velichkevich <[email protected]>
1 parent e065767 commit acabc71

File tree

7 files changed

+637
-23
lines changed

7 files changed

+637
-23
lines changed

.github/workflows/test-python.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Unit Test - Python
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Set up Python
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: '3.9'
18+
19+
20+
- name: Verify
21+
run: make verify

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ __debug_bin
99
# Python cache files
1010
__pycache__/
1111
*.egg-info/
12+
bin

.pre-commit-config.yaml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,11 @@ repos:
66
args: [--allow-multiple-documents]
77
- id: end-of-file-fixer
88
- id: trailing-whitespace
9-
- repo: https://github.com/pycqa/isort
10-
rev: 6.0.1
9+
- repo: https://github.com/astral-sh/ruff-pre-commit
10+
rev: v0.4.4
1111
hooks:
12-
- id: isort
13-
name: isort
14-
entry: isort --profile black
15-
- repo: https://github.com/psf/black
16-
rev: 25.1.0
17-
hooks:
18-
- id: black
19-
- repo: https://github.com/pycqa/flake8
20-
rev: 7.2.0
21-
hooks:
22-
- id: flake8
12+
- id: ruff
13+
args: [--select=E,F,W]
2314
exclude: |
2415
(?x)^(
2516
python/kubeflow/trainer/__init__.py|

Makefile

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Copyright 2025 The Kubeflow Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Setting SHELL to bash allows bash commands to be executed by recipes.
16+
# This is a requirement for 'setup-envtest.sh' in the test target.
17+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
18+
SHELL = /usr/bin/env bash -o pipefail
19+
.SHELLFLAGS = -ec
20+
21+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
22+
23+
PY_DIR := $(PROJECT_DIR)/python
24+
25+
##@ General
26+
27+
# The help target prints out all targets with their descriptions organized
28+
# beneath their categories. The categories are represented by '##@' and the
29+
# target descriptions by '##'. The awk commands is responsible for reading the
30+
# entire set of makefiles included in this invocation, looking for lines of the
31+
# file as xyz: ## something, and then pretty-format the target and help. Then,
32+
# if there's a line with ##@ something, that gets pretty-printed as a category.
33+
# More info on the usage of ANSI control characters for terminal formatting:
34+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
35+
# More info on the awk command:
36+
# http://linuxcommand.org/lc3_adv_awk.php
37+
38+
help: ## Display this help.
39+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
40+
41+
42+
#UV := $(shell which uv)
43+
44+
.PHONY: uv
45+
uv: ## Install UV
46+
@command -v uv &> /dev/null || { \
47+
curl -LsSf https://astral.sh/uv/install.sh | sh; \
48+
echo "✅ uv has been installed."; \
49+
}
50+
51+
.PHONY: ruff
52+
ruff: ## Install Ruff
53+
@uvx ruff --help &> /dev/null || uv tool install ruff
54+
55+
56+
.PHONY: verify
57+
verify: uv ruff ## install all required tools
58+
@cd $(PY_DIR) && uv lock --check
59+
@cd $(PY_DIR) && uvx ruff check --show-fixes
60+
61+
.PHONY: test-python
62+
test-python: ## Run Python unit test.
63+
uv install --dev
64+
PYTHONPATH=$(PROJECT_DIR) pytest ./python/kubeflow
65+

python/kubeflow/trainer/utils/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import inspect
1616
import os
1717
import queue
18-
import re
1918
import textwrap
2019
import threading
2120
from typing import Any, Callable, Dict, List, Optional, Tuple
@@ -259,7 +258,7 @@ def get_entrypoint_using_train_func(
259258
# Check if the runtime has a trainer.
260259
if not runtime.trainer:
261260
raise ValueError(f"Runtime must have a trainer: {runtime}")
262-
261+
263262
# Check if training function is callable.
264263
if not callable(train_func):
265264
raise ValueError(

python/pyproject.toml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
[build-system]
2-
requires = ["hatchling"]
3-
build-backend = "hatchling.build"
4-
51
[project]
62
name = "kubeflow"
73
dynamic = ["version"]
4+
requires-python = ">=3.9"
85
authors = [
96
{ name = "The Kubeflow Authors", email = "[email protected]" },
107
]
@@ -17,7 +14,6 @@ classifiers = [
1714
"Intended Audience :: Education",
1815
"Intended Audience :: Science/Research",
1916
# TODO (andreyvelich): Check Python version for Kubeflow Trainer.
20-
"Programming Language :: Python :: 3.8",
2117
"Programming Language :: Python :: 3.9",
2218
"Programming Language :: Python :: 3.10",
2319
"Programming Language :: Python :: 3.11",
@@ -40,11 +36,30 @@ Homepage = "https://github.com/kubeflow/trainer"
4036
Documentation = "https://www.kubeflow.org/docs/components/trainer/"
4137
Source = "https://github.com/kubeflow/trainer"
4238

43-
[tool.hatch.build.targets.wheel]
44-
packages = ["kubeflow"]
45-
4639
[tool.hatch.version]
4740
path = "kubeflow/trainer/__init__.py"
4841

42+
[tool.ruff]
43+
line-length = 100
44+
45+
[tool.ruff.lint]
46+
select = ["E", "F", "W"]
47+
ignore = ["E203"]
48+
49+
[dependency-groups]
50+
dev = [
51+
"ruff>=0.12.2",
52+
]
53+
54+
[tool.uv]
55+
package = true
56+
57+
[build-system]
58+
requires = ["hatchling"]
59+
build-backend = "hatchling.build"
60+
61+
[tool.hatch.build.targets]
62+
packages = ["kubeflow"]
63+
4964
[tool.hatch.metadata]
5065
allow-direct-references = true

0 commit comments

Comments
 (0)