xref: /aosp_15_r20/external/pytorch/scripts/release/promote/wheel_to_pypi.sh (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1#!/usr/bin/env bash
2
3set -eou pipefail
4
5DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
6source "${DIR}/common_utils.sh"
7
8# Allow for users to pass PACKAGE_NAME
9# For use with other packages, i.e. torchvision, etc.
10PACKAGE_NAME=${PACKAGE_NAME:-torch}
11
12pytorch_version="$(get_pytorch_version)"
13# Refers to the specific package we'd like to promote
14# i.e. VERSION_SUFFIX='%2Bcu102'
15#      torch-1.8.0+cu102 -> torch-1.8.0
16VERSION_SUFFIX=${VERSION_SUFFIX:-}
17# Refers to the specific platofmr we'd like to promote
18# i.e. PLATFORM=linux_x86_64
19# For domains like torchaudio / torchtext this is to be left blank
20PLATFORM=${PLATFORM:-}
21
22pkgs_to_promote=$(\
23    curl -fsSL https://download.pytorch.org/whl/torch_stable.html \
24        | grep "${PACKAGE_NAME}-${pytorch_version}${VERSION_SUFFIX}-" \
25        | grep "${PLATFORM}" \
26        | cut -d '"' -f2
27)
28
29tmp_dir="$(mktemp -d)"
30output_tmp_dir="$(mktemp -d)"
31trap 'rm -rf ${tmp_dir} ${output_tmp_dir}' EXIT
32pushd "${output_tmp_dir}"
33
34# Dry run by default
35DRY_RUN=${DRY_RUN:-enabled}
36# On dry run just echo the commands that are meant to be run
37TWINE_UPLOAD="echo twine upload"
38if [[ $DRY_RUN = "disabled" ]]; then
39    TWINE_UPLOAD="twine upload"
40fi
41
42for pkg in ${pkgs_to_promote}; do
43    pkg_basename="$(basename "${pkg}")"
44    # Don't attempt to change if manylinux2014
45    if [[ "${pkg}" != *manylinux2014* ]]; then
46        pkg_basename="$(basename "${pkg//linux/manylinux1}")"
47    fi
48    orig_pkg="${tmp_dir}/${pkg_basename}"
49    (
50        set -x
51        # Download package, sub out linux for manylinux1
52        curl -fsSL -o "${orig_pkg}" "https://download.pytorch.org/whl/${pkg}"
53    )
54
55    if [[ -n "${VERSION_SUFFIX}" ]]; then
56        OUTPUT_DIR="${output_tmp_dir}" ${DIR}/prep_binary_for_pypi.sh "${orig_pkg}"
57    else
58        mv "${orig_pkg}" "${output_tmp_dir}/"
59    fi
60
61    (
62        set -x
63        ${TWINE_UPLOAD} \
64            --disable-progress-bar \
65            --non-interactive \
66            ./*.whl
67        rm -rf ./*.whl
68    )
69done
70