11from __future__ import annotations
22
33import json
4- import os
4+ import shutil
55import subprocess
6+ from pathlib import Path
67from typing import TYPE_CHECKING
78from urllib .request import urlopen
89
@@ -22,31 +23,32 @@ def download_openapi_generator_jar(version: str) -> None:
2223 + ".jar"
2324 )
2425
25- if os .path .exists ("openapi-generator.jar" ):
26- os .remove ("openapi-generator.jar" )
26+ Path ("openapi-generator.jar" ).unlink (missing_ok = True )
2727
2828 print (download_url )
29- response = urlopen (download_url )
29+ response = urlopen (download_url ) # noqa: S310
3030
31- if response .status != 200 :
32- raise RuntimeError (f"{ response .status } : { download_url } " )
31+ if response .status != 200 : # noqa: PLR2004
32+ msg = f"{ response .status } : { download_url } "
33+ raise RuntimeError (msg )
3334
3435 print ("Downloading complete" )
3536
36- with open ("openapi_generator_cli/openapi-generator.jar" , "wb" ) as openapi_generator_jar :
37+ with Path ("openapi_generator_cli/openapi-generator.jar" ). open ( "wb" ) as openapi_generator_jar :
3738 openapi_generator_jar .write (response .read ())
3839 openapi_generator_jar .close ()
3940
4041 updated_toml = (
41- open ("pyproject.toml" )
42+ Path ("pyproject.toml" ) # noqa: SIM115
43+ .open ("r" )
4244 .read ()
4345 .replace (
4446 '[tool.poetry]\n version = "0"' ,
4547 f'[tool.poetry]\n version = "{ version } "' ,
4648 1 ,
4749 )
4850 )
49- with open ("pyproject.toml" , "w" ) as toml :
51+ with Path ("pyproject.toml" ). open ( "w" ) as toml :
5052 toml .write (updated_toml )
5153
5254
@@ -55,21 +57,23 @@ def get_available_versions() -> list[str]:
5557 MVN_BASE_URL + "/solrsearch/select?q=g:org.openapitools+AND+a:openapi-generator-cli&core=gav"
5658 "&start=0&rows=200"
5759 )
58- response = urlopen (mvn_url )
60+ response = urlopen (mvn_url ) # noqa: S310
5961 docs = json .loads (response .read ())["response" ]["docs" ]
6062 return [doc ["v" ] for doc in docs ]
6163
6264
6365def get_published_vesions () -> KeysView [str ]:
6466 pypi_url = "https://pypi.org/pypi/openapi-generator-cli/json"
65- response = urlopen (pypi_url )
67+ response = urlopen (pypi_url ) # noqa: S310
6668
67- if response .status != 200 :
68- raise RuntimeError (f"{ response .status } : { pypi_url } " )
69+ if response .status != 200 : # noqa: PLR2004
70+ msg = f"{ response .status } : { pypi_url } "
71+ raise RuntimeError (msg )
6972
7073 published_releases = json .loads (response .read ()).get ("releases" )
7174 if not isinstance (published_releases , dict ):
72- raise TypeError (f"Expected dict, got { type (published_releases )} " )
75+ msg = f"Expected dict, got { type (published_releases )} "
76+ raise TypeError (msg )
7377
7478 return published_releases .keys ()
7579
@@ -81,9 +85,10 @@ def publish() -> None:
8185 if latest_version not in published_versions :
8286 print ("Publishing version " + latest_version )
8387 download_openapi_generator_jar (latest_version )
84- subprocess .check_call ("poetry build" , shell = True )
85- subprocess .check_call ("poetry publish -r testpypi" , shell = True )
86- subprocess .check_call ("poetry publish" , shell = True )
88+ poetry_path = shutil .which ("poetry" )
89+ subprocess .check_call ([poetry_path , "build" ]) # noqa: S603
90+ subprocess .check_call ([poetry_path , "publish" , "-r" , "testpypi" ]) # noqa: S603
91+ subprocess .check_call ([poetry_path , "publish" ]) # noqa: S603
8792
8893
8994if __name__ == "__main__" :
0 commit comments