Skip to content

Commit 1c43bcd

Browse files
authored
Fix requirements checking in pypi_deploy.sh and document scripts. (iree-org#19137)
* `set -e` was exiting before we could log helpful messages * `check_exists` was assuming a command would exist in `PATH`, but some of the requirements are python packages without scripts sharing their name
1 parent 2311e04 commit 1c43bcd

File tree

2 files changed

+73
-7
lines changed

2 files changed

+73
-7
lines changed

build_tools/python_deploy/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,61 @@
11
# Python Deployment
22

3+
These scripts assist with building Python packages and pushing them to
4+
[PyPI (the Python Package Index)](https://pypi.org/). See also
5+
6+
* The Python Packaging User Guide: <https://packaging.python.org/en/latest/>
7+
* Our release management documentation:
8+
https://iree.dev/developers/general/release-management/
9+
10+
## Overview
11+
312
See comments in scripts for canonical usage. This page includes additional
413
notes.
514

15+
### Package building
16+
17+
These scripts build all packages we maintain, for all Python versions and
18+
platforms that we support:
19+
20+
* [`build_linux_packages.sh`](./build_linux_packages.sh)
21+
* [`build_macos_packages.sh`](./build_macos_packages.sh)
22+
* [`build_windows_packages.ps1`](./build_windows_packages.ps1)
23+
24+
To assist with environment setup, we use a
25+
[manylinux Docker image](https://github.com/iree-org/base-docker-images/blob/main/dockerfiles/manylinux_x86_64.Dockerfile)
26+
for Linux builds and these scripts on other platforms:
27+
28+
* [`install_macos_deps.sh`](./install_macos_deps.sh)
29+
* [`install_windows_deps.ps1`](./install_windows_deps.ps1)
30+
31+
### Version management
32+
33+
These scripts handle versioning across packages, including considerations like
34+
major, minor, and patch levels (`X.Y.Z`), as well as suffixes like
35+
`rc20241107` or `dev+{git hash}`:
36+
37+
* [`compute_common_version.py`](./compute_common_version.py)
38+
* [`compute_local_version.py`](./compute_local_version.py)
39+
* [`promote_whl_from_rc_to_final.py`](./promote_whl_from_rc_to_final.py)
40+
41+
### PyPI deployment
42+
43+
These scripts handle promoting nightly releases packages to stable and pushing
44+
to PyPI:
45+
46+
* [`promote_whl_from_rc_to_final.py`](./promote_whl_from_rc_to_final.py)
47+
* [`pypi_deploy.sh`](./pypi_deploy.sh)
48+
49+
Both of these scripts expect to have the dependencies from
50+
[`pypi_deploy_requirements.txt`](./pypi_deploy_requirements.txt) installed.
51+
This can be easily managed by using a Python virtual environment:
52+
53+
```bash
54+
python -m venv .venv
55+
source .venv/bin/activate
56+
python -m pip install -r ./pypi_deploy_requirements.txt
57+
```
58+
659
## Debugging manylinux builds
760

861
We build releases under a manylinux derived docker image. When all goes well,

build_tools/python_deploy/pypi_deploy.sh

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
# You must have `gh` installed and authenticated (run `gh auth`).
2020
#
2121
# Usage:
22-
# ./pypi_deploy.sh candidate-20220930.282
22+
# python -m venv .venv
23+
# source .venv/bin/activate
24+
# python -m pip install -r ./pypi_deploy_requirements.txt
25+
# ./pypi_deploy.sh candidate-20220930.282
2326

2427
set -euo pipefail
2528

@@ -29,15 +32,22 @@ SCRIPT_DIR="$(dirname -- "$( readlink -f -- "$0"; )")";
2932
REQUIREMENTS_FILE="${SCRIPT_DIR}/pypi_deploy_requirements.txt"
3033
TMPDIR="$(mktemp --directory --tmpdir iree_pypi_wheels.XXXXX)"
3134

32-
function check_exists() {
35+
function check_command_exists() {
3336
if ! command -v "$1" > /dev/null; then
3437
echo "$1 not found."
35-
exit 1
38+
return 1
3639
fi
40+
return 0
41+
}
42+
43+
function check_python_package_installed() {
44+
if ! pip show "$1" > /dev/null; then
45+
echo "$1 not installed."
46+
return 1
47+
fi
48+
return 0
3749
}
3850

39-
# It really *seems* like there should be a pip command to do this, but there's
40-
# not, apparently.
4151
function check_requirements() {
4252
while read line; do
4353
# Read in the package, ignoring everything after the first '='
@@ -48,7 +58,7 @@ function check_requirements() {
4858
echo "Reading requirements file '${REQUIREMENTS_FILE}' failed."
4959
exit "${ret}"
5060
fi
51-
if ! check_exists "${package}"; then
61+
if ! check_python_package_installed "${package}"; then
5262
echo "Recommend installing python dependencies in a venv using pypi_deploy_requirements.txt"
5363
exit 1
5464
fi
@@ -88,13 +98,16 @@ function upload_wheels() {
8898
function main() {
8999
echo "Changing into ${TMPDIR}"
90100
cd "${TMPDIR}"
101+
102+
set +e
91103
check_requirements
92104

93-
if ! check_exists gh; then
105+
if ! check_command_exists gh; then
94106
echo "The GitHub CLI 'gh' is required. See https://github.com/cli/cli#installation."
95107
echo " Googlers, the PPA should already be on your linux machine."
96108
exit 1
97109
fi
110+
set -e
98111

99112
download_wheels
100113
edit_release_versions

0 commit comments

Comments
 (0)