Skip to content

Commit 4a4b183

Browse files
committed
Added safe python identification mode
1 parent 32a3291 commit 4a4b183

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

versions.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
def get_all_python_versions():
2020
"""
2121
Retrieve all supported Python versions (i.e., not end-of-life)
22+
23+
Note that all versions are returned in descending order
2224
"""
2325
python_versions = (
2426
pd.read_html(
@@ -41,6 +43,14 @@ def get_all_python_versions_in_range(start, stop):
4143
print(json.dumps(python_versions[start_idx : stop_idx + 1]))
4244

4345

46+
def get_safe_python_version():
47+
"""
48+
Retrieve the n-2 Python release version
49+
"""
50+
python_versions = get_all_python_versions()[::-1] # Reverse order
51+
print(python_versions[-3])
52+
53+
4454
def get_min_python_version():
4555
"""
4656
Find the minimum version of Python supported (i.e., not end-of-life)
@@ -442,7 +452,10 @@ def get_all_min_versions(MIN_PYTHON):
442452
if __name__ == "__main__":
443453
parser = argparse.ArgumentParser()
444454
parser.add_argument(
445-
"-mode", type=str, default="min", help='Options: ["min", "max", "range"]'
455+
"-mode",
456+
type=str,
457+
default="min",
458+
help='Options: ["min", "max", "range", "safe"]',
446459
)
447460
parser.add_argument("python_version", nargs="*", default=None)
448461
args = parser.parse_args()
@@ -469,5 +482,7 @@ def get_all_min_versions(MIN_PYTHON):
469482
start = args.python_version[0]
470483
stop = args.python_version[1]
471484
get_all_python_versions_in_range(start, stop)
485+
elif args.mode == "safe":
486+
get_safe_python_version()
472487
else:
473488
raise ValueError(f'Unrecognized mode: "{args.mode}"')

0 commit comments

Comments
 (0)