diff --git a/.gitignore b/.gitignore index a1ee77226..1818f3234 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ object_database/web/content/dist # Emacs \#* \.#* +**/*~ # leading slash means only match at repo-root level /.python-version @@ -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 \ No newline at end of file diff --git a/build_scripts/README.md b/build_scripts/README.md new file mode 100644 index 000000000..10a668c68 --- /dev/null +++ b/build_scripts/README.md @@ -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 ` (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. \ No newline at end of file diff --git a/build_scripts/create_manylinux_wheel.sh b/build_scripts/create_manylinux_wheel.sh new file mode 100755 index 000000000..a75b778f8 --- /dev/null +++ b/build_scripts/create_manylinux_wheel.sh @@ -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 diff --git a/build_scripts/run_build.sh b/build_scripts/run_build.sh new file mode 100755 index 000000000..4216614e3 --- /dev/null +++ b/build_scripts/run_build.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -ex + +if [[ $# -eq 0 ]]; then + echo "Usage: ./run_build.sh " + echo "Valid '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