Skip to content

Commit 041d36c

Browse files
authored
[python] Fix poetry deprecation warnings (#21268)
* Convert pyproject.toml template to the format expected by Poetry >=2.0 (https://python-poetry.org/blog/announcing-poetry-2.0.0) * Update samples * Add option to fallback to Poetry 1.x style pyproject.toml * Generate new docs and samples * Place project.urls section a bit further down, so that it doesn't clash with other sections * Update samples
1 parent c6a88ea commit 041d36c

File tree

7 files changed

+127
-51
lines changed

7 files changed

+127
-51
lines changed

docs/generators/python.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2929
|packageName|python package name (convention: snake_case).| |openapi_client|
3030
|packageUrl|python package URL.| |null|
3131
|packageVersion|python package version.| |1.0.0|
32+
|poetry1|Fallback to formatting pyproject.toml to Poetry 1.x format.| |null|
3233
|projectName|python project name in setup.py (e.g. petstore-api).| |null|
3334
|recursionLimit|Set the recursion limit. If not set, use the system default value.| |null|
3435
|setEnsureAsciiToFalse|When set to true, add `ensure_ascii=False` in json.dumps when creating the HTTP request body.| |false|

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class PythonClientCodegen extends AbstractPythonCodegen implements Codege
4747
public static final String DATETIME_FORMAT = "datetimeFormat";
4848
public static final String DATE_FORMAT = "dateFormat";
4949
public static final String SET_ENSURE_ASCII_TO_FALSE = "setEnsureAsciiToFalse";
50+
public static final String POETRY1_FALLBACK = "poetry1";
5051

5152
@Setter protected String packageUrl;
5253
protected String apiDocPath = "docs/";
@@ -149,6 +150,7 @@ public PythonClientCodegen() {
149150
cliOptions.add(new CliOption(DATE_FORMAT, "date format for query parameters")
150151
.defaultValue("%Y-%m-%d"));
151152
cliOptions.add(new CliOption(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP_DESC).defaultValue("false"));
153+
cliOptions.add(new CliOption(POETRY1_FALLBACK, "Fallback to formatting pyproject.toml to Poetry 1.x format."));
152154

153155
supportedLibraries.put("urllib3", "urllib3-based client");
154156
supportedLibraries.put("asyncio", "asyncio-based client");

modules/openapi-generator/src/main/resources/python/pyproject.mustache

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
1+
{{#poetry1}}
12
[tool.poetry]
3+
{{/poetry1}}
4+
{{^poetry1}}
5+
[project]
6+
{{/poetry1}}
27
name = "{{{packageName}}}"
38
version = "{{{packageVersion}}}"
49
description = "{{{appName}}}"
10+
{{#poetry1}}
511
authors = ["{{infoName}}{{^infoName}}OpenAPI Generator Community{{/infoName}} <{{infoEmail}}{{^infoEmail}}[email protected]{{/infoEmail}}>"]
12+
{{/poetry1}}
13+
{{^poetry1}}
14+
authors = [
15+
{name = "{{infoName}}{{^infoName}}OpenAPI Generator Community{{/infoName}}",email = "{{infoEmail}}{{^infoEmail}}[email protected]{{/infoEmail}}"},
16+
]
17+
{{/poetry1}}
618
license = "{{{licenseInfo}}}{{^licenseInfo}}NoLicense{{/licenseInfo}}"
719
readme = "README.md"
20+
{{#poetry1}}
821
repository = "https://{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}}"
22+
{{/poetry1}}
923
keywords = ["OpenAPI", "OpenAPI-Generator", "{{{appName}}}"]
24+
{{#poetry1}}
1025
include = ["{{packageName}}/py.typed"]
1126

1227
[tool.poetry.dependencies]
1328
python = "^3.9"
14-
1529
urllib3 = ">= 2.1.0, < 3.0.0"
1630
python-dateutil = ">= 2.8.2"
1731
{{#asyncio}}
@@ -27,8 +41,43 @@ pycryptodome = ">= 3.9.0"
2741
{{/hasHttpSignatureMethods}}
2842
pydantic = ">= 2"
2943
typing-extensions = ">= 4.7.1"
44+
{{/poetry1}}
45+
{{^poetry1}}
46+
requires-python = "^3.9"
47+
48+
dependencies = [
49+
"urllib3 (>=2.1.0,<3.0.0)",
50+
"python-dateutil (>=2.8.2)",
51+
{{#asyncio}}
52+
"aiohttp (>=3.8.4)",
53+
"aiohttp-retry (>=2.8.3)",
54+
{{/asyncio}}
55+
{{#tornado}}
56+
"tornado (>=4.2,<5)",
57+
{{/tornado}}
58+
{{#hasHttpSignatureMethods}}
59+
"pem (>=19.3.0)",
60+
"pycryptodome (>=3.9.0)",
61+
{{/hasHttpSignatureMethods}}
62+
"pydantic (>=2)",
63+
"typing-extensions (>=4.7.1)"
64+
]
65+
66+
[project.urls]
67+
Repository = "https://{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}}"
68+
69+
{{/poetry1}}
70+
{{^poetry1}}
71+
[tool.poetry]
72+
requires-poetry = ">=2.0"
73+
{{/poetry1}}
3074

75+
{{#poetry1}}
3176
[tool.poetry.dev-dependencies]
77+
{{/poetry1}}
78+
{{^poetry1}}
79+
[tool.poetry.group.dev.dependencies]
80+
{{/poetry1}}
3281
pytest = ">= 7.2.1"
3382
pytest-cov = ">= 2.8.1"
3483
tox = ">= 3.9.0"

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
[tool.poetry]
1+
[project]
22
name = "openapi_client"
33
version = "1.0.0"
44
description = "Echo Server API"
5-
authors = ["OpenAPI Generator Community <[email protected]>"]
5+
authors = [
6+
{name = "OpenAPI Generator Community",email = "[email protected]"},
7+
]
68
license = "Apache 2.0"
79
readme = "README.md"
8-
repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID"
910
keywords = ["OpenAPI", "OpenAPI-Generator", "Echo Server API"]
10-
include = ["openapi_client/py.typed"]
11+
requires-python = "^3.9"
1112

12-
[tool.poetry.dependencies]
13-
python = "^3.9"
13+
dependencies = [
14+
"urllib3 (>=2.1.0,<3.0.0)",
15+
"python-dateutil (>=2.8.2)",
16+
"pydantic (>=2)",
17+
"typing-extensions (>=4.7.1)"
18+
]
1419

15-
urllib3 = ">= 2.1.0, < 3.0.0"
16-
python-dateutil = ">= 2.8.2"
17-
pydantic = ">= 2"
18-
typing-extensions = ">= 4.7.1"
20+
[project.urls]
21+
Repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID"
22+
23+
[tool.poetry]
24+
requires-poetry = ">=2.0"
1925

20-
[tool.poetry.dev-dependencies]
26+
[tool.poetry.group.dev.dependencies]
2127
pytest = ">= 7.2.1"
2228
pytest-cov = ">= 2.8.1"
2329
tox = ">= 3.9.0"

samples/client/echo_api/python/pyproject.toml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
[tool.poetry]
1+
[project]
22
name = "openapi_client"
33
version = "1.0.0"
44
description = "Echo Server API"
5-
authors = ["OpenAPI Generator Community <[email protected]>"]
5+
authors = [
6+
{name = "OpenAPI Generator Community",email = "[email protected]"},
7+
]
68
license = "Apache 2.0"
79
readme = "README.md"
8-
repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID"
910
keywords = ["OpenAPI", "OpenAPI-Generator", "Echo Server API"]
10-
include = ["openapi_client/py.typed"]
11+
requires-python = "^3.9"
1112

12-
[tool.poetry.dependencies]
13-
python = "^3.9"
13+
dependencies = [
14+
"urllib3 (>=2.1.0,<3.0.0)",
15+
"python-dateutil (>=2.8.2)",
16+
"pydantic (>=2)",
17+
"typing-extensions (>=4.7.1)"
18+
]
1419

15-
urllib3 = ">= 2.1.0, < 3.0.0"
16-
python-dateutil = ">= 2.8.2"
17-
pydantic = ">= 2"
18-
typing-extensions = ">= 4.7.1"
20+
[project.urls]
21+
Repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID"
22+
23+
[tool.poetry]
24+
requires-poetry = ">=2.0"
1925

20-
[tool.poetry.dev-dependencies]
26+
[tool.poetry.group.dev.dependencies]
2127
pytest = ">= 7.2.1"
2228
pytest-cov = ">= 2.8.1"
2329
tox = ">= 3.9.0"

samples/openapi3/client/petstore/python-aiohttp/pyproject.toml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1-
[tool.poetry]
1+
[project]
22
name = "petstore_api"
33
version = "1.0.0"
44
description = "OpenAPI Petstore"
5-
authors = ["OpenAPI Generator Community <[email protected]>"]
5+
authors = [
6+
{name = "OpenAPI Generator Community",email = "[email protected]"},
7+
]
68
license = "Apache-2.0"
79
readme = "README.md"
8-
repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID"
910
keywords = ["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"]
10-
include = ["petstore_api/py.typed"]
11+
requires-python = "^3.9"
1112

12-
[tool.poetry.dependencies]
13-
python = "^3.9"
13+
dependencies = [
14+
"urllib3 (>=2.1.0,<3.0.0)",
15+
"python-dateutil (>=2.8.2)",
16+
"aiohttp (>=3.8.4)",
17+
"aiohttp-retry (>=2.8.3)",
18+
"pem (>=19.3.0)",
19+
"pycryptodome (>=3.9.0)",
20+
"pydantic (>=2)",
21+
"typing-extensions (>=4.7.1)"
22+
]
1423

15-
urllib3 = ">= 2.1.0, < 3.0.0"
16-
python-dateutil = ">= 2.8.2"
17-
aiohttp = ">= 3.8.4"
18-
aiohttp-retry = ">= 2.8.3"
19-
pem = ">= 19.3.0"
20-
pycryptodome = ">= 3.9.0"
21-
pydantic = ">= 2"
22-
typing-extensions = ">= 4.7.1"
24+
[project.urls]
25+
Repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID"
26+
27+
[tool.poetry]
28+
requires-poetry = ">=2.0"
2329

24-
[tool.poetry.dev-dependencies]
30+
[tool.poetry.group.dev.dependencies]
2531
pytest = ">= 7.2.1"
2632
pytest-cov = ">= 2.8.1"
2733
tox = ">= 3.9.0"

samples/openapi3/client/petstore/python/pyproject.toml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1-
[tool.poetry]
1+
[project]
22
name = "petstore_api"
33
version = "1.0.0"
44
description = "OpenAPI Petstore"
5-
authors = ["OpenAPI Generator Community <[email protected]>"]
5+
authors = [
6+
{name = "OpenAPI Generator Community",email = "[email protected]"},
7+
]
68
license = "Apache-2.0"
79
readme = "README.md"
8-
repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID"
910
keywords = ["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"]
10-
include = ["petstore_api/py.typed"]
11+
requires-python = "^3.9"
1112

12-
[tool.poetry.dependencies]
13-
python = "^3.9"
13+
dependencies = [
14+
"urllib3 (>=2.1.0,<3.0.0)",
15+
"python-dateutil (>=2.8.2)",
16+
"pem (>=19.3.0)",
17+
"pycryptodome (>=3.9.0)",
18+
"pydantic (>=2)",
19+
"typing-extensions (>=4.7.1)"
20+
]
1421

15-
urllib3 = ">= 2.1.0, < 3.0.0"
16-
python-dateutil = ">= 2.8.2"
17-
pem = ">= 19.3.0"
18-
pycryptodome = ">= 3.9.0"
19-
pydantic = ">= 2"
20-
typing-extensions = ">= 4.7.1"
22+
[project.urls]
23+
Repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID"
24+
25+
[tool.poetry]
26+
requires-poetry = ">=2.0"
2127

22-
[tool.poetry.dev-dependencies]
28+
[tool.poetry.group.dev.dependencies]
2329
pytest = ">= 7.2.1"
2430
pytest-cov = ">= 2.8.1"
2531
tox = ">= 3.9.0"

0 commit comments

Comments
 (0)