Skip to content

Commit 3a43109

Browse files
ssjhvcopybara-github
authored andcommitted
Added package test script.
PiperOrigin-RevId: 592057630 Change-Id: I9e47f76baabc5d3ab9cc1060c7da4945b214b72b
1 parent 4aa9583 commit 3a43109

File tree

5 files changed

+66
-19
lines changed

5 files changed

+66
-19
lines changed

.bazelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
# This flag is required for CUDA repo that @org_tensorflow depends on.
22
common --experimental_repo_remote_exec
3+
4+
build:manylinux_2_17_x86_64 --host_crosstool_top="@ubuntu20.04-gcc9_manylinux2014-cuda11.2-cudnn8.1-tensorrt7.2_config_cuda//crosstool:toolchain"
5+
build:manylinux_2_17_x86_64 --crosstool_top="@ubuntu20.04-gcc9_manylinux2014-cuda11.2-cudnn8.1-tensorrt7.2_config_cuda//crosstool:toolchain"
6+
build:manylinux_2_17_x86_64 --extra_toolchains="@ubuntu20.04-gcc9_manylinux2014-cuda11.2-cudnn8.1-tensorrt7.2_config_cuda//crosstool:toolchain-linux-x86_64"
7+
build:manylinux_2_17_x86_64 --extra_execution_platforms="@ubuntu20.04-gcc9_manylinux2014-cuda11.2-cudnn8.1-tensorrt7.2_config_platform//:platform"
8+
build:manylinux_2_17_x86_64 --host_platform="@ubuntu20.04-gcc9_manylinux2014-cuda11.2-cudnn8.1-tensorrt7.2_config_platform//:platform"
9+
build:manylinux_2_17_x86_64 --platforms="@ubuntu20.04-gcc9_manylinux2014-cuda11.2-cudnn8.1-tensorrt7.2_config_platform//:platform"

BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ py_binary(
4545

4646
py_binary(
4747
name = "build_pip_pkg",
48-
srcs = ["build_pip_pkg.py"],
48+
srcs = ["tools/build_pip_pkg.py"],
4949
data = [
5050
"LICENSE",
5151
"README.md",
File renamed without changes.

build_pip_pkg.sh renamed to tools/build_pip_pkg.sh

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,36 @@
1515
# ==============================================================================
1616

1717
# This script must run at the workspace root directory.
18-
# In addition, `tensorflow_compression/cc:libtensorflow_compression.so` should
19-
# have been built using bazel.
2018

2119
set -ex # Fail if any command fails, echo commands.
2220

23-
OUTPUT_DIR="${1-/tmp}"
24-
WHEEL_VERSION="${2-0.dev0}"
21+
# Script configuration --------------------------------------------------------
22+
OUTPUT_DIR="${1-/tmp/tensorflow_compression}"
23+
WHEEL_VERSION=${2-0.dev0}
2524

26-
PKGDIR="$(mktemp -d)"
27-
trap 'rm -r -- "${PKGDIR}"' EXIT
25+
# Optionally exported environment variables.
26+
: ${BAZEL_OPT:=}
27+
# -----------------------------------------------------------------------------
2828

29-
cp LICENSE README.md MANIFEST.in requirements.txt build_pip_pkg.py "${PKGDIR}"
29+
python -m pip install -U pip setuptools wheel
30+
python -m pip install -r requirements.txt
31+
bazel build ${BAZEL_OPT} -c opt --copt=-mavx tensorflow_compression/cc:libtensorflow_compression.so
3032

31-
mkdir -p "${PKGDIR}/tensorflow_compression/cc"
33+
SRCDIR="$(mktemp -d)"
34+
trap 'rm -r -- "${SRCDIR}"' EXIT
35+
36+
cp LICENSE README.md MANIFEST.in requirements.txt "${SRCDIR}"
37+
38+
mkdir -p "${SRCDIR}/tensorflow_compression/cc"
3239
cp "$(bazel info -c opt bazel-genfiles)/tensorflow_compression/cc/libtensorflow_compression.so" \
33-
"${PKGDIR}/tensorflow_compression/cc"
40+
"${SRCDIR}/tensorflow_compression/cc"
3441

3542

36-
copy_file()
37-
{
38-
FILENAME="${1#./}"
39-
DEST="${PKGDIR%/}/$(dirname "${FILENAME}")"
40-
mkdir -p "${DEST}"
41-
cp "${FILENAME}" "${DEST}"
43+
copy_file() {
44+
local FILENAME="${1#./}"
45+
local DST="${SRCDIR%/}/$(dirname "${FILENAME}")"
46+
mkdir -p "${DST}"
47+
cp "${FILENAME}" "${DST}"
4248
}
4349

4450
copy_file "tensorflow_compression/__init__.py"
@@ -48,6 +54,4 @@ copy_file "tensorflow_compression/all_tests.py"
4854
find tensorflow_compression/python -name "*.py" \
4955
| while read filename; do copy_file "${filename}"; done
5056

51-
pushd "${PKGDIR}"
52-
python build_pip_pkg.py . "${OUTPUT_DIR}" "${WHEEL_VERSION}"
53-
popd
57+
python tools/build_pip_pkg.py "${SRCDIR}" "${OUTPUT_DIR}" "${WHEEL_VERSION}"

tools/test_pip_pkg.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2023 Google LLC. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ==============================================================================
16+
17+
set -ex # Fail if any command fails, echo commands.
18+
19+
WHEEL="${1}"
20+
21+
# `import tensorflow_compression` in the bazel root directory produces cryptic
22+
# error messages, because Python ends up looking for .so files under the
23+
# subdirectories in the src repo instead of Python module libraries. Changing
24+
# the current directory helps avoid running tests inside the bazel root
25+
# direcotory by accident.
26+
pushd /tmp
27+
28+
python -m pip install -U pip setuptools wheel
29+
python -m pip install "${WHEEL}"
30+
python -m pip list -v
31+
32+
# Logs elements of tfc namespace and runs unit tests.
33+
python -c "import tensorflow_compression as tfc; print('\n'.join(sorted(dir(tfc))))"
34+
python -m tensorflow_compression.all_tests
35+
36+
popd # /tmp

0 commit comments

Comments
 (0)