Skip to content

Commit 6bf5654

Browse files
committed
chore: fix kokoro and mypy presubmits (#305)
This PR fixes the failing presubmits to build this package in different environments. Note that the presubmits have been failing for a while. A better long term solution is to switch the approach by building and testing against the supported Python versions within a nox session.
1 parent 7995389 commit 6bf5654

11 files changed

Lines changed: 58 additions & 204 deletions

File tree

packages/google-crc32c/.kokoro/build-manylinux.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ cd github/python-crc32c
2727

2828
# Before running nox and such, build the extension.
2929
./scripts/manylinux/build.sh
30-
./scripts/manylinux/check.sh

packages/google-crc32c/.kokoro/build-osx.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,3 @@ cd github/python-crc32c
2626

2727
# Before running nox and such, build the extension.
2828
./scripts/osx/build.sh
29-
./scripts/osx/check.sh

packages/google-crc32c/noxfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ def check(session):
5252
@nox.session(python="3.13")
5353
def mypy(session):
5454
"""Verify type hints are mypy compatible."""
55-
session.install("-e", ".")
5655
session.install(
5756
"mypy",
5857
"types-mock",
5958
"types-setuptools",
6059
)
61-
session.run("mypy", "src/google_crc32c/", "tests/")
60+
session.env["MYPYPATH"] = "src"
61+
session.run("mypy", "src/google_crc32c/", "tests/")

packages/google-crc32c/scripts/manylinux/build.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,18 @@ MANYLINUX_DIR=$(echo $(cd $(dirname ${0}); pwd))
2121
SCRIPTS_DIR=$(dirname ${MANYLINUX_DIR})
2222
REPO_ROOT=$(dirname ${SCRIPTS_DIR})
2323

24+
sudo apt-get install -y software-properties-common
25+
sudo add-apt-repository -y ppa:deadsnakes/ppa
2426
sudo apt-get update
25-
sudo apt-get install -y python3.9
27+
sudo apt-get install -y python3.12
2628

2729
cd $REPO_ROOT
2830
# Add directory as safe to avoid "detected dubious ownership" fatal issue1
2931
git config --global --add safe.directory $REPO_ROOT
3032
git config --global --add safe.directory $REPO_ROOT/google_crc32c
3133
git submodule update --init --recursive
3234

33-
docker pull quay.io/pypa/manylinux2010_x86_64
34-
docker run \
35-
--rm \
36-
--interactive \
37-
--volume ${REPO_ROOT}:/var/code/python-crc32c/ \
38-
--env BUILD_PYTHON=${BUILD_PYTHON} \
39-
quay.io/pypa/manylinux2010_x86_64 \
40-
/var/code/python-crc32c/scripts/manylinux/build_on_centos.sh
35+
4136

4237
docker pull quay.io/pypa/manylinux2014_x86_64
4338
docker run \

packages/google-crc32c/scripts/manylinux/build_on_centos.sh

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ MAIN_PYTHON_BIN="/opt/python/cp39-cp39/bin/"
1818
echo "BUILD_PYTHON: ${BUILD_PYTHON}"
1919
REPO_ROOT=/var/code/python-crc32c/
2020

21+
# Install `openssl-devel` so that `cmake` can be built.
22+
yum install -y openssl-devel
23+
2124
# Upgrade `pip` before using it.
2225
${MAIN_PYTHON_BIN}/python -m pip install --upgrade pip
2326
# Install `cmake` (i.e. non-Python build dependency).
@@ -31,11 +34,12 @@ cd ${REPO_ROOT}/google_crc32c/
3134
rm -rf build
3235
mkdir build
3336
cd build/
34-
${MAIN_PYTHON_BIN}/cmake \
37+
cmake \
3538
-DCMAKE_BUILD_TYPE=Release \
3639
-DCRC32C_BUILD_TESTS=no \
3740
-DCRC32C_BUILD_BENCHMARKS=no \
3841
-DBUILD_SHARED_LIBS=yes \
42+
-DCMAKE_POLICY_VERSION_MINIMUM=3.12 \
3943
..
4044
make all install
4145

@@ -56,7 +60,7 @@ if [[ -z ${BUILD_PYTHON} ]]; then
5660
elif [[ "${PYTHON_BIN}" == *"312"* ]]; then
5761
PYTHON_VERSIONS="${PYTHON_VERSIONS} ${PYTHON_BIN}"
5862
continue
59-
elif [[ "${PYTHON_BIN}" == *"313"* ]]; then
63+
elif [[ "${PYTHON_BIN}" == *"313"* && "${PYTHON_BIN}" != *"313t"* ]]; then
6064
PYTHON_VERSIONS="${PYTHON_VERSIONS} ${PYTHON_BIN}"
6165
continue
6266
else
@@ -84,7 +88,27 @@ done
8488

8589
# Bundle external shared libraries into the wheels
8690
for whl in dist_wheels/google_crc32c*.whl; do
87-
${MAIN_PYTHON_BIN}/auditwheel repair "${whl}" --wheel-dir wheels/
91+
"${MAIN_PYTHON_BIN}/auditwheel" repair "${whl}" --wheel-dir wheels/
92+
done
93+
94+
# Install and test wheels
95+
for PYTHON_BIN in ${PYTHON_VERSIONS}; do
96+
# Identify the short python version e.g. "39", "310"
97+
# Get the ABI tag from the Python binary's path, e.g., "cp310-cp310"
98+
ABI_TAG=$(basename $(dirname ${PYTHON_BIN}))
99+
ARCH=$(uname -m)
100+
# Create a virtual environment to install and test the wheel
101+
${PYTHON_BIN}/python -m venv /tmp/venv
102+
103+
# Find the correct wheel file using the precise ABI tag and architecture.
104+
WHEEL_FILE=$(ls ${REPO_ROOT}/wheels/google_crc32c-*-${ABI_TAG}-*manylinux*${ARCH}*.whl) # Install the wheel
105+
/tmp/venv/bin/pip install "${WHEEL_FILE}"
106+
107+
# Verify that the module is installed and peek at contents.
108+
/tmp/venv/bin/python ${REPO_ROOT}/scripts/check_crc32c_extension.py
109+
110+
# Clean up the virtual environment
111+
rm -rf /tmp/venv
88112
done
89113

90114
# Clean up.

packages/google-crc32c/scripts/manylinux/check.sh

Lines changed: 0 additions & 60 deletions
This file was deleted.

packages/google-crc32c/scripts/osx/build.sh

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,13 @@ export MACOSX_DEPLOYMENT_TARGET=12
2121

2222
# ``readlink -f`` is not our friend on OS X. This relies on **some**
2323
# ``python`` being installed.
24-
SCRIPT_FI=$(python -c "import os; print(os.path.realpath('${0}'))")
24+
SCRIPT_FI=$(python3 -c "import os; print(os.path.realpath('${0}'))")
2525
OSX_DIR=$(dirname ${SCRIPT_FI})
2626
SCRIPTS_DIR=$(dirname ${OSX_DIR})
2727
export REPO_ROOT=$(dirname ${SCRIPTS_DIR})
2828

29-
# install required packages for pyenv
30-
# https://github.com/pyenv/pyenv/wiki#suggested-build-environment
31-
brew install openssl readline sqlite3 xz zlib tcl-tk
32-
33-
# Replace the old version of pyenv with the latest version.
34-
rm -rf /Users/kbuilder/.pyenv
35-
git clone https://github.com/pyenv/pyenv.git /Users/kbuilder/.pyenv
36-
3729
# Build and install `libcrc32c`
38-
export PY_BIN="${PY_BIN:-python3}"
30+
export PY_BIN="python3"
3931
export CRC32C_INSTALL_PREFIX="${REPO_ROOT}/usr"
4032

4133
cd ${REPO_ROOT}
@@ -46,14 +38,17 @@ git submodule update --init --recursive
4638

4739
${OSX_DIR}/build_c_lib.sh
4840

49-
SUPPORTED_PYTHON_VERSIONS=("3.9" "3.10" "3.11" "3.12" "3.13")
50-
51-
for PYTHON_VERSION in ${SUPPORTED_PYTHON_VERSIONS[@]}; do
52-
echo "Build wheel for Python ${PYTHON_VERSION}"
53-
export PY_BIN=$PYTHON_VERSION
54-
export PY_TAG="cp${PYTHON_VERSION//.}-cp${PYTHON_VERSION//.}"
55-
. /${OSX_DIR}/build_python_wheel.sh
56-
done
41+
# Build the wheel for the system Python.
42+
. /${OSX_DIR}/build_python_wheel.sh
43+
44+
# Install the wheel in a virtualenv and test it.
45+
VENV=${REPO_ROOT}/venv
46+
"python3" -m venv ${VENV}
47+
${VENV}/bin/pip install --no-index --find-links=${REPO_ROOT}/wheels google-crc32c --force-reinstall
48+
${VENV}/bin/pip install pytest
49+
${VENV}/bin/py.test ${REPO_ROOT}/tests
50+
${VENV}/bin/python ${REPO_ROOT}/scripts/check_crc32c_extension.py
51+
rm -fr ${VENV}
5752

5853
# Clean up.
5954
rm -fr ${CRC32C_INSTALL_PREFIX}

packages/google-crc32c/scripts/osx/build_c_lib.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ ${VENV}/bin/cmake \
6565
-DBUILD_SHARED_LIBS=yes \
6666
-DCMAKE_INSTALL_PREFIX:PATH=${CRC32C_INSTALL_PREFIX} \
6767
-DCMAKE_INSTALL_NAME_DIR:PATH=${CRC32C_INSTALL_PREFIX}/lib \
68+
-DCMAKE_POLICY_VERSION_MINIMUM=3.12 \
6869
..
6970

7071
# Install `libcrc32c` into CRC32C_INSTALL_PREFIX.

packages/google-crc32c/scripts/osx/build_python_wheel.sh

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,16 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
# Build a **single** Python wheel for a specified version. The version and
17-
# associated paths should be set as environment variables; the expected
18-
# environment variables will be verified below.
19-
20-
set -e -x
21-
22-
# Check that the REPO_ROOT, PY_BIN and PY_TAG environment variables are set.
23-
if [[ -z "${REPO_ROOT}" ]]; then
24-
echo "REPO_ROOT environment variable should be set by the caller."
25-
exit 1
26-
fi
27-
if [[ -z "${PY_BIN}" ]]; then
28-
echo "PY_BIN environment variable should be set by the caller."
29-
exit 1
30-
fi
31-
if [[ -z "${PY_TAG}" ]]; then
32-
echo "PY_TAG environment variable should be set by the caller."
33-
exit 1
34-
fi
35-
36-
# set up pyenv & shell environment for switching across python versions
37-
eval "$(pyenv init -)"
38-
eval "$(pyenv init --path)"
39-
40-
install_python_pyenv() {
41-
version=$1
42-
43-
if [ -z "$(pyenv versions --bare | grep $version)" ]; then
44-
echo "Python $version is not installed. Installing..."
45-
pyenv install $version
46-
echo "Python $version installed."
47-
else
48-
echo "Python $version is already installed."
49-
fi
50-
pyenv shell $version
51-
}
52-
install_python_pyenv ${PY_BIN}
16+
# ``readlink -f`` is not our friend on OS X. This relies on **some**
17+
# ``python`` being installed.
18+
SCRIPT_FI=$(python3 -c "import os; print(os.path.realpath('${0}'))")
19+
OSX_DIR=$(dirname ${SCRIPT_FI})
20+
SCRIPTS_DIR=$(dirname ${OSX_DIR})
21+
export REPO_ROOT=$(dirname ${SCRIPTS_DIR})
5322

5423
# Create a virtualenv where we can install Python build dependencies.
55-
VENV=${REPO_ROOT}/venv${PY_BIN}
56-
"python${PY_BIN}" -m venv ${VENV}
24+
VENV=${REPO_ROOT}/venv_build
25+
"python3" -m venv ${VENV}
5726

5827
curl https://bootstrap.pypa.io/get-pip.py | ${VENV}/bin/python
5928
${VENV}/bin/python -m pip install \
@@ -76,11 +45,7 @@ ${VENV}/bin/delocate-wheel \
7645
--wheel-dir ${FIXED_WHEELS} \
7746
--verbose \
7847
--check-archs \
79-
${DIST_WHEELS}/google_crc32c*${PY_TAG}*.whl
80-
81-
if [[ "${PUBLISH_WHEELS}" == "true" ]]; then
82-
. /${OSX_DIR}/publish_python_wheel.sh
83-
fi
48+
${DIST_WHEELS}/google_crc32c*.whl
8449

8550
# Clean up.
8651
rm -fr ${DIST_WHEELS}

packages/google-crc32c/scripts/osx/check.sh

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)