Skip to content

Commit 22b394a

Browse files
committed
Fixed black formatting
1 parent d815750 commit 22b394a

File tree

1 file changed

+29
-45
lines changed

1 file changed

+29
-45
lines changed

versions.py

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ def get_minor_versions_between(start_version_str, end_version_str):
184184
to the end version, or if major versions differ.
185185
"""
186186
try:
187-
start_parts = [int(x) for x in start_version_str.split('.')]
188-
end_parts = [int(x) for x in end_version_str.split('.')]
187+
start_parts = [int(x) for x in start_version_str.split(".")]
188+
end_parts = [int(x) for x in end_version_str.split(".")]
189189
except ValueError:
190190
raise ValueError("Invalid version string format. Expected 'MAJOR.MINOR.PATCH'.")
191191

@@ -200,7 +200,9 @@ def get_minor_versions_between(start_version_str, end_version_str):
200200
return []
201201

202202
if start_minor >= end_minor:
203-
print("Warning: Start minor version is not less than end minor version. Returning an empty list.")
203+
print(
204+
"Warning: Start minor version is not less than end minor version. Returning an empty list."
205+
)
204206
return []
205207

206208
versions = []
@@ -212,25 +214,24 @@ def get_minor_versions_between(start_version_str, end_version_str):
212214

213215
def get_latest_numpy_version():
214216
url = "https://pypi.org/project/numpy/"
215-
req = request.Request(
216-
url,
217-
data=None,
218-
headers=HEADERS
219-
)
217+
req = request.Request(url, data=None, headers=HEADERS)
220218
html = request.urlopen(req).read().decode("utf-8")
221-
match = re.search(r'numpy (\d+\.\d+\.\d+)', html, re.DOTALL)
219+
match = re.search(r"numpy (\d+\.\d+\.\d+)", html, re.DOTALL)
222220
return match.groups()[0]
223221

224222

225223
def check_python_version(row):
226-
versions = get_minor_versions_between(row.START_PYTHON_VERSION, row.END_PYTHON_VERSION)
224+
versions = get_minor_versions_between(
225+
row.START_PYTHON_VERSION, row.END_PYTHON_VERSION
226+
)
227227

228228
compatible_version = None
229229
for version in versions:
230230
if Version(version) in row.NUMBA_PYTHON_SPEC & row.SCIPY_PYTHON_SPEC:
231231
compatible_version = version
232232
return compatible_version
233233

234+
234235
def check_numpy_version(row):
235236
if row.NUMPY in row.NUMPY_SPEC:
236237
return row.NUMPY
@@ -277,41 +278,27 @@ def get_all_max_versions():
277278
).apply(SpecifierSet)
278279
)
279280
)
280-
.assign(
281-
NUMPY = get_latest_numpy_version()
282-
)
281+
.assign(NUMPY=get_latest_numpy_version())
283282
.pipe(
284283
lambda df: df.assign(
285284
NUMPY_SPEC=(
286-
df.NumPy
287-
.str.replace(r' [;†\.]$', '', regex=True)
288-
.str.split().str[-2:].replace({".x": ""}, regex=True)
289-
.str.join('')
285+
df.NumPy.str.replace(r" [;†\.]$", "", regex=True)
286+
.str.split()
287+
.str[-2:]
288+
.replace({".x": ""}, regex=True)
289+
.str.join("")
290290
).apply(SpecifierSet)
291291
)
292292
)
293-
.assign(
294-
NUMPY=lambda row: row.apply(
295-
check_numpy_version, axis=1
296-
)
297-
)
298-
.assign(
299-
SCIPY = get_scipy_version_df().iloc[0].SciPy_version
300-
)
301-
.assign(
302-
SCIPY_PYTHON_SPEC = get_scipy_version_df().iloc[0].Python_versions
303-
)
293+
.assign(NUMPY=lambda row: row.apply(check_numpy_version, axis=1))
294+
.assign(SCIPY=get_scipy_version_df().iloc[0].SciPy_version)
295+
.assign(SCIPY_PYTHON_SPEC=get_scipy_version_df().iloc[0].Python_versions)
304296
.pipe(
305-
lambda df:
306-
df.assign(
307-
SCIPY_PYTHON_SPEC = df.SCIPY_PYTHON_SPEC.apply(SpecifierSet)
308-
)
309-
)
310-
.assign(
311-
MAX_PYTHON=lambda row: row.apply(
312-
check_python_version, axis=1
297+
lambda df: df.assign(
298+
SCIPY_PYTHON_SPEC=df.SCIPY_PYTHON_SPEC.apply(SpecifierSet)
313299
)
314300
)
301+
.assign(MAX_PYTHON=lambda row: row.apply(check_python_version, axis=1))
315302
.pipe(lambda df: df.assign(MAJOR=df.MAX_PYTHON.str.split(".").str[0]))
316303
.pipe(lambda df: df.assign(MINOR=df.MAX_PYTHON.str.split(".").str[1]))
317304
.sort_values(["MAJOR", "MINOR"], ascending=[False, False])
@@ -326,9 +313,6 @@ def get_all_max_versions():
326313
)
327314

328315

329-
330-
331-
332316
def match_pkg_version(line, pkg_name):
333317
"""
334318
Regular expression to match package versions
@@ -437,27 +421,27 @@ def get_all_min_versions(MIN_PYTHON):
437421
)
438422

439423

440-
441424
if __name__ == "__main__":
442425
parser = argparse.ArgumentParser()
443-
parser.add_argument("-mode", type=str, default='min', help='Options: ["min", "max"]')
426+
parser.add_argument(
427+
"-mode", type=str, default="min", help='Options: ["min", "max"]'
428+
)
444429
parser.add_argument("python_version", nargs="?", default=None)
445430
args = parser.parse_args()
446431
# Example
447432
# ./versions.py
448433
# ./versions.py 3.11
449434
# ./versions.py -mode max
450435

451-
print(f'mode: {args.mode}')
436+
print(f"mode: {args.mode}")
452437

453-
if args.mode == 'min':
438+
if args.mode == "min":
454439
if args.python_version is not None:
455440
MIN_PYTHON = str(args.python_version)
456441
else:
457442
MIN_PYTHON = get_min_python_version()
458443
get_all_min_versions(MIN_PYTHON)
459-
elif args.mode == 'max':
444+
elif args.mode == "max":
460445
get_all_max_versions()
461446
else:
462447
raise ValueError(f'Unrecognized mode: "{args.mode}"')
463-

0 commit comments

Comments
 (0)