22
33import json
44import os
5+ import re
56import shutil
67import subprocess
78from 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]\n version = "0"' ,
46- f'[tool.poetry]\n version = "{ version } "' ,
47- 1 ,
48- )
49- )
50- with Path ("pyproject.toml" ).open ("w" ) as toml :
51- toml .write (updated_toml )
52-
5341
5442def 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+
8080def 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
0 commit comments