#!/bin/sh # Copyright 2023 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. set -e OUT_DIR_DEFAULT=bazel-pypi-out USAGE="$(basename $0) [] Build a Python wheel for public release to PyPI using a special Docker build container. Uses bazel, but does not pollute the WORKSPACE's default cache. must be one of the supported interpreters: cp310 cp311 cp312 cp313 defaults to $OUT_DIR_DEFAULT. " case "$1" in cp310|cp311|cp312|cp313) PY_TAG=$1 OUTDIR=$(realpath ${2:-$OUT_DIR_DEFAULT}) mkdir -p $OUTDIR break ;; *) echo usage: "$USAGE" >&2 exit 1 esac SRCDIR=$(realpath .) if ! test -f $SRCDIR/WORKSPACE; then echo "error: must run from the top of the source tree" >&2 exit 1 fi # Remove Bazel's workspace symlinks so they'll be rewritten below, pointing into # OUTDIR. find . -maxdepth 1 -type l -name bazel-\* | xargs rm -f # Build the Docker image from its source file. Don't pollute the public list of # images by tagging; just use the image's ID. DOCKERFILE=python/tflite_micro/pypi_build.dockerfile IMAGE_ID_FILE=$OUTDIR/image-id docker build - --iidfile $IMAGE_ID_FILE <$DOCKERFILE IMAGE_ID=$(cat $IMAGE_ID_FILE) # Build the Python package within an ephemeral container. docker run \ --init \ --rm \ --interactive \ --mount type=bind,source=$SRCDIR,destination=$SRCDIR \ --mount type=bind,source=$OUTDIR,destination=$OUTDIR \ --workdir $SRCDIR \ --env USER=$(id -un) \ $IMAGE_ID \ /bin/bash -s -e -x -u \ <