Skip to content

SG-42625 Fix tank_vendor imports for pip installations and developer scripts#1091

Open
eduardoChaucaGallegos wants to merge 9 commits intomasterfrom
ticket/SG-42625-developer-scripts
Open

SG-42625 Fix tank_vendor imports for pip installations and developer scripts#1091
eduardoChaucaGallegos wants to merge 9 commits intomasterfrom
ticket/SG-42625-developer-scripts

Conversation

@eduardoChaucaGallegos
Copy link
Contributor

@eduardoChaucaGallegos eduardoChaucaGallegos commented Mar 16, 2026

Two related fixes for import failures introduced by the pkgs.zip architecture in tk-core v0.23.x.

Fix 1 - Developer scripts use sys.path.insert instead of append

The developer scripts used sys.path.append() to add the local tk-core, but
append() puts it at the end of sys.path, so any sgtk installed in
site-packages takes precedence and fails because it lacks pkgs.zip.

Changed to sys.path.insert(0, ...) in bake_config.py, build_plugin.py and
populate_bundle_cache.py.

Fix 2 - Add install_requires to setup.py

When sgtk is installed via pip, the requirements/ directory (containing
pkgs.zip) is not included. The tank_vendor import hook falls back to loading
packages from the Python environment, but they are not installed because
setup.py had no install_requires.

Added get_install_requires() that reads dependencies from
requirements/<python_version>/requirements.txt, keeping versions in sync
with pkgs.zip.

Testing

  • Created a fresh venv, ran pip install -e .
  • Verified import sgtk works
  • Verified from tank_vendor.shotgun_api3 import Shotgun works
  • Verified from tank_vendor.shotgun_api3.lib import httplib2 works

Fixes for issues: #1090

@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.42%. Comparing base (28f457c) to head (25dabb0).

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

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.

@eduardoChaucaGallegos eduardoChaucaGallegos requested a review from a team March 16, 2026 21:09
@carlos-villavicencio-adsk
Copy link
Contributor

Hi @eduardoChaucaGallegos , can you also check if this case is covered here?

@eduardoChaucaGallegos eduardoChaucaGallegos changed the title SG-42625 imports for developer scripts fixed SG-42625 Fix tank_vendor imports for pip installations and developer scripts Mar 19, 2026
Copy link
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.

One thing I don't understand in this PR is why those issues sudently created problems? What was the cause and why?

Copy link
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.

LGTM!

@eduardoChaucaGallegos
Copy link
Contributor Author

One thing I don't understand in this PR is why those issues sudently created problems? What was the cause and why?

Good question - full context is in SG-42625, but here's the short version.

These bugs are latent - they always existed but only became visible as pip installs of sgtk are becoming more common outside the standard Toolkit/DCC workflow. Both issues were introduced (or exposed) by the task that reorganized third-party dependencies into requirements/<python_version>/pkgs.zip.

Two independent root causes:

1. Developer scripts used sys.path.append instead of sys.path.insert(0, ...)
If sgtk was already pip-installed, Python would find it in site-packages first and the scripts would silently run against the wrong tank module.

2. setup.py had no install_requires
pkgs.zip is not included in a pip install and setup.py was never updated to declare the dependencies. So pip would install successfully but fail at runtime with ModuleNotFoundError: No module named tank_vendor.shotgun_api3. The fix reads pinned versions from the existing requirements/<python_version>/requirements.txt to stay in sync with pkgs.zip.

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.

3 participants