-
Notifications
You must be signed in to change notification settings - Fork 119
SG-40319 SG-41241 version normalize function #1066
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
SG-40319 SG-41241 version normalize function #1066
Conversation
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.
Pull Request Overview
This PR introduces a version normalization function to handle diverse version string formats, ensuring consistent parsing across different software conventions (e.g., Nuke's "6.3v6" format). The changes improve version parsing reliability by standardizing various formats to semantic versioning before parsing.
Key changes:
- Added
_normalize_version_formatfunction to convert various version formats (X.YvZ, X.Y-Z, X.Y, X, vX.Y.Z) into standard X.Y.Z semantic versioning - Updated
version_parseto normalize version strings before parsing withpackaging.version.parse - Reorganized imports for better code organization
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
julien-lang
left a comment
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.
Which code is using this version_parse method?
According to GH search, only a couple of things.
Regarding setup_project_wizard.py, we should change it to:
diff --git a/python/tank/commands/setup_project_wizard.py b/python/tank/commands/setup_project_wizard.py
index 45f11947..82ee1799 100644
--- a/python/tank/commands/setup_project_wizard.py
+++ b/python/tank/commands/setup_project_wizard.py
@@ -716,7 +716,7 @@ class SetupProjectWizard(object):
sg_minor_ver = connection.server_info["version"][1]
sg_patch_ver = connection.server_info["version"][2]
- return version_parse(f"{sg_major_ver}.{sg_minor_ver}.{sg_patch_ver}")
+ return f"{sg_major_ver}.{sg_minor_ver}.{sg_patch_ver}"
def _is_session_based_authentication_supported(self):
"""
@@ -728,10 +728,7 @@ class SetupProjectWizard(object):
"""
# First version to support human based authentication for all operations was
# 6.0.2.
- if self._get_server_version(self._sg) >= version_parse("6.0.2"):
- return True
- else:
- return False
+ return version_parse(self._get_server_version(self._sg)) >= version_parse("6.0.2"):
def execute(self):
"""Consistent with https://github.com/shotgunsoftware/tk-desktop/blob/v2.8.0/python/tk_desktop/desktop_window.py#L1277 and more logical
…function used string comparison in the firsts attemps, which doesn’t work correctly if the new format is not compatible
…function used string comparison in the firsts attemps, which doesn’t work correctly if the new format is not compatible
carlos-villavicencio-adsk
left a comment
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.
Looks good so far.
I might be out of scope, but can I request adding more test cases to this unit test, please?
test_glob_and_match. Specifically, Nuke test cases. See the implenebtation of _glob_and_match to see how it should work.
This function is used by the Nuke engine with this regex to match the version. In my opinion, we can just improve the regex to fix the issue. But if we're adding a centralized solution here, I'd like to add test cases such as the ones from SG-40319 (this ticket).
carlos-villavicencio-adsk
left a comment
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.
That's great. Thanks!
Dismissing this review until we answer Julien's questions.
- Add tank_vendor/packaging with version 25.0 for guaranteed availability - Replace complex fallback logic with direct vendored import - Simplify normalize_version_format with type hints and combined regex patterns - Update test_version_import to focus on import validation only - Fix chaining substitutions in version normalization to prevent InvalidVersion errors
julien-lang
left a comment
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.
Looks good!
carlos-villavicencio-adsk
left a comment
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.
LGTM. Just a couple things:
- I don't know if we need to update the software credits. Please check with @julien-lang
- Let's check if #1071 is also addressed with this PR.
julien-lang
left a comment
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.
LGTM!
Description
This pull request modernizes and simplifies version parsing and comparison logic throughout the codebase, ensuring robust handling of non-standard version formats and eliminating legacy dependencies. The most significant changes are the switch to a vendored version of the
packaginglibrary for version parsing, improved normalization of version strings, and expanded test coverage for complex version patterns.Version parsing and normalization improvements:
LooseVersionanddistutils) inpython/tank/util/version.pywith a vendoredpackaging.version.parseimplementation, ensuring consistent and future-proof version comparisons.normalize_version_formatfunction and supporting regex patterns to convert non-standard version strings (like"6.3v6","2017.2sp1", etc.) into PEP 440–compliant forms before parsing, improving compatibility with a wide range of software versioning schemes. [1] [2]Vendored dependency addition:
packaginglibrary as a vendored dependency underpython/tank_vendor/packaging, including its metadata and required modules for version parsing and comparison. [1] [2]Test suite enhancements:
tests/platform_tests/test_software_launcher.pyto cover more complex version and product patterns, especially for applications like Nuke that use non-standard version formats.tests/util_tests/test_version_compare.pyto include additional edge cases for new normalization logic.tests/util_tests/test_version_import.py, removing legacy dependency checks and verifying availability of new core functions and vendored packaging.Additional context:
This change is required for PR version-related tests in the tk-nuke project to run successfully.
Follow up from #1045