File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 6363except ImportError :
6464 HAS_UNIVERSE = False
6565
66- from google .api_core ._python_package_support import parse_version_to_tuple
6766from googleapiclient import _helpers as util
6867from googleapiclient .discovery import (DISCOVERY_URI ,
6968 MEDIA_BODY_PARAMETER_DEFAULT_VALUE ,
@@ -142,6 +141,28 @@ def read_datafile(filename, mode="r"):
142141 with open (datafile (filename ), mode = mode ) as f :
143142 return f .read ()
144143
144+ def parse_version_to_tuple (version_string : str ) -> ParsedVersion :
145+ """Safely converts a semantic version string to a comparable tuple of integers.
146+
147+ Example: "4.25.8" -> (4, 25, 8)
148+ Ignores non-numeric parts and handles common version formats.
149+
150+ Args:
151+ version_string: Version string in the format "x.y.z" or "x.y.z<suffix>"
152+
153+ Returns:
154+ Tuple of integers for the parsed version string.
155+ """
156+ parts = []
157+ for part in version_string .split ("." ):
158+ try :
159+ parts .append (int (part ))
160+ except ValueError :
161+ # If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here.
162+ # This is a simplification compared to 'packaging.parse_version', but sufficient
163+ # for comparing strictly numeric semantic versions.
164+ break
165+ return tuple (parts )
145166
146167class SetupHttplib2 (unittest .TestCase ):
147168 def test_retries (self ):
You can’t perform that action at this time.
0 commit comments