From f62298b7f0a1e80fa75d29157c2ff589de72fb8c Mon Sep 17 00:00:00 2001 From: Stephen Crowe Date: Wed, 28 Aug 2024 09:34:54 -0700 Subject: [PATCH] chore: create adaptor packaging artifact script (#109) * chore: add script to create adaptor packaging artifact Signed-off-by: wonjoel <127782171+joel-wong-aws@users.noreply.github.com> Signed-off-by: Stephen Crowe Co-authored-by: Joel Wong <127782171+joel-wong-aws@users.noreply.github.com> --- scripts/create_adaptor_packaging_artifact.sh | 157 ++++++++++++++++++ .../KeyShotClient/keyshot_client.py | 2 + 2 files changed, 159 insertions(+) create mode 100644 scripts/create_adaptor_packaging_artifact.sh diff --git a/scripts/create_adaptor_packaging_artifact.sh b/scripts/create_adaptor_packaging_artifact.sh new file mode 100644 index 0000000..1cbb85a --- /dev/null +++ b/scripts/create_adaptor_packaging_artifact.sh @@ -0,0 +1,157 @@ +#!/usr/bin/env bash +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +set -xeou pipefail + +APP_LOWERCASE=keyshot +APP_PASCAL_CASE=KeyShot +ADAPTOR_NAME=deadline-cloud-for-$APP_LOWERCASE + +# This script generates an tar.gz artifact from $ADAPTOR_NAME and its dependencies +# that can be used to create a package for running the adaptor. + +SCRIPTDIR=$(realpath $(dirname $0)) + +SOURCE=0 +# Python 3.11 is for https://vfxplatform.com/ CY2024 +PYTHON_VERSION=3.11 +CONDA_PLATFORM=win-64 +TAR_BASE= + +while [ $# -gt 0 ]; do + case "${1}" in + --source) SOURCE=1 ; shift ;; + --platform) CONDA_PLATFORM="$2" ; shift 2 ;; + --python) PYTHON_VERSION="$2" ; shift 2 ;; + --tar-base) TAR_BASE="$2" ; shift 2 ;; + *) echo "Unexpected option: $1"; exit 1 ;; + esac +done + +if [ "$CONDA_PLATFORM" = "linux-64" ]; then + PYPI_PLATFORM=manylinux2014_x86_64 +elif [ "$CONDA_PLATFORM" = "win-64" ]; then + PYPI_PLATFORM=win_amd64 +elif [ "$CONDA_PLATFORM" = "osx-64" ]; then + PYPI_PLATFORM=macosx_10_9_x86_64 +else + echo "Unknown Conda operating system option --platform $CONDA_PLATFORM" + exit 1 +fi + +if [ "$TAR_BASE" = "" ]; then + TAR_BASE=$SCRIPTDIR/../$APP_LOWERCASE-openjd-py$PYTHON_VERSION-$CONDA_PLATFORM +fi + +# Create a temporary prefix +WORKDIR=$(mktemp -d adaptor-pkg.XXXXXXXXXX) +function cleanup_workdir { + echo "Cleaning up $WORKDIR" + rm -rf $WORKDIR +} +trap cleanup_workdir EXIT + +PREFIX=$WORKDIR/prefix + +if [ "$CONDA_PLATFORM" = "win-64" ]; then + PACKAGEDIR=$PREFIX/Library/opt/$ADAPTOR_NAME +else + PACKAGEDIR=$PREFIX/opt/$ADAPTOR_NAME +fi + + +mkdir -p $PREFIX +mkdir -p $PACKAGEDIR + +# Install the adaptor into the virtual env +if [ $SOURCE = 1 ]; then + # In source mode, openjd-adaptor-runtime-for-python and deadline-cloud must be alongside this adaptor source + RUNTIME_INSTALLABLE=$SCRIPTDIR/../../openjd-adaptor-runtime-for-python + CLIENT_INSTALLABLE=$SCRIPTDIR/../../deadline-cloud + ADAPTOR_INSTALLABLE=$SCRIPTDIR/.. + + if [ "$CONDA_PLATFORM" = "win-64" ]; then + DEPS="pyyaml jsonschema pywin32" + else + DEPS="pyyaml jsonschema" + fi + + for DEP in $DEPS; do + pip install \ + --target $PACKAGEDIR \ + --platform $PYPI_PLATFORM \ + --python-version $PYTHON_VERSION \ + --ignore-installed \ + --only-binary=:all: \ + $DEP + done + + pip install \ + --target $PACKAGEDIR \ + --platform $PYPI_PLATFORM \ + --python-version $PYTHON_VERSION \ + --ignore-installed \ + --no-deps \ + $RUNTIME_INSTALLABLE + + # Install these two at the same time otherwise they overwrite eachother + pip install \ + --target $PACKAGEDIR \ + --platform $PYPI_PLATFORM \ + --python-version $PYTHON_VERSION \ + --only-binary=:all: \ + --ignore-installed \ + $ADAPTOR_INSTALLABLE $CLIENT_INSTALLABLE +else + # In PyPI mode, PyPI and/or a CodeArtifact must have these packages + RUNTIME_INSTALLABLE=openjd-adaptor-runtime + CLIENT_INSTALLABLE=deadline + ADAPTOR_INSTALLABLE=$ADAPTOR_NAME + + pip install \ + --target $PACKAGEDIR \ + --platform $PYPI_PLATFORM \ + --python-version $PYTHON_VERSION \ + --ignore-installed \ + --no-deps \ + $RUNTIME_INSTALLABLE + + # Install these two at the same time otherwise they overwrite eachother + pip install \ + --target $PACKAGEDIR \ + --platform $PYPI_PLATFORM \ + --python-version $PYTHON_VERSION \ + --ignore-installed \ + --only-binary=:all: \ + $ADAPTOR_INSTALLABLE $CLIENT_INSTALLABLE +fi + + +# Remove the submitter code +rm -r $PACKAGEDIR/deadline/*_submitter + +# Remove the bin dir if there is one +if [ -d $PACKAGEDIR/bin ]; then + rm -r $PACKAGEDIR/bin +fi + +# Everything between the first "-" and the next "+" is the package version number +PACKAGEVER=$(cd $PACKAGEDIR; echo deadline_cloud_for*) +PACKAGEVER=${PACKAGEVER#*-} +PACKAGEVER=${PACKAGEVER%+*} +echo "Package version number is $PACKAGEVER" + +# Create the tar artifact +GIT_TIMESTAMP="$(env TZ=UTC git log -1 --date=iso-strict-local --format="%ad")" +pushd $PREFIX +# See https://reproducible-builds.org/docs/archives/ for information about +# these options +#tar --mtime=$GIT_TIMESTAMP \ +# --sort=name \ +# --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime \ +# --owner=0 --group=0 --numeric-owner \ +# -cf $TAR_BASE . +# TODO Switch to the above command once the build environment has tar version > 1.28 +tar --owner=0 --group=0 --numeric-owner \ + -cf $TAR_BASE-$PACKAGEVER.tar.gz . +sha256sum $TAR_BASE-$PACKAGEVER.tar.gz +popd diff --git a/src/deadline/keyshot_adaptor/KeyShotClient/keyshot_client.py b/src/deadline/keyshot_adaptor/KeyShotClient/keyshot_client.py index dc26c46..341d873 100644 --- a/src/deadline/keyshot_adaptor/KeyShotClient/keyshot_client.py +++ b/src/deadline/keyshot_adaptor/KeyShotClient/keyshot_client.py @@ -21,6 +21,8 @@ print("add_dll_directory failed: %s" % p) sys.path.append(p) +# Required for making pywin32 portable. See https://github.com/mhammond/pywin32/blob/main/win32/Lib/pywin32_bootstrap.py +import pywin32_bootstrap # type: ignore # noqa: F401 E402 from types import FrameType # noqa: E402 from typing import Optional # noqa: E402