Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: add parse version helper and improve pre-release version parsing#17995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
b1e01900eba65103b3cc9c01e4b3cc9e229bd6b3dd103597cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -91,7 +91,7 @@ else: # pragma: NO COVER | ||
| def parse_version_to_tuple(version_string: str): | ||
| """Safely converts a semantic version string to a comparable tuple of integers. | ||
| Example: "6.33.5" -> (6, 33, 5) | ||
| Example: "6.33.5" -> (6, 33, 5), "1.83.1rc1" -> (1, 83, 1) | ||
| Ignores non-numeric parts and handles common version formats. | ||
| Args: | ||
| version_string: Version string in the format "x.y.z" or "x.y.z<suffix>" | ||
| @@ -100,15 +100,19 @@ else: # pragma: NO COVER | ||
| """ | ||
| parts = [] | ||
| for part in version_string.split("."): | ||
| try: | ||
| parts.append(int(part)) | ||
| except ValueError: | ||
| # If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here. | ||
| # This is a simplification compared to 'packaging.parse_version', but sufficient | ||
| # for comparing strictly numeric semantic versions. | ||
| digits = "" | ||
| for c in part: | ||
| if not c.isdigit(): | ||
| break | ||
| digits += c | ||
| if digits: | ||
| parts.append(int(digits)) | ||
| else: | ||
| break | ||
| return tuple(parts) | ||
ohmayr marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| def _get_version(dependency_name): | ||
| try: | ||
| version_string: str = metadata.version(dependency_name) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -534,3 +534,29 @@ def response_log(logger: logging.Logger, response: Any) -> None: | ||
| if is_logging_enabled(logger): | ||
| json_response = _parse_response(response) | ||
| _response_log_base(logger, json_response) | ||
| def _parse_version_to_tuple(version_string): | ||
ohmayr marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure we need to add the warning to both the clients, and google-auth? That would result in duplicate warnings to most end-users That's probably ok, just wanted to make sure that's the intention | ||
| """Safely converts a semantic version string to a comparable tuple of integers. | ||
| Example: "6.33.5" -> (6, 33, 5), "1.83.1rc1" -> (1, 83, 1) | ||
| Parses leading digits of each component to correctly handle pre-releases. | ||
| Args: | ||
| version_string: Version string in the format "x.y.z" or "x.y.z<suffix>" | ||
| Returns: | ||
| Tuple of integers for the parsed version string. | ||
| """ | ||
| parts = [] | ||
| for part in version_string.split("."): | ||
| digits = "" | ||
| for c in part: | ||
| if not c.isdigit(): | ||
| break | ||
| digits += c | ||
| if digits: | ||
| parts.append(int(digits)) | ||
| else: | ||
| break | ||
| return tuple(parts) | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give more context on how this change will be used?
Keep in mind that if the user has an old version of api_core installed, it will fall back to using that implementation. So if you need to depend on this specific parsing logic, that might be a problem