Skip to content

Build linux wheels for typed_python #393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ object_database/web/content/dist
# Emacs
\#*
\.#*
**/*~

# leading slash means only match at repo-root level
/.python-version
Expand All @@ -25,6 +26,13 @@ object_database/web/content/dist
/.env*
/.test_venv
/dist/
/wheels/
/pip-wheel-metadata/
/testcert.cert
/testcert.key

.idea/

# build_scripts sets up temporary symlinks so don't accidentally check them in
Pipfile
Pipfile.lock
26 changes: 26 additions & 0 deletions build_scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Wheel builds for typed_python

Using [Manylinux](https://github.com/pypa/manylinux) we can make typed_python
more portable.

## Building wheels

1. Prerequisites: docker
2. Run `run_build.sh <python_version>` (37 38 39 310 are supported)

This process should create a `./wheels` directory under the typed_python repo
root with wheels for python 3.7-3.10 built for linux x86_64 that are uploadable
to pypi

## Release to pypi

1. pip install twine
2. twine upload wheels/*.whl

## Notes

Here we're using the CentOS 7 based manylinux2014 image.
We cannot move to the newer `manylinux_x_y` image ([PEP 600](https://peps.python.org/pep-0600/))
until type_python drops support for python 3.7

`typed_python` code does not build on arm64 though manylinux does support it.
34 changes: 34 additions & 0 deletions build_scripts/create_manylinux_wheel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Run this inside a manylinux docker container

# code dir
pushd ${TYPED_PYTHON_DIR:-/opt/apriori/typed_python}

FLAVOR="cp" # cpython not pypy
ORIG_PATH=$PATH
VERSION=$1

VALID_VERSIONS=("37 38 39 310")
if [[ ! "${VALID_VERSIONS[*]}" =~ "$VERSION" ]]; then
echo "Valid versions are 37, 38, 39, 310"
exit 1
fi

# Manylinux image has supported python installed like /opt/python/cp38-cp38
PYNAME="${FLAVOR}${VERSION}"

# 37 in maintenance so has special suffix
if [[ ${VERSION} == 37 ]]; then SUFFIX="m"; else SUFFIX=""; fi

# select the right python
PYTHON=/opt/python/${PYNAME}-${PYNAME}${SUFFIX}/bin/python

# `python -m build` respects build deps in pyproject.toml
# `-w` option builds the wheel
${PYTHON} -m build -w

# make wheels that pypi recognizes
for whl in dist/*${PYNAME}*.whl; do
auditwheel repair "$whl" -w wheels
done
27 changes: 27 additions & 0 deletions build_scripts/run_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -ex

if [[ $# -eq 0 ]]; then
echo "Usage: ./run_build.sh <python_version>"
echo "Valid <python_verson>'s are 37 38 39 310"
exit 1
fi

VERSION=$1

REPO_ROOT=$(realpath $(dirname $(realpath $0))/..)
ARCH=${2:-"x86_64"}
MANYLINUX=${3:-"manylinux2014"} # PEP 599
BASE_IMAGE="quay.io/pypa/${MANYLINUX}_${ARCH}"

# Unfortunately the code is specific to x86_64 arch
#if [[ $ARCH = "aarch64" ]]; then
#
# DOCKER_PLATFORM="--platform linux/arm64"
#fi

docker run --rm ${DOCKER_PLATFORM} \
--volume ${REPO_ROOT}:/opt/apriori/typed_python \
${BASE_IMAGE} \
/opt/apriori/typed_python/build_scripts/create_manylinux_wheel.sh $VERSION