diff --git a/docs/generators/python.md b/docs/generators/python.md index 6a41958cb7fd..51b011e04409 100644 --- a/docs/generators/python.md +++ b/docs/generators/python.md @@ -29,6 +29,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |packageName|python package name (convention: snake_case).| |openapi_client| |packageUrl|python package URL.| |null| |packageVersion|python package version.| |1.0.0| +|poetry1|Fallback to formatting pyproject.toml to Poetry 1.x format.| |null| |projectName|python project name in setup.py (e.g. petstore-api).| |null| |recursionLimit|Set the recursion limit. If not set, use the system default value.| |null| |setEnsureAsciiToFalse|When set to true, add `ensure_ascii=False` in json.dumps when creating the HTTP request body.| |false| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java index 32ff3da81780..011b807c98dc 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java @@ -47,6 +47,7 @@ public class PythonClientCodegen extends AbstractPythonCodegen implements Codege public static final String DATETIME_FORMAT = "datetimeFormat"; public static final String DATE_FORMAT = "dateFormat"; public static final String SET_ENSURE_ASCII_TO_FALSE = "setEnsureAsciiToFalse"; + public static final String POETRY1_FALLBACK = "poetry1"; @Setter protected String packageUrl; protected String apiDocPath = "docs/"; @@ -149,6 +150,7 @@ public PythonClientCodegen() { cliOptions.add(new CliOption(DATE_FORMAT, "date format for query parameters") .defaultValue("%Y-%m-%d")); cliOptions.add(new CliOption(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP_DESC).defaultValue("false")); + cliOptions.add(new CliOption(POETRY1_FALLBACK, "Fallback to formatting pyproject.toml to Poetry 1.x format.")); supportedLibraries.put("urllib3", "urllib3-based client"); supportedLibraries.put("asyncio", "asyncio-based client"); diff --git a/modules/openapi-generator/src/main/resources/python/pyproject.mustache b/modules/openapi-generator/src/main/resources/python/pyproject.mustache index 195e46b9c5f4..4b2949c9e9db 100644 --- a/modules/openapi-generator/src/main/resources/python/pyproject.mustache +++ b/modules/openapi-generator/src/main/resources/python/pyproject.mustache @@ -1,17 +1,31 @@ +{{#poetry1}} [tool.poetry] +{{/poetry1}} +{{^poetry1}} +[project] +{{/poetry1}} name = "{{{packageName}}}" version = "{{{packageVersion}}}" description = "{{{appName}}}" +{{#poetry1}} authors = ["{{infoName}}{{^infoName}}OpenAPI Generator Community{{/infoName}} <{{infoEmail}}{{^infoEmail}}team@openapitools.org{{/infoEmail}}>"] +{{/poetry1}} +{{^poetry1}} +authors = [ + {name = "{{infoName}}{{^infoName}}OpenAPI Generator Community{{/infoName}}",email = "{{infoEmail}}{{^infoEmail}}team@openapitools.org{{/infoEmail}}"}, +] +{{/poetry1}} license = "{{{licenseInfo}}}{{^licenseInfo}}NoLicense{{/licenseInfo}}" readme = "README.md" +{{#poetry1}} repository = "https://{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}}" +{{/poetry1}} keywords = ["OpenAPI", "OpenAPI-Generator", "{{{appName}}}"] +{{#poetry1}} include = ["{{packageName}}/py.typed"] [tool.poetry.dependencies] python = "^3.9" - urllib3 = ">= 2.1.0, < 3.0.0" python-dateutil = ">= 2.8.2" {{#asyncio}} @@ -27,8 +41,43 @@ pycryptodome = ">= 3.9.0" {{/hasHttpSignatureMethods}} pydantic = ">= 2" typing-extensions = ">= 4.7.1" +{{/poetry1}} +{{^poetry1}} +requires-python = "^3.9" + +dependencies = [ + "urllib3 (>=2.1.0,<3.0.0)", + "python-dateutil (>=2.8.2)", +{{#asyncio}} + "aiohttp (>=3.8.4)", + "aiohttp-retry (>=2.8.3)", +{{/asyncio}} +{{#tornado}} + "tornado (>=4.2,<5)", +{{/tornado}} +{{#hasHttpSignatureMethods}} + "pem (>=19.3.0)", + "pycryptodome (>=3.9.0)", +{{/hasHttpSignatureMethods}} + "pydantic (>=2)", + "typing-extensions (>=4.7.1)" +] + +[project.urls] +Repository = "https://{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}}" + +{{/poetry1}} +{{^poetry1}} +[tool.poetry] +requires-poetry = ">=2.0" +{{/poetry1}} +{{#poetry1}} [tool.poetry.dev-dependencies] +{{/poetry1}} +{{^poetry1}} +[tool.poetry.group.dev.dependencies] +{{/poetry1}} pytest = ">= 7.2.1" pytest-cov = ">= 2.8.1" tox = ">= 3.9.0" diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml index 1ff108ea46c8..602a4bba01a1 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml @@ -1,23 +1,29 @@ -[tool.poetry] +[project] name = "openapi_client" version = "1.0.0" description = "Echo Server API" -authors = ["OpenAPI Generator Community "] +authors = [ + {name = "OpenAPI Generator Community",email = "team@openapitools.org"}, +] license = "Apache 2.0" readme = "README.md" -repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID" keywords = ["OpenAPI", "OpenAPI-Generator", "Echo Server API"] -include = ["openapi_client/py.typed"] +requires-python = "^3.9" -[tool.poetry.dependencies] -python = "^3.9" +dependencies = [ + "urllib3 (>=2.1.0,<3.0.0)", + "python-dateutil (>=2.8.2)", + "pydantic (>=2)", + "typing-extensions (>=4.7.1)" +] -urllib3 = ">= 2.1.0, < 3.0.0" -python-dateutil = ">= 2.8.2" -pydantic = ">= 2" -typing-extensions = ">= 4.7.1" +[project.urls] +Repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID" + +[tool.poetry] +requires-poetry = ">=2.0" -[tool.poetry.dev-dependencies] +[tool.poetry.group.dev.dependencies] pytest = ">= 7.2.1" pytest-cov = ">= 2.8.1" tox = ">= 3.9.0" diff --git a/samples/client/echo_api/python/pyproject.toml b/samples/client/echo_api/python/pyproject.toml index 1ff108ea46c8..602a4bba01a1 100644 --- a/samples/client/echo_api/python/pyproject.toml +++ b/samples/client/echo_api/python/pyproject.toml @@ -1,23 +1,29 @@ -[tool.poetry] +[project] name = "openapi_client" version = "1.0.0" description = "Echo Server API" -authors = ["OpenAPI Generator Community "] +authors = [ + {name = "OpenAPI Generator Community",email = "team@openapitools.org"}, +] license = "Apache 2.0" readme = "README.md" -repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID" keywords = ["OpenAPI", "OpenAPI-Generator", "Echo Server API"] -include = ["openapi_client/py.typed"] +requires-python = "^3.9" -[tool.poetry.dependencies] -python = "^3.9" +dependencies = [ + "urllib3 (>=2.1.0,<3.0.0)", + "python-dateutil (>=2.8.2)", + "pydantic (>=2)", + "typing-extensions (>=4.7.1)" +] -urllib3 = ">= 2.1.0, < 3.0.0" -python-dateutil = ">= 2.8.2" -pydantic = ">= 2" -typing-extensions = ">= 4.7.1" +[project.urls] +Repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID" + +[tool.poetry] +requires-poetry = ">=2.0" -[tool.poetry.dev-dependencies] +[tool.poetry.group.dev.dependencies] pytest = ">= 7.2.1" pytest-cov = ">= 2.8.1" tox = ">= 3.9.0" diff --git a/samples/openapi3/client/petstore/python-aiohttp/pyproject.toml b/samples/openapi3/client/petstore/python-aiohttp/pyproject.toml index 7af017bf4449..b19ccea78df0 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/pyproject.toml +++ b/samples/openapi3/client/petstore/python-aiohttp/pyproject.toml @@ -1,27 +1,33 @@ -[tool.poetry] +[project] name = "petstore_api" version = "1.0.0" description = "OpenAPI Petstore" -authors = ["OpenAPI Generator Community "] +authors = [ + {name = "OpenAPI Generator Community",email = "team@openapitools.org"}, +] license = "Apache-2.0" readme = "README.md" -repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID" keywords = ["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"] -include = ["petstore_api/py.typed"] +requires-python = "^3.9" -[tool.poetry.dependencies] -python = "^3.9" +dependencies = [ + "urllib3 (>=2.1.0,<3.0.0)", + "python-dateutil (>=2.8.2)", + "aiohttp (>=3.8.4)", + "aiohttp-retry (>=2.8.3)", + "pem (>=19.3.0)", + "pycryptodome (>=3.9.0)", + "pydantic (>=2)", + "typing-extensions (>=4.7.1)" +] -urllib3 = ">= 2.1.0, < 3.0.0" -python-dateutil = ">= 2.8.2" -aiohttp = ">= 3.8.4" -aiohttp-retry = ">= 2.8.3" -pem = ">= 19.3.0" -pycryptodome = ">= 3.9.0" -pydantic = ">= 2" -typing-extensions = ">= 4.7.1" +[project.urls] +Repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID" + +[tool.poetry] +requires-poetry = ">=2.0" -[tool.poetry.dev-dependencies] +[tool.poetry.group.dev.dependencies] pytest = ">= 7.2.1" pytest-cov = ">= 2.8.1" tox = ">= 3.9.0" diff --git a/samples/openapi3/client/petstore/python/pyproject.toml b/samples/openapi3/client/petstore/python/pyproject.toml index 186674bcc8a7..fbf945b895c1 100644 --- a/samples/openapi3/client/petstore/python/pyproject.toml +++ b/samples/openapi3/client/petstore/python/pyproject.toml @@ -1,25 +1,31 @@ -[tool.poetry] +[project] name = "petstore_api" version = "1.0.0" description = "OpenAPI Petstore" -authors = ["OpenAPI Generator Community "] +authors = [ + {name = "OpenAPI Generator Community",email = "team@openapitools.org"}, +] license = "Apache-2.0" readme = "README.md" -repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID" keywords = ["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"] -include = ["petstore_api/py.typed"] +requires-python = "^3.9" -[tool.poetry.dependencies] -python = "^3.9" +dependencies = [ + "urllib3 (>=2.1.0,<3.0.0)", + "python-dateutil (>=2.8.2)", + "pem (>=19.3.0)", + "pycryptodome (>=3.9.0)", + "pydantic (>=2)", + "typing-extensions (>=4.7.1)" +] -urllib3 = ">= 2.1.0, < 3.0.0" -python-dateutil = ">= 2.8.2" -pem = ">= 19.3.0" -pycryptodome = ">= 3.9.0" -pydantic = ">= 2" -typing-extensions = ">= 4.7.1" +[project.urls] +Repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID" + +[tool.poetry] +requires-poetry = ">=2.0" -[tool.poetry.dev-dependencies] +[tool.poetry.group.dev.dependencies] pytest = ">= 7.2.1" pytest-cov = ">= 2.8.1" tox = ">= 3.9.0"