|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2024 Advanced Micro Devices, Inc. |
| 4 | +# |
| 5 | +# Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 6 | +# See https://llvm.org/LICENSE.txt for license information. |
| 7 | +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 8 | + |
| 9 | +# This script promotes Python packages from nightly releases to PyPI. |
| 10 | +# |
| 11 | +# Prerequisites: |
| 12 | +# * You will need to have PyPI credentials set up. See |
| 13 | +# https://packaging.python.org/en/latest/tutorials/packaging-projects/#uploading-the-distribution-archives |
| 14 | +# * Install requirements, e.g. in a Python virtual environment (venv): |
| 15 | +# `pip install -r requirements-pypi-deploy.txt` |
| 16 | +# * Install python3.13t and install pip. On Ubuntu: |
| 17 | +# ```bash |
| 18 | +# sudo add-apt-repository ppa:deadsnakes |
| 19 | +# sudo apt-get update |
| 20 | +# sudo apt-get install python3.13-nogil |
| 21 | +# python3.13t -m ensurepip --upgrade |
| 22 | +# ``` |
| 23 | +# * Choose a release candidate to promote from |
| 24 | +# https://github.com/nod-ai/SHARK-Platform/releases/tag/dev-wheels |
| 25 | +# |
| 26 | +# Usage: |
| 27 | +# ./pypi_deploy.sh 2.9.0rc20241108 |
| 28 | + |
| 29 | +set -euo pipefail |
| 30 | + |
| 31 | +RELEASE="$1" |
| 32 | + |
| 33 | +SCRIPT_DIR="$(dirname -- "$( readlink -f -- "$0"; )")"; |
| 34 | +REPO_ROOT="$(cd "$SCRIPT_DIR"/../../ && pwd)" |
| 35 | +TMPDIR="$(mktemp --directory --tmpdir shark_platform_pypi_wheels.XXXXX)" |
| 36 | +ASSETS_PAGE="https://github.com/nod-ai/SHARK-Platform/releases/expanded_assets/dev-wheels" |
| 37 | + |
| 38 | +# TODO: rewrite in Python? |
| 39 | + |
| 40 | +function download_wheels() { |
| 41 | + echo "" |
| 42 | + echo "Downloading wheels for '${RELEASE}'..." |
| 43 | + |
| 44 | + # sharktank |
| 45 | + python -m pip download sharktank==${RELEASE} \ |
| 46 | + --no-deps --python-version 3.11 -f ${ASSETS_PAGE} |
| 47 | + |
| 48 | + # shortfin |
| 49 | + python -m pip download shortfin==${RELEASE} \ |
| 50 | + --no-deps --python-version 3.11 -f ${ASSETS_PAGE} |
| 51 | + python -m pip download shortfin==${RELEASE} \ |
| 52 | + --no-deps --python-version 3.12 -f ${ASSETS_PAGE} |
| 53 | + python -m pip download shortfin==${RELEASE} \ |
| 54 | + --no-deps --python-version 3.13 -f ${ASSETS_PAGE} |
| 55 | + python -m pip download shortfin==${RELEASE} \ |
| 56 | + --no-deps --python-version 3.13 -f ${ASSETS_PAGE} |
| 57 | + # TODO: fetch 3.13t using the same `python` somehow |
| 58 | + # * https://pip.pypa.io/en/stable/cli/pip_download/ |
| 59 | + # * https://py-free-threading.github.io/installing_cpython/ |
| 60 | + # * https://pip.pypa.io/en/stable/installation/ |
| 61 | + python3.13t -m pip download shortfin==${RELEASE} --no-deps -f ${ASSETS_PAGE} |
| 62 | + |
| 63 | + # TODO: shark-ai meta package when it is published to nightlies |
| 64 | + |
| 65 | + echo "" |
| 66 | + echo "Downloaded wheels:" |
| 67 | + ls |
| 68 | +} |
| 69 | + |
| 70 | +function edit_release_versions() { |
| 71 | + echo "" |
| 72 | + echo "Editing release versions..." |
| 73 | + for file in * |
| 74 | + do |
| 75 | + ${SCRIPT_DIR}/promote_whl_from_rc_to_final.py ${file} --delete-old-wheel |
| 76 | + done |
| 77 | + |
| 78 | + echo "Edited wheels:" |
| 79 | + ls |
| 80 | +} |
| 81 | + |
| 82 | +function upload_wheels() { |
| 83 | + # TODO: list packages that would be uploaded, pause, prompt to continue |
| 84 | + echo "" |
| 85 | + echo "Uploading wheels:" |
| 86 | + ls |
| 87 | + twine upload --verbose * |
| 88 | +} |
| 89 | + |
| 90 | +function build_shark_ai_meta_package() { |
| 91 | + # TODO: download meta package from nightly releases instead of this |
| 92 | + # Be aware that nightly releases pin other dependencies via the |
| 93 | + # generated `requirements.txt` compared to stable releases. |
| 94 | + echo "" |
| 95 | + |
| 96 | + # TODO: rework `write_requirements.py` to use the versions from the downloaded whls? |
| 97 | + echo "Computing local versions for sharktank and shortfin..." |
| 98 | + ${SCRIPT_DIR}/compute_local_version.py ${REPO_ROOT}/sharktank |
| 99 | + ${SCRIPT_DIR}/compute_local_version.py ${REPO_ROOT}/shortfin |
| 100 | + |
| 101 | + echo "Computing common version for shark-ai meta package..." |
| 102 | + ${SCRIPT_DIR}/compute_common_version.py --stable-release --write-json |
| 103 | + |
| 104 | + echo "Writing requirements for shark-ai meta package..." |
| 105 | + ${SCRIPT_DIR}/write_requirements.py |
| 106 | + |
| 107 | + echo "Building shark-ai meta package..." |
| 108 | + ${REPO_ROOT}/shark-ai/build_tools/build_linux_package.sh |
| 109 | + |
| 110 | + # TODO: This is error-prone. We only want to publish the whl for this release. |
| 111 | + # Copy instead? Specify exact file name? Clear directory before building? |
| 112 | + mv ${REPO_ROOT}/shark-ai/build_tools/wheelhouse/* . |
| 113 | +} |
| 114 | + |
| 115 | +function main() { |
| 116 | + echo "Changing into ${TMPDIR}" |
| 117 | + cd "${TMPDIR}" |
| 118 | + # TODO: check_requirements (using pip) |
| 119 | + |
| 120 | + download_wheels |
| 121 | + edit_release_versions |
| 122 | + build_shark_ai_meta_package |
| 123 | + upload_wheels |
| 124 | +} |
| 125 | + |
| 126 | +main |
0 commit comments