Skip to content

SG-37222 new way to handle python third parties#996

Merged
eduardoChaucaGallegos merged 47 commits intomasterfrom
ticket/SG-37222-python-third-parties
Mar 11, 2026
Merged

SG-37222 new way to handle python third parties#996
eduardoChaucaGallegos merged 47 commits intomasterfrom
ticket/SG-37222-python-third-parties

Conversation

@eduardoChaucaGallegos
Copy link
Copy Markdown
Contributor

@eduardoChaucaGallegos eduardoChaucaGallegos commented Dec 31, 2024

This pull request introduces a major overhaul to the way third-party Python dependencies are managed and loaded in the project, focusing on the tank_vendor mechanism. The changes centralize dependency management using versioned pkgs.zip files, implement a robust dynamic import hook for the tank_vendor namespace, and improve documentation and maintainability. Legacy or redundant scripts and files are removed, and package-specific patches are handled more cleanly.

Dependency Management and Loading Redesign:

  • Introduced a new dynamic loading mechanism in tank_vendor/__init__.py that auto-discovers and loads third-party packages from version-specific pkgs.zip files, supports lazy aliasing for the tank_vendor.* namespace, and applies package-specific patches (e.g., for shotgun_api3 SSL certificates). This includes a custom meta path finder and robust error handling for missing or invalid ZIP files.
  • Updated the documentation in developer/README.md to describe the new requirements folder structure, the workflow for updating bundled dependencies, and the rationale behind using pkgs.zip files for consistent and reproducible environments. [1] [2]

Import and Compatibility Improvements:

  • Enhanced the import handler in python/tank/bootstrap/import_handler.py to correctly skip SourceFileLoader for modules inside ZIP files, ensuring compatibility with the new packaging approach.
  • Removed the legacy upgrade_pyyaml.py script, as dependency upgrades are now handled via the new requirements workflow and automation.

Cleanup and Maintenance:

  • Removed redundant or now-unmanaged files from vendored packages, such as packaging/__init__.py and packaging/_structures.py, as these are now managed within the ZIP-based dependency system. [1] [2]
  • Updated copyright years and added detailed module-level docstrings.

These changes modernize and streamline dependency management for the project, making it more maintainable and robust across Python versions and environments.

Resolves #914

@julien-lang julien-lang requested a review from a team January 6, 2025 16:29
Comment thread developer/requirements.txt Outdated
Comment thread python/tank_vendor/__init__.py Outdated
Comment thread python/tank_vendor/__init__.py
Comment thread python/tank_vendor/__init__.py Outdated
Comment thread requirements/3.10/frozen_requirements.txt Outdated
Comment thread update_python_packages.py Outdated
Comment thread update_python_packages.py Outdated
Comment thread update_python_packages.py Outdated
Comment thread requirements/3.11/requirements.txt Outdated
Comment thread update_python_packages.py Outdated
@eduardoChaucaGallegos eduardoChaucaGallegos marked this pull request as draft January 28, 2025 17:30
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.42%. Comparing base (187b794) to head (a9a1aa3).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #996   +/-   ##
=======================================
  Coverage   79.42%   79.42%           
=======================================
  Files         198      198           
  Lines       20749    20751    +2     
=======================================
+ Hits        16479    16481    +2     
  Misses       4270     4270           
Flag Coverage Δ
Linux 78.89% <100.00%> (+<0.01%) ⬆️
Python-3.10 79.24% <100.00%> (+<0.01%) ⬆️
Python-3.11 79.00% <100.00%> (-0.14%) ⬇️
Python-3.13 79.14% <100.00%> (+<0.01%) ⬆️
Python-3.9 79.21% <100.00%> (+<0.01%) ⬆️
Windows 78.92% <100.00%> (+<0.01%) ⬆️
macOS 78.90% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread developer/requirements.txt
Comment thread python/tank/platform/environment.py Outdated
Comment thread requirements/3.11/frozen_requirements.txt
Comment thread update_python_packages.py Outdated
Comment thread update_python_packages.py Outdated
Comment thread update_python_packages.py Outdated
Comment thread update_python_packages.py Outdated
Comment thread update_python_packages.py Outdated
Comment thread python/tank/bootstrap/import_handler.py Outdated
Comment thread requirements/3.7/requirements.txt
Comment thread requirements/update_python_packages.py
Comment thread python/tank_vendor/__init__.py
Copy link
Copy Markdown
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. The init.py file it's too big in my opinion. It would be great to have a better organization/modularization there. Maybe we can consider using a main.py file? These are just thoughts.

Besides this, I think we should start testing this throughoutly.

Comment thread python/tank_vendor/__init__.py Outdated
Comment thread python/tank_vendor/__init__.py Outdated
Copy link
Copy Markdown
Member

@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.

A few changes please. Also, I agree with all comments from Charlie so could you address them please?

And could you add some unit tests validating the import and handle of third partiy libs

Comment thread python/tank_vendor/__init__.py Outdated
Comment thread python/tank_vendor/__init__.py
Comment thread tests/core_tests/test_tank_vendor.py
@eduardoChaucaGallegos eduardoChaucaGallegos merged commit 28f457c into master Mar 11, 2026
20 checks passed
@eduardoChaucaGallegos eduardoChaucaGallegos deleted the ticket/SG-37222-python-third-parties branch March 11, 2026 15:50
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