Skip to content

Commit 38385d8

Browse files
feat(python) migrate to uv (#236)
- change gh workflows to use uv - adapt pyproject.mustache to generate a uv pyproject.toml In `python.sh` the `pyproject.toml` from the sdk repo is copied into the generated repo. -> this template is only used for initial generation
1 parent 78a2f6d commit 38385d8

4 files changed

Lines changed: 65 additions & 62 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,29 +101,22 @@ jobs:
101101
uses: ./.github/actions/build/python
102102
- name: Generate SDK
103103
uses: ./.github/actions/generate-sdk/python
104-
- name: Install Python ${{ matrix.python-version }}
105-
uses: actions/setup-python@v5
106104
with:
107-
python-version: ${{ matrix.python-version }}
105+
python-version: ${{ matrix.python-version }}
106+
- name: install uv
107+
uses: astral-sh/setup-uv@v7
108+
with:
109+
version: "0.10.4"
110+
python-version: ${{ matrix.python-version }}
108111
- name: Install sdk
109112
working-directory: ./sdk-repo-updated
110-
run: |
111-
pip install poetry
112-
poetry config virtualenvs.create false
113-
python -m venv .venv
114-
. .venv/bin/activate
115-
python -m pip install --upgrade pip
116-
make install-dev
113+
run: make install-dev
117114
- name: Lint
118115
working-directory: ./sdk-repo-updated
119-
run: |
120-
. .venv/bin/activate
121-
make lint
116+
run: make lint
122117
- name: Test
123118
working-directory: ./sdk-repo-updated
124-
run: |
125-
. .venv/bin/activate
126-
make test
119+
run: make test
127120

128121
main-java:
129122
name: CI [Java]

.github/workflows/sdk-pr.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,16 @@ jobs:
6565
uses: ./.github/actions/build/python
6666
- name: Generate SDK
6767
uses: ./.github/actions/generate-sdk/python
68+
- name: install uv
69+
uses: astral-sh/setup-uv@v7
70+
with:
71+
version: "0.10.4"
6872
- name: Push SDK
6973
env:
7074
GH_REPO: "stackitcloud/stackit-sdk-python"
7175
GH_TOKEN: ${{ secrets.SDK_PR_TOKEN }}
7276
run: |
73-
set -e
74-
python -m venv .venv
75-
. .venv/bin/activate
76-
python -m pip install --upgrade pip
77-
pip install poetry
78-
poetry config virtualenvs.create false
79-
(cd ./sdk-repo-updated && make install-dev)
77+
(cd ./sdk-repo-updated && uv install)
8078
scripts/sdk-create-pr.sh "generator-bot-${{ github.run_id }}" "Generated from GitHub run [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" "git@github.com:stackitcloud/stackit-sdk-python.git" "python"
8179
8280
main-java:

languages/python/templates/pyproject.mustache

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,67 @@
11
[project]
22
name = "{{{pythonPackageName}}}"
3-
4-
[tool.poetry]
5-
name = "{{{pythonPackageName}}}"
63
version = "v0.0.1a"
7-
authors = [
8-
"STACKIT Developer Tools <developer-tools@stackit.cloud>",
9-
]
104
description = "{{{appName}}}"
5+
authors = [{name = "STACKIT Developer Tools", email = "developer-tools@stackit.cloud"}]
6+
requires-python = ">=3.9,<4.0"
117
readme = "README.md"
12-
#license = "{{{licenseInfo}}}{{^licenseInfo}}NoLicense{{/licenseInfo}}"
138
classifiers = [
149
"Programming Language :: Python :: 3",
1510
"License :: OSI Approved :: Apache Software License",
1611
"Operating System :: OS Independent",
12+
"Programming Language :: Python :: 3.9",
13+
"Programming Language :: Python :: 3.10",
14+
"Programming Language :: Python :: 3.11",
15+
"Programming Language :: Python :: 3.12",
16+
"Programming Language :: Python :: 3.13",
17+
"Programming Language :: Python :: 3.14",
1718
]
18-
packages = [
19-
{ include = "stackit", from="src" }
19+
dependencies = [
20+
"stackit-core>=0.0.1a",
21+
"requests>=2.32.3",
22+
"pydantic>=2.9.2",
23+
"python-dateutil>=2.9.0.post0",
2024
]
2125

22-
[tool.poetry.dependencies]
23-
python = "^3.9"
24-
stackit-core = ">=0.0.1a"
25-
requests = ">=2.32.3"
26-
pydantic = ">=2.9.2"
27-
python-dateutil = ">=2.9.0.post0"
28-
29-
[tool.poetry.group.dev.dependencies]
30-
black = ">=24.8.0"
31-
pytest = ">=8.3.3"
32-
flake8 = [
33-
{ version= ">=5.0.3", python="<3.12"},
34-
{ version= ">=6.0.1", python=">=3.12"}
35-
]
36-
flake8-black = ">=0.3.6"
37-
flake8-pyproject = ">=1.2.3"
38-
autoimport = ">=1.6.1"
39-
flake8-eol = ">=0.0.8"
40-
flake8-eradicate = ">=1.5.0"
41-
flake8-bandit = ">=4.1.1"
42-
flake8-bugbear = ">=23.1.14"
43-
flake8-quotes = ">=3.4.0"
44-
isort = ">=5.13.2"
45-
4626
[project.urls]
4727
Homepage = "https://github.com/{{{gitUserId}}}/{{{gitRepoId}}}"
4828
Issues = "https://github.com/{{{gitUserId}}}/{{{gitRepoId}}}/issues"
4929

30+
[dependency-groups]
31+
dev = [
32+
"black>=24.8.0",
33+
"pytest>=8.3.3",
34+
"flake8>=5.0.3 ; python_full_version < '3.12'",
35+
"flake8>=6.0.1 ; python_full_version >= '3.12'",
36+
"flake8-black>=0.3.6",
37+
"flake8-pyproject>=1.2.3",
38+
"autoimport>=1.6.1",
39+
"flake8-eol>=0.0.8",
40+
"flake8-eradicate>=1.5.0",
41+
"flake8-bandit>=4.1.1",
42+
"flake8-bugbear>=23.1.14",
43+
"flake8-quotes>=3.4.0",
44+
"isort>=5.13.2",
45+
]
46+
47+
[tool.uv]
48+
default-groups = "all"
49+
50+
[tool.uv.sources]
51+
stackit-core = { path = "../../stackit-core" }
52+
53+
[tool.hatch.build.targets.sdist]
54+
include = ["src/stackit"]
55+
56+
[tool.hatch.build.targets.wheel]
57+
include = ["src/stackit"]
58+
59+
[tool.hatch.build.targets.wheel-sources]
60+
"src/stackit" = "stackit"
61+
5062
[build-system]
51-
requires = ["setuptools", "poetry-core"]
52-
build-backend = "poetry.core.masonry.api"
63+
requires = ["hatchling"]
64+
build-backend = "hatchling.build"
5365

5466
[tool.pytest.ini_options]
5567
pythonpath = [

scripts/generate-sdk/languages/python.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ generate_python_sdk() {
146146
cp -r "${sdk_services_backup_dir}/${service}/pyproject.toml" "${SERVICES_FOLDER}/${service}/pyproject.toml"
147147
fi
148148

149-
# If the service has a poetry.lock file, move them inside the service folder
150-
if [ -f "${sdk_services_backup_dir}/${service}/poetry.lock" ]; then
151-
echo "Found ${service} \"poetry.lock\" file"
152-
cp -r "${sdk_services_backup_dir}/${service}/poetry.lock" "${SERVICES_FOLDER}/${service}/poetry.lock"
149+
# If the service has a uv.lock file, move them inside the service folder
150+
if [ -f "${sdk_services_backup_dir}/${service}/uv.lock" ]; then
151+
echo "Found ${service} \"uv.lock\" file"
152+
cp -r "${sdk_services_backup_dir}/${service}/uv.lock" "${SERVICES_FOLDER}/${service}/uv.lock"
153153
fi
154154

155155
# If the service has a CHANGELOG file, move it inside the service folder

0 commit comments

Comments
 (0)