From 43e878b4216ede0794e4cd105949c209c8096ac7 Mon Sep 17 00:00:00 2001 From: Youri Westerman Date: Wed, 18 Jun 2025 10:39:37 +0200 Subject: [PATCH] [python] Validate pyproject.toml and fix the pyproject.toml version constraint format (#21402) * Validate pyproject.toml of echo client python sample * Use PEP-508 compatible version constraint for `requires-python` key * Update samples * Move job to petstore workflow * Update generated sample * Use equals or greater than operator instead of greater than * Update samples --- .github/workflows/samples-python-petstore.yaml | 12 ++++++++++++ .../src/main/resources/python/pyproject.mustache | 2 +- .../pyproject.toml | 2 +- samples/client/echo_api/python/pyproject.toml | 2 +- .../openapi3/client/petstore/python/pyproject.toml | 2 +- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/samples-python-petstore.yaml b/.github/workflows/samples-python-petstore.yaml index 2b4b1c91e3c..bb659c8b8e6 100644 --- a/.github/workflows/samples-python-petstore.yaml +++ b/.github/workflows/samples-python-petstore.yaml @@ -8,6 +8,18 @@ on: - .github/workflows/samples-python-petstore.yaml jobs: + validate-pyproject-toml: + name: Validate pyproject.toml + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.13" + - name: Install validator + run: pip install 'validate-pyproject[all]' + - name: Validate + run: validate-pyproject samples/openapi3/client/petstore/python/pyproject.toml build: name: Test Python client runs-on: ubuntu-latest diff --git a/modules/openapi-generator/src/main/resources/python/pyproject.mustache b/modules/openapi-generator/src/main/resources/python/pyproject.mustache index 4b2949c9e9d..b97a1a5a77c 100644 --- a/modules/openapi-generator/src/main/resources/python/pyproject.mustache +++ b/modules/openapi-generator/src/main/resources/python/pyproject.mustache @@ -43,7 +43,7 @@ pydantic = ">= 2" typing-extensions = ">= 4.7.1" {{/poetry1}} {{^poetry1}} -requires-python = "^3.9" +requires-python = ">=3.9" dependencies = [ "urllib3 (>=2.1.0,<3.0.0)", diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml index 602a4bba01a..db1f365aa46 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml @@ -8,7 +8,7 @@ authors = [ license = "Apache 2.0" readme = "README.md" keywords = ["OpenAPI", "OpenAPI-Generator", "Echo Server API"] -requires-python = "^3.9" +requires-python = ">=3.9" dependencies = [ "urllib3 (>=2.1.0,<3.0.0)", diff --git a/samples/client/echo_api/python/pyproject.toml b/samples/client/echo_api/python/pyproject.toml index 602a4bba01a..db1f365aa46 100644 --- a/samples/client/echo_api/python/pyproject.toml +++ b/samples/client/echo_api/python/pyproject.toml @@ -8,7 +8,7 @@ authors = [ license = "Apache 2.0" readme = "README.md" keywords = ["OpenAPI", "OpenAPI-Generator", "Echo Server API"] -requires-python = "^3.9" +requires-python = ">=3.9" dependencies = [ "urllib3 (>=2.1.0,<3.0.0)", diff --git a/samples/openapi3/client/petstore/python/pyproject.toml b/samples/openapi3/client/petstore/python/pyproject.toml index fbf945b895c..b790b56f03d 100644 --- a/samples/openapi3/client/petstore/python/pyproject.toml +++ b/samples/openapi3/client/petstore/python/pyproject.toml @@ -8,7 +8,7 @@ authors = [ license = "Apache-2.0" readme = "README.md" keywords = ["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"] -requires-python = "^3.9" +requires-python = ">=3.9" dependencies = [ "urllib3 (>=2.1.0,<3.0.0)",