|
| 1 | +# Copyright 2026 Autodesk, Inc. All rights reserved. |
| 2 | +# |
| 3 | +# Use of this software is subject to the terms of the Autodesk license agreement |
| 4 | +# provided at the time of installation or download, or which otherwise accompanies |
| 5 | +# this software in either electronic or hard copy form. |
| 6 | +# |
| 7 | + |
| 8 | +""" |
| 9 | +Validate that developer scripts work correctly even when sgtk is also |
| 10 | +installed via pip in the same Python environment. |
| 11 | +
|
| 12 | +This ensures that developer scripts always use the local tk-core |
| 13 | +(via sys.path.insert) and not the pip-installed version. |
| 14 | +""" |
| 15 | + |
| 16 | +import os |
| 17 | +import subprocess # nosec B404 |
| 18 | +import sys |
| 19 | +import tempfile |
| 20 | +import unittest |
| 21 | + |
| 22 | +from sgtk_integration_test import SgtkIntegrationTest |
| 23 | + |
| 24 | + |
| 25 | +class DeveloperScriptsTests(SgtkIntegrationTest): |
| 26 | + """Validate developer scripts work with pip sgtk installed. |
| 27 | +
|
| 28 | + Creates a temporary venv with sgtk pip-installed, then runs each |
| 29 | + developer script from that venv to confirm they still prioritize |
| 30 | + the local tk-core (via sys.path.insert) over site-packages. |
| 31 | + """ |
| 32 | + |
| 33 | + @classmethod |
| 34 | + def _get_venv_python(cls, venv_dir): |
| 35 | + """Return the path to the Python executable inside the venv.""" |
| 36 | + if sys.platform == "win32": |
| 37 | + return os.path.join(venv_dir, "Scripts", "python.exe") |
| 38 | + return os.path.join(venv_dir, "bin", "python") |
| 39 | + |
| 40 | + @classmethod |
| 41 | + def setUpClass(cls): |
| 42 | + """Create a temp venv and install sgtk via pip.""" |
| 43 | + super().setUpClass() |
| 44 | + cls._venv_dir = tempfile.mkdtemp(prefix="test_dev_scripts_") |
| 45 | + subprocess.check_call( # nosec B603 |
| 46 | + [sys.executable, "-m", "venv", cls._venv_dir] |
| 47 | + ) |
| 48 | + cls._venv_python = cls._get_venv_python(cls._venv_dir) |
| 49 | + subprocess.check_call( # nosec B603 |
| 50 | + [cls._venv_python, "-m", "pip", "install", cls.tk_core_repo_root] |
| 51 | + ) |
| 52 | + |
| 53 | + def test_bake_config(self): |
| 54 | + """Validate bake_config.py --help works.""" |
| 55 | + script = os.path.join(self.tk_core_repo_root, "developer", "bake_config.py") |
| 56 | + subprocess.check_call([self._venv_python, script, "--help"]) # nosec B603 |
| 57 | + |
| 58 | + def test_build_plugin(self): |
| 59 | + """Validate build_plugin.py --help works.""" |
| 60 | + script = os.path.join(self.tk_core_repo_root, "developer", "build_plugin.py") |
| 61 | + subprocess.check_call([self._venv_python, script, "--help"]) # nosec B603 |
| 62 | + |
| 63 | + def test_populate_bundle_cache(self): |
| 64 | + """Validate populate_bundle_cache.py --help works.""" |
| 65 | + script = os.path.join( |
| 66 | + self.tk_core_repo_root, "developer", "populate_bundle_cache.py" |
| 67 | + ) |
| 68 | + subprocess.check_call([self._venv_python, script, "--help"]) # nosec B603 |
| 69 | + |
| 70 | + |
| 71 | +if __name__ == "__main__": |
| 72 | + unittest.main(failfast=True, verbosity=2) |
0 commit comments