1- import distutils .version
21import json
2+ import re
33import sys
44import urllib .request
55
6- distutils .version .StrictVersion
6+ class SimpleVersion :
7+ """
8+ A simple version class using only the Python standard library.
9+
10+ This class is intended as a minimal replacement for standard library components
11+ such as distutils.version.StrictVersion, supporting only a subset of versioning features.
12+
13+ Supported version format:
14+ - Version strings must be in the form "X.Y.Z", where X, Y, and Z are integers.
15+ - Example: "1.9.3"
16+ - No support for pre-releases, post-releases, alpha/beta/rc tags, or other PEP 440 features.
17+
18+ Comparison behavior:
19+ - Versions are compared lexicographically by (major, minor, micro) components.
20+ - Only equality and less-than comparisons are implemented.
21+
22+ Limitations:
23+ - Only the "X.Y.Z" format is accepted; other formats will raise ValueError.
24+ - Does not support version strings with fewer or more than three components.
25+ - Does not support non-numeric version parts.
26+ - Not a drop-in replacement for distutils.version.StrictVersion or packaging.version.Version.
27+ """
28+ def __init__ (self , version_string ):
29+ self .version_string = version_string
30+ # Parse version string like "1.9.3" into components
31+ match = re .match (r'^(\d+)\.(\d+)\.(\d+)$' , version_string )
32+ if not match :
33+ raise ValueError (f"Invalid version string: { version_string } " )
34+ self .major = int (match .group (1 ))
35+ self .minor = int (match .group (2 ))
36+ self .micro = int (match .group (3 ))
37+
38+ def __lt__ (self , other ):
39+ if not isinstance (other , SimpleVersion ):
40+ return NotImplemented
41+ return (self .major , self .minor , self .micro ) < (other .major , other .minor , other .micro )
42+
43+ def __eq__ (self , other ):
44+ if not isinstance (other , SimpleVersion ):
45+ return NotImplemented
46+ return (self .major , self .minor , self .micro ) == (other .major , other .minor , other .micro )
47+
48+ def __str__ (self ):
49+ return self .version_string
750
851def download_versions_json (url = "https://julialang-s3.julialang.org/bin/versions.json" ):
952 request = urllib .request .Request (url )
@@ -20,18 +63,18 @@ def get_stable_versions(parsed_json):
2063 if is_stable :
2164 stable_version_strings .append (key )
2265 stable_version_strings_unique = list (set (stable_version_strings ))
23- stable_versions = [distutils . version . StrictVersion (s ) for s in stable_version_strings_unique ]
66+ stable_versions = [SimpleVersion (s ) for s in stable_version_strings_unique ]
2467 stable_versions .sort ()
2568 return stable_versions
2669
27- def get_major (version ):
28- return version . version [ 0 ]
70+ def get_major (version_obj ):
71+ return version_obj . major
2972
30- def get_minor (version ):
31- return version . version [ 1 ]
73+ def get_minor (version_obj ):
74+ return version_obj . minor
3275
33- def get_patch (version ):
34- return version . version [ 2 ]
76+ def get_patch (version_obj ):
77+ return version_obj . micro
3578
3679def get_highest_minor_matching_major (versions_list , major ):
3780 all_majors = [get_major (v ) for v in versions_list ]
0 commit comments