Skip to content

Conversation

@eduardoChaucaGallegos
Copy link
Contributor

@eduardoChaucaGallegos eduardoChaucaGallegos commented Oct 25, 2025

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 packaging library for version parsing, improved normalization of version strings, and expanded test coverage for complex version patterns.

Version parsing and normalization improvements:

  • Replaced legacy and deprecated version parsing logic (including LooseVersion and distutils) in python/tank/util/version.py with a vendored packaging.version.parse implementation, ensuring consistent and future-proof version comparisons.
  • Added the normalize_version_format function 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:

  • Added the packaging library as a vendored dependency under python/tank_vendor/packaging, including its metadata and required modules for version parsing and comparison. [1] [2]

Test suite enhancements:

  • Updated and expanded tests in tests/platform_tests/test_software_launcher.py to cover more complex version and product patterns, especially for applications like Nuke that use non-standard version formats.
  • Improved version comparison tests in tests/util_tests/test_version_compare.py to include additional edge cases for new normalization logic.
  • Refactored and simplified import tests for the version module in 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

Copy link
Contributor

Copilot AI left a 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_format function 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_parse to normalize version strings before parsing with packaging.version.parse
  • Reorganized imports for better code organization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a 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.

@eduardoChaucaGallegos eduardoChaucaGallegos requested a review from a team October 27, 2025 16:49
Copy link
Contributor

@julien-lang julien-lang left a 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
Copy link
Contributor

@carlos-villavicencio-adsk carlos-villavicencio-adsk left a 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).

Copy link
Contributor

@carlos-villavicencio-adsk carlos-villavicencio-adsk left a 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!

@carlos-villavicencio-adsk carlos-villavicencio-adsk dismissed their stale review November 13, 2025 20:00

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
@eduardoChaucaGallegos eduardoChaucaGallegos changed the title SG-40319 version normalize function SG-40319 SG-41241 version normalize function Nov 24, 2025
Copy link
Contributor

@julien-lang julien-lang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Copy link
Contributor

@carlos-villavicencio-adsk carlos-villavicencio-adsk left a 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:

  1. I don't know if we need to update the software credits. Please check with @julien-lang
  2. Let's check if #1071 is also addressed with this PR.

Copy link
Contributor

@julien-lang julien-lang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@eduardoChaucaGallegos eduardoChaucaGallegos merged commit a449564 into master Nov 27, 2025
24 checks passed
@eduardoChaucaGallegos eduardoChaucaGallegos deleted the ticket/SG-40319-version-normalize branch November 27, 2025 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants