Skip to content

Commit feafbc0

Browse files
committed
SG-42304 Replace OS-specific binary scripts with install_binary.py
install_binary.py is a single cross-platform Python script that replaces install_binary_linux.sh, install_binary_mac.sh and install_binary_windows.ps1. Platform detection is done via sys.platform at runtime. pipelines.yml already calls python install_binary.py - this commit adds the script and removes the three old OS-specific scripts. SG-42304 Clean up pipeline naming and move git add to pipeline steps
1 parent 2a4f310 commit feafbc0

15 files changed

Lines changed: 408 additions & 729 deletions

.snyk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ignore:
88
- resources/python/src/3.10/explicit_requirements.txt
99
- resources/python/src/3.11/explicit_requirements.txt
1010
- resources/python/src/3.13/explicit_requirements.txt
11+
# WHY &&&&??????? that's not what we want to do. Quite the opposite....
1112
exclude:
1213
global:
1314
# Exclude Python 3.7 deps because Snyk only scans with supported versions

azure-pipelines.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ jobs:
3535
- name: tk-framework-desktopclient
3636
- name: tk-shotgun
3737
extra_test_dependencies:
38-
# Required when binary dependencies are not bundled
39-
- attrs==22.2.0 # Fix version. Otherwise tk-ci-tools will install latest
40-
- Twisted==22.10.0 # Last version supporting Python 3.7
41-
- websocket-client==1.6.1 # Last version supporting Python 3.7
38+
# All runtime dependencies come from the unified requirements file.
39+
# This guarantees CI-installed versions match what pkgs.zip bundles,
40+
# preventing sys.modules version conflicts (see SG-42304). TODO
41+
- --requirement=azure-pipelines/requirements.txt
4242
post_tests_steps:
4343
- task: Bash@3
4444
displayName: Run interpreter integration tests

azure-pipelines/requirements.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Required when binary dependencies are not bundled
2+
attrs==22.2.0 # Fix version. Otherwise tk-ci-tools will install latest
3+
## TODO will see later if we can update this ..!.!.!.!
4+
5+
# Twisted must match the version bundled in pkgs.zip/src/ for the corresponding
6+
# Python version. If the test environment installs a different version, it gets
7+
# loaded first and causes a sys.modules version conflict at runtime (see SG-42304).
8+
Twisted==22.10.0; python_version < "3.9"
9+
# Twisted==24.10.0; python_version >= "3.9" and python_version < "3.13"
10+
# Twisted~=24.11.0; python_version >= "3.13"
11+
Twisted~=25.5.0; python_version >= "3.9"
12+
13+
# websocket-client is a test-only dependency (not bundled in pkgs.zip).
14+
# 1.6.2+ dropped Python 3.7 support; our minimum is Python 3.9.
15+
websocket-client==1.6.1; python_version < "3.9" # Last version supporting Python 3.7
16+
websocket-client~=1.9.0; python_version >= "3.9"

resources/python/install_binary.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright (c) 2017 Shotgun Software Inc.
2+
#
3+
# CONFIDENTIAL AND PROPRIETARY
4+
#
5+
# This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit
6+
# Source Code License included in this distribution package. See LICENSE.
7+
# By accessing, using, copying or modifying this work you indicate your
8+
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
9+
# not expressly granted therein are reserved by Shotgun Software Inc.
10+
"""Cross-platform binary requirements installer.
11+
12+
Platform directory mapping:
13+
linux -> bin/<version>/linux
14+
darwin -> bin/<version>/mac
15+
win32 -> bin/<version>/win
16+
17+
Usage: python install_binary.py
18+
"""
19+
20+
import os
21+
import pathlib
22+
import shutil
23+
import sys
24+
25+
from pip._internal.cli.main import main as pip_main
26+
27+
_PLATFORM_DIR = {
28+
"linux": "linux",
29+
"darwin": "mac",
30+
"win32": "win",
31+
}
32+
33+
platform_dir = _PLATFORM_DIR[sys.platform]
34+
35+
python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
36+
bin_dir = pathlib.Path("bin") / python_version / platform_dir
37+
requirements = pathlib.Path("bin") / python_version / "explicit_requirements.txt"
38+
39+
# Delete and recreate the bin directory
40+
shutil.rmtree(bin_dir, ignore_errors=True)
41+
bin_dir.mkdir(parents=True)
42+
43+
# Build pip install arguments
44+
pip_args = [
45+
"install",
46+
"--target",
47+
os.fspath(bin_dir),
48+
"--no-deps",
49+
"--requirement",
50+
os.fspath(requirements),
51+
]
52+
53+
# Linux requires explicit manylinux platform tags so that pip downloads the
54+
# correct pre-built wheels regardless of the host platform.
55+
# See: https://deepwiki.com/pypa/manylinux#policy-and-platform-support-matrix
56+
if sys.platform == "linux":
57+
pip_args += [
58+
"--platform",
59+
"manylinux_2_28_x86_64",
60+
"--platform",
61+
"manylinux2014_x86_64",
62+
"--platform",
63+
"manylinux2010_x86_64",
64+
"--prefer-binary",
65+
]
66+
67+
if pip_main(pip_args) != 0:
68+
raise SystemExit("pip install failed")
69+
70+
# For some reason zope is missing a top-level __init__.py when installed
71+
# with pip, so we add it manually.
72+
(bin_dir / "zope" / "__init__.py").touch()
73+
74+
# Remove test directories to reduce package size
75+
for pattern in [
76+
"Crypto/SelfTest",
77+
"zope/interface/tests",
78+
"zope/interface/*/tests",
79+
]:
80+
for match in bin_dir.glob(pattern):
81+
shutil.rmtree(match, ignore_errors=True)
82+
83+

resources/python/install_binary_linux.sh

Lines changed: 0 additions & 48 deletions
This file was deleted.

resources/python/install_binary_mac.sh

Lines changed: 0 additions & 41 deletions
This file was deleted.

resources/python/install_binary_windows.ps1

Lines changed: 0 additions & 37 deletions
This file was deleted.

resources/python/install_source_only.sh

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
99
# not expressly granted therein are reserved by Shotgun Software Inc.
1010

11+
set -o errexit
12+
1113
echo "----------------------------------------------------"
1214
echo "Get python version"
1315

14-
python_major_version=$(python -c "import sys; print(sys.version_info.major)")
15-
python_minor_version=$(python -c "import sys; print(sys.version_info.minor)")
16-
python_version="$python_major_version.$python_minor_version"
16+
python_major_version="$(python -c "import sys; print(sys.version_info.major)")"
17+
python_minor_version="$(python -c "import sys; print(sys.version_info.minor)")"
18+
python_version="${python_major_version}.${python_minor_version}"
1719

1820
echo "Python version is $python_version"
1921

@@ -22,51 +24,58 @@ echo "Set base paths"
2224

2325
requirements_filename="explicit_requirements.txt"
2426
package_filename="pkgs.zip"
25-
source_dir="src/$python_version"
26-
source_requirements="$source_dir/$requirements_filename"
27+
source_dir="src/${python_version}"
28+
source_requirements="${source_dir}/${requirements_filename}"
2729

2830
echo "Source Dir: $source_dir"
2931
echo "Source Requirements: $source_requirements"
3032

3133
echo "----------------------------------------------------"
3234
echo "Remove current packages"
3335

34-
find $source_dir/* ! -name $package_filename ! -name $requirements_filename -maxdepth 1 -exec rm -rf {} +
36+
find "${source_dir}"/* \
37+
! -name "${package_filename}" \
38+
! -name "${requirements_filename}" \
39+
-maxdepth 1 \
40+
-exec rm --recursive --force {} +
3541

3642
echo "----------------------------------------------------"
3743
echo "Install new packages"
3844

3945
pip install --upgrade pip setuptools wheel
4046

4147
pip install \
42-
--target $source_dir \
48+
--target "${source_dir}" \
4349
--no-deps \
44-
-r $source_requirements
50+
--requirement "${source_requirements}"
4551

4652
echo "----------------------------------------------------"
4753
echo "Remove unnecessary files"
4854

49-
rm -Rf $source_dir/autobahn/test
50-
rm -Rf $source_dir/autobahn/*/test
51-
rm -Rf $source_dir/twisted/test
52-
rm -Rf $source_dir/twisted/*/test
53-
rm -Rf $source_dir/twisted/*/*/test
54-
rm -Rf $source_dir/automat/_test
55-
rm -Rf $source_dir/hyperlink/test
56-
rm -Rf $source_dir/incremental/tests
55+
rm --recursive --force "${source_dir}/autobahn/test"
56+
rm --recursive --force "${source_dir}/autobahn/*/test"
57+
rm --recursive --force "${source_dir}/twisted/test"
58+
rm --recursive --force "${source_dir}/twisted/*/test"
59+
rm --recursive --force "${source_dir}/twisted/*/*/test"
60+
rm --recursive --force "${source_dir}/automat/_test"
61+
rm --recursive --force "${source_dir}/hyperlink/test"
62+
rm --recursive --force "${source_dir}/incremental/tests"
5763

58-
# In twisted.internet.unix, there is a mixin which we don't use that allows to copy file descriptors
59-
# into other processes, which we don't require. That module is compiled, so we'll delete it.
60-
rm -Rf $source_dir/twisted/python/_sendmsg.so
64+
# In twisted.internet.unix, there is a mixin which we don't use that allows to
65+
# copy file descriptors into other processes, which we don't require. That module
66+
# is compiled, so we'll delete it.
67+
rm --recursive --force "${source_dir}/twisted/python/_sendmsg.so"
6168

6269
# Compress all files
63-
pushd $source_dir
64-
zip -q -r pkgs.zip ./*
70+
pushd "${source_dir}"
71+
zip --quiet --recurse-paths pkgs.zip ./*
6572
popd
6673

6774
# Remove files
68-
find $source_dir/* ! -name $package_filename ! -name $requirements_filename -maxdepth 1 -exec rm -rf {} +
75+
find "${source_dir}"/* \
76+
! -name "${package_filename}" \
77+
! -name "${requirements_filename}" \
78+
-maxdepth 1 \
79+
-exec rm --recursive --force {} +
80+
6981

70-
echo "----------------------------------------------------"
71-
echo "Adding new files to git"
72-
git add $source_dir

0 commit comments

Comments
 (0)