From 55ed45c671ee01b409f4d9005b2ca26a2845a904 Mon Sep 17 00:00:00 2001 From: Carlo Goetz Date: Tue, 24 Feb 2026 10:55:31 +0100 Subject: [PATCH] feat(python) migrate to uv - 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 --- .github/workflows/ci.yaml | 25 ++---- .github/workflows/sdk-pr.yaml | 12 ++- languages/python/templates/pyproject.mustache | 82 +++++++++++-------- scripts/generate-sdk/languages/python.sh | 8 +- 4 files changed, 65 insertions(+), 62 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 73458f0..43ca42f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -101,29 +101,22 @@ jobs: uses: ./.github/actions/build/python - name: Generate SDK uses: ./.github/actions/generate-sdk/python - - name: Install Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python-version }} + python-version: ${{ matrix.python-version }} + - name: install uv + uses: astral-sh/setup-uv@v7 + with: + version: "0.10.4" + python-version: ${{ matrix.python-version }} - name: Install sdk working-directory: ./sdk-repo-updated - run: | - pip install poetry - poetry config virtualenvs.create false - python -m venv .venv - . .venv/bin/activate - python -m pip install --upgrade pip - make install-dev + run: make install-dev - name: Lint working-directory: ./sdk-repo-updated - run: | - . .venv/bin/activate - make lint + run: make lint - name: Test working-directory: ./sdk-repo-updated - run: | - . .venv/bin/activate - make test + run: make test main-java: name: CI [Java] diff --git a/.github/workflows/sdk-pr.yaml b/.github/workflows/sdk-pr.yaml index 4a9a251..eeb92e5 100644 --- a/.github/workflows/sdk-pr.yaml +++ b/.github/workflows/sdk-pr.yaml @@ -65,18 +65,16 @@ jobs: uses: ./.github/actions/build/python - name: Generate SDK uses: ./.github/actions/generate-sdk/python + - name: install uv + uses: astral-sh/setup-uv@v7 + with: + version: "0.10.4" - name: Push SDK env: GH_REPO: "stackitcloud/stackit-sdk-python" GH_TOKEN: ${{ secrets.SDK_PR_TOKEN }} run: | - set -e - python -m venv .venv - . .venv/bin/activate - python -m pip install --upgrade pip - pip install poetry - poetry config virtualenvs.create false - (cd ./sdk-repo-updated && make install-dev) + (cd ./sdk-repo-updated && uv install) 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" main-java: diff --git a/languages/python/templates/pyproject.mustache b/languages/python/templates/pyproject.mustache index 5c1ae96..ad2819c 100644 --- a/languages/python/templates/pyproject.mustache +++ b/languages/python/templates/pyproject.mustache @@ -1,55 +1,67 @@ [project] name = "{{{pythonPackageName}}}" - -[tool.poetry] -name = "{{{pythonPackageName}}}" version = "v0.0.1a" -authors = [ - "STACKIT Developer Tools ", -] description = "{{{appName}}}" +authors = [{name = "STACKIT Developer Tools", email = "developer-tools@stackit.cloud"}] +requires-python = ">=3.9,<4.0" readme = "README.md" -#license = "{{{licenseInfo}}}{{^licenseInfo}}NoLicense{{/licenseInfo}}" classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", ] -packages = [ - { include = "stackit", from="src" } +dependencies = [ + "stackit-core>=0.0.1a", + "requests>=2.32.3", + "pydantic>=2.9.2", + "python-dateutil>=2.9.0.post0", ] -[tool.poetry.dependencies] -python = "^3.9" -stackit-core = ">=0.0.1a" -requests = ">=2.32.3" -pydantic = ">=2.9.2" -python-dateutil = ">=2.9.0.post0" - -[tool.poetry.group.dev.dependencies] -black = ">=24.8.0" -pytest = ">=8.3.3" -flake8 = [ - { version= ">=5.0.3", python="<3.12"}, - { version= ">=6.0.1", python=">=3.12"} -] -flake8-black = ">=0.3.6" -flake8-pyproject = ">=1.2.3" -autoimport = ">=1.6.1" -flake8-eol = ">=0.0.8" -flake8-eradicate = ">=1.5.0" -flake8-bandit = ">=4.1.1" -flake8-bugbear = ">=23.1.14" -flake8-quotes = ">=3.4.0" -isort = ">=5.13.2" - [project.urls] Homepage = "https://github.com/{{{gitUserId}}}/{{{gitRepoId}}}" Issues = "https://github.com/{{{gitUserId}}}/{{{gitRepoId}}}/issues" +[dependency-groups] +dev = [ + "black>=24.8.0", + "pytest>=8.3.3", + "flake8>=5.0.3 ; python_full_version < '3.12'", + "flake8>=6.0.1 ; python_full_version >= '3.12'", + "flake8-black>=0.3.6", + "flake8-pyproject>=1.2.3", + "autoimport>=1.6.1", + "flake8-eol>=0.0.8", + "flake8-eradicate>=1.5.0", + "flake8-bandit>=4.1.1", + "flake8-bugbear>=23.1.14", + "flake8-quotes>=3.4.0", + "isort>=5.13.2", +] + +[tool.uv] +default-groups = "all" + +[tool.uv.sources] +stackit-core = { path = "../../stackit-core" } + +[tool.hatch.build.targets.sdist] +include = ["src/stackit"] + +[tool.hatch.build.targets.wheel] +include = ["src/stackit"] + +[tool.hatch.build.targets.wheel-sources] +"src/stackit" = "stackit" + [build-system] -requires = ["setuptools", "poetry-core"] -build-backend = "poetry.core.masonry.api" +requires = ["hatchling"] +build-backend = "hatchling.build" [tool.pytest.ini_options] pythonpath = [ diff --git a/scripts/generate-sdk/languages/python.sh b/scripts/generate-sdk/languages/python.sh index a290d39..0074a28 100644 --- a/scripts/generate-sdk/languages/python.sh +++ b/scripts/generate-sdk/languages/python.sh @@ -146,10 +146,10 @@ generate_python_sdk() { cp -r "${sdk_services_backup_dir}/${service}/pyproject.toml" "${SERVICES_FOLDER}/${service}/pyproject.toml" fi - # If the service has a poetry.lock file, move them inside the service folder - if [ -f "${sdk_services_backup_dir}/${service}/poetry.lock" ]; then - echo "Found ${service} \"poetry.lock\" file" - cp -r "${sdk_services_backup_dir}/${service}/poetry.lock" "${SERVICES_FOLDER}/${service}/poetry.lock" + # If the service has a uv.lock file, move them inside the service folder + if [ -f "${sdk_services_backup_dir}/${service}/uv.lock" ]; then + echo "Found ${service} \"uv.lock\" file" + cp -r "${sdk_services_backup_dir}/${service}/uv.lock" "${SERVICES_FOLDER}/${service}/uv.lock" fi # If the service has a CHANGELOG file, move it inside the service folder