1414MVN_CENTRAL_BASE_URL = "https://central.sonatype.com"
1515
1616
17+ def get_path (cmd : str ) -> str :
18+ path = shutil .which (cmd )
19+ if not path :
20+ msg = f"{ cmd } not found"
21+ raise ValueError (msg )
22+ return path
23+
24+
1725def convert_pre_release_version (version : str ) -> str :
1826 pattern = re .compile (
1927 r"(?P<ver>\d+\.\d+\.\d+)-(?P<stage>[ab])(?:lpha|eta)(?P<revision>\d*)$" ,
@@ -51,7 +59,6 @@ def download_openapi_generator_jar(version: str) -> None:
5159 "wb" ,
5260 ) as openapi_generator_jar :
5361 openapi_generator_jar .write (response .read ())
54- openapi_generator_jar .close ()
5562
5663
5764def get_available_versions () -> set [str ]:
@@ -71,7 +78,7 @@ def get_available_versions() -> set[str]:
7178 return set (versions )
7279
7380
74- def get_published_vesions () -> set [str ]:
81+ def get_published_versions () -> set [str ]:
7582 pypi_url = "https://pypi.org/pypi/openapi-generator-cli/json"
7683 response = urlopen (pypi_url ) # noqa: S310
7784
@@ -107,10 +114,13 @@ def download_latest_jar_for_test() -> None:
107114
108115
109116def publish (* , dryrun : bool = False ) -> None :
110- pytest_path = shutil .which ("pytest" )
111- uv_path = shutil .which ("uv" )
117+ pytest_path = get_path ("pytest" )
118+ uv_path = get_path ("uv" )
119+
120+ testpypi_api_token = os .environ ["TESTPYPI_API_TOKEN" ]
121+ pypi_api_token = os .environ ["PYPI_API_TOKEN" ]
112122
113- unpublished_versions = natsorted (get_available_versions () - get_published_vesions ())
123+ unpublished_versions = natsorted (get_available_versions () - get_published_versions ())
114124
115125 if len (unpublished_versions ) == 0 :
116126 print ("[!] Nothing to be released." )
@@ -140,7 +150,7 @@ def publish(*, dryrun: bool = False) -> None:
140150 "--publish-url" ,
141151 "https://test.pypi.org/legacy/" ,
142152 "--token" ,
143- os . getenv ( "TESTPYPI_API_TOKEN" ) ,
153+ testpypi_api_token ,
144154 "-v" ,
145155 ],
146156 )
@@ -151,7 +161,7 @@ def publish(*, dryrun: bool = False) -> None:
151161 uv_path ,
152162 "publish" ,
153163 "--token" ,
154- os . getenv ( "PYPI_API_TOKEN" ) ,
164+ pypi_api_token ,
155165 "-v" ,
156166 ],
157167 )
0 commit comments