14
14
MVN_CENTRAL_BASE_URL = "https://central.sonatype.com"
15
15
16
16
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
+
17
25
def convert_pre_release_version (version : str ) -> str :
18
26
pattern = re .compile (
19
27
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:
51
59
"wb" ,
52
60
) as openapi_generator_jar :
53
61
openapi_generator_jar .write (response .read ())
54
- openapi_generator_jar .close ()
55
62
56
63
57
64
def get_available_versions () -> set [str ]:
@@ -71,7 +78,7 @@ def get_available_versions() -> set[str]:
71
78
return set (versions )
72
79
73
80
74
- def get_published_vesions () -> set [str ]:
81
+ def get_published_versions () -> set [str ]:
75
82
pypi_url = "https://pypi.org/pypi/openapi-generator-cli/json"
76
83
response = urlopen (pypi_url ) # noqa: S310
77
84
@@ -107,10 +114,13 @@ def download_latest_jar_for_test() -> None:
107
114
108
115
109
116
def 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" ]
112
122
113
- unpublished_versions = natsorted (get_available_versions () - get_published_vesions ())
123
+ unpublished_versions = natsorted (get_available_versions () - get_published_versions ())
114
124
115
125
if len (unpublished_versions ) == 0 :
116
126
print ("[!] Nothing to be released." )
@@ -140,7 +150,7 @@ def publish(*, dryrun: bool = False) -> None:
140
150
"--publish-url" ,
141
151
"https://test.pypi.org/legacy/" ,
142
152
"--token" ,
143
- os . getenv ( "TESTPYPI_API_TOKEN" ) ,
153
+ testpypi_api_token ,
144
154
"-v" ,
145
155
],
146
156
)
@@ -151,7 +161,7 @@ def publish(*, dryrun: bool = False) -> None:
151
161
uv_path ,
152
162
"publish" ,
153
163
"--token" ,
154
- os . getenv ( "PYPI_API_TOKEN" ) ,
164
+ pypi_api_token ,
155
165
"-v" ,
156
166
],
157
167
)
0 commit comments