Skip to content

Commit 056c67d

Browse files
committed
Fix substitution for package version
1 parent 9b90ea0 commit 056c67d

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

publish.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
import os
5+
import re
56
import shutil
67
import subprocess
78
from pathlib import Path
@@ -37,19 +38,6 @@ def download_openapi_generator_jar(version: str) -> None:
3738
openapi_generator_jar.write(response.read())
3839
openapi_generator_jar.close()
3940

40-
updated_toml = (
41-
Path("pyproject.toml") # noqa: SIM115
42-
.open("r")
43-
.read()
44-
.replace(
45-
'[tool.poetry]\nversion = "0"',
46-
f'[tool.poetry]\nversion = "{version}"',
47-
1,
48-
)
49-
)
50-
with Path("pyproject.toml").open("w") as toml:
51-
toml.write(updated_toml)
52-
5341

5442
def get_available_versions() -> list[str]:
5543
mvn_url = (
@@ -77,6 +65,18 @@ def get_published_vesions() -> KeysView[str]:
7765
return published_releases.keys()
7866

7967

68+
def update_package_version(version: str) -> None:
69+
updated_toml = re.sub(
70+
r'(?<=\[tool.poetry\]\nversion = ")[^"]+(?=")',
71+
version,
72+
Path("pyproject.toml").open("r").read(), # noqa: SIM115
73+
count=1,
74+
flags=(re.MULTILINE),
75+
)
76+
with Path("pyproject.toml").open("w") as toml:
77+
toml.write(updated_toml)
78+
79+
8080
def download_latest_jar_for_test() -> None:
8181
latest_version = natsorted(get_available_versions())[-1]
8282
print(f"[{latest_version}] Downloading...")
@@ -94,6 +94,9 @@ def publish(*, dryrun: bool = False) -> None:
9494
print(f"[{publishing_version}] Downloading...")
9595
download_openapi_generator_jar(publishing_version)
9696

97+
print(f"[{publishing_version}] Updating package version...")
98+
update_package_version(publishing_version)
99+
97100
print(f"[{publishing_version}] Testing...")
98101
subprocess.check_call([pytest_path])
99102

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ requires = [
77
]
88

99
[tool.poetry]
10-
version = "7.10.0"
10+
version = "0"
1111
authors = [
1212
"OpenAPI Generator community <team@openapitools.org>",
1313
]

0 commit comments

Comments
 (0)