aboutsummaryrefslogtreecommitdiff
path: root/python/tools
diff options
context:
space:
mode:
authorambrosin <ambrosin@google.com>2022-07-05 04:09:26 -0700
committerCopybara-Service <copybara-worker@google.com>2022-07-05 04:10:28 -0700
commit22338673807c283bd4c168867b89667da40c236c (patch)
treea78334a121faae34ac7ab06a1a08ad557d739a6b /python/tools
parent7a4fa64c6bbfd8bf105731e019a312a6930d7e28 (diff)
downloadtink-22338673807c283bd4c168867b89667da40c236c.tar.gz
Some refactoring of Tink Python create_release.sh script:
- Rename `build_linux` as `create_distribution_for_linux` and split it into two functions, one for wheels build and one for source distribution build - Rename `build_macos` as `create_distribution_for_macos`. - Add comments to functions - Remove `set_owner_within_tar` as this is no longer needed: since https://github.com/pypa/setuptools/pull/2800 the parameters `--owner` and `--group` are propagated to setuptools. PiperOrigin-RevId: 459048112
Diffstat (limited to 'python/tools')
-rwxr-xr-xpython/tools/distribution/create_release.sh86
1 files changed, 58 insertions, 28 deletions
diff --git a/python/tools/distribution/create_release.sh b/python/tools/distribution/create_release.sh
index 3de7a12f7..90700f653 100755
--- a/python/tools/distribution/create_release.sh
+++ b/python/tools/distribution/create_release.sh
@@ -37,11 +37,21 @@ readonly IMAGE_NAME="quay.io/pypa/manylinux2014_x86_64"
readonly IMAGE_DIGEST="sha256:31d7d1cbbb8ea93ac64c3113bceaa0e9e13d65198229a25eee16dc70e8bf9cf7"
readonly IMAGE="${IMAGE_NAME}@${IMAGE_DIGEST}"
-build_linux() {
- echo "### Building Linux binary wheels ###"
+#######################################
+# Builds Tink Python built distribution (Wheel) [1].
+#
+# This function must be called from within the Tink Python's root folder.
+#
+# [1] https://packaging.python.org/en/latest/glossary/#term-Built-Distribution
+# Globals:
+# None
+# Arguments:
+# None
+#######################################
+__create_and_test_wheels_for_linux() {
+ echo "### Building and testing Linux binary wheels ###"
local -r tink_py_relative_path="${PWD##*/}"
local -r workdir="/tmp/tink/${tink_py_relative_path}"
-
# Use signatures for getting images from registry (see
# https://docs.docker.com/engine/security/trust/content_trust/).
export DOCKER_CONTENT_TRUST=1
@@ -64,13 +74,25 @@ build_linux() {
"${IMAGE}" \
"${workdir}/tools/distribution/test_linux_binary_wheels.sh"
- # Restore the original WORKSPACE.
- mv WORKSPACE.bak WORKSPACE
-
# Docker runs as root so we transfer ownership to the non-root user.
sudo chown -R "$(id -un):$(id -gn)" "${TINK_PYTHON_ROOT_PATH}"
+ # Restore the original WORKSPACE.
+ mv WORKSPACE.bak WORKSPACE
+}
- echo "### Building Linux source distribution ###"
+#######################################
+# Builds Tink Python source distribution [1].
+#
+# This function must be called from within the Tink Python's root folder.
+#
+# [1] https://packaging.python.org/en/latest/glossary/#term-Source-Distribution-or-sdist
+# Globals:
+# PYTHON_VERSIONS
+# Arguments:
+# None
+#######################################
+__create_and_test_sdist_for_linux() {
+ echo "### Building and testing Linux source distribution ###"
local sorted=( $( echo "${PYTHON_VERSIONS[@]}" \
| xargs -n1 | sort -V | xargs ) )
local latest="${sorted[${#sorted[@]}-1]}"
@@ -78,9 +100,8 @@ build_linux() {
# Build source distribution.
export TINK_PYTHON_SETUPTOOLS_OVERRIDE_BASE_PATH="${TINK_PYTHON_ROOT_PATH}/.."
- python3 setup.py sdist
+ python3 setup.py sdist --owner=root --group=root
local sdist_filename="tink-${TINK_VERSION}.tar.gz"
- set_owner_within_tar "dist/${sdist_filename}"
cp "dist/${sdist_filename}" release/
# Test install from source distribution.
@@ -92,7 +113,32 @@ build_linux() {
| xargs -0 -n1 python3
}
-build_macos() {
+#######################################
+# Creates a Tink Python distribution for Linux.
+#
+# This function must be called from within the Tink Python's root folder.
+#
+# Globals:
+# None
+# Arguments:
+# None
+#######################################
+create_distribution_for_linux() {
+ __create_and_test_wheels_for_linux
+ __create_and_test_sdist_for_linux
+}
+
+#######################################
+# Creates a Tink Python distribution for MacOS.
+#
+# This function must be called from within the Tink Python's root folder.
+#
+# Globals:
+# PYTHON_VERSIONS
+# Arguments:
+# None
+#######################################
+create_distribution_for_macos() {
echo "### Building macOS binary wheels ###"
for v in "${PYTHON_VERSIONS[@]}"; do
@@ -123,30 +169,14 @@ enable_py_version() {
python3 -m pip install --upgrade wheel
}
-# setuptools does not replicate the distutils feature of explicitly setting
-# user/group ownership on the files within the source distribution archive.
-#
-# This function is an easy workaround that doesn't require monkey-patching
-# setuptools. This behavior is desired to produce deterministic release
-# artifacts.
-set_owner_within_tar() {
- local tar_file="$1"
- local tmp_dir="$(mktemp -d tink-py-tar-XXXXXX)"
- tar -C "${tmp_dir}" -xzf "${tar_file}"
- local tink_dir="$(basename $(ls -d ${tmp_dir}/tink*))"
- tar -C "${tmp_dir}" -czf "${tar_file}" \
- --owner=root --group=root "${tink_dir}"
- rm -r "${tmp_dir}"
-}
-
main() {
eval "$(pyenv init -)"
mkdir -p release
if [[ "${PLATFORM}" == 'linux' ]]; then
- build_linux
+ create_distribution_for_linux
elif [[ "${PLATFORM}" == 'darwin' ]]; then
- build_macos
+ create_distribution_for_macos
else
echo "${PLATFORM} is not a supported platform."
exit 1