forked from tensorflow/gan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pypi_utils.sh
121 lines (97 loc) · 3.19 KB
/
pypi_utils.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
#
# Some utilities for constructing, testing, and releasing PyPi packages.
make_virtual_env() {
local py_version=$1
local venv_dir=$2
echo "make_virtual_env ${py_version} ${venv_dir}"
# TODO(joelshor): Check that virtualenv exists and, if not, install it.
# Probably check using something like `which virtualenv`, and install
# using something like `sudo apt-get install virtualenv`.
# Create and activate a virtualenv to specify python version and test in
# isolated environment. Note that we don't actually have to cd'ed into a
# virtualenv directory to use it; we just need to source bin/activate into the
# current shell.
VENV_PATH=${venv_dir}/virtualenv/${py_version}
virtualenv -p "${py_version}" "${VENV_PATH}"
source ${VENV_PATH}/bin/activate
}
install_tensorflow() {
local tf_version=$1
if [[ "$tf_version" == "TF1.x" ]]; then
pip install tensorflow==1.15
elif [[ "$tf_version" == "TF2.x" ]]; then
pip install tensorflow
else
echo "TensorFlow version not recognized: ${tf_version}"
exit -1
fi
}
install_tfp() {
local tf_version=$1
if [[ "$tf_version" == "TF1.x" ]]; then
pip install tensorflow-probability
elif [[ "$tf_version" == "TF2.x" ]]; then
pip install tfp-nightly
else
echo "TensorFlow version not recognized: ${tf_version}"
exit -1
fi
}
install_tfds() {
local tf_version=$1
if [[ "$tf_version" == "TF1.x" ]]; then
pip install tensorflow-datasets
elif [[ "$tf_version" == "TF2.x" ]]; then
pip install tfds-nightly
else
echo "TensorFlow version not recognized: ${tf_version}"
exit -1
fi
}
run_unittests_tests() {
local py_version=$1
local tf_version=$2
echo "run_tests ${py_version}" "${tf_version}"
venv_dir=$(mktemp -d)
make_virtual_env "${py_version}" "${venv_dir}"
# Install TensorFlow explicitly (see http://g/tf-oss/vpEioAGbZ4Q).
install_tensorflow "${tf_version}"
# TODO(joelshor): These should get installed in setup.py, but aren't for some
# reason.
pip install Pillow
pip install scipy
pip install matplotlib
pip install --upgrade google-api-python-client
pip install --upgrade oauth2client
install_tfp "${tf_version}"
install_tfds "${tf_version}"
pip install tensorflow-hub # Package is the same regardless of TF version.
# Run the tests.
python setup.py test
# Deactivate virtualenv.
deactivate
}
test_build_and_install_whl() {
local py_version=$1
local tf_version=$2
local venv_dir=$3
echo "run_tests ${py_version}" "${tf_version}" "${venv_dir}"
if [ "${venv_dir}" = "" ]; then
venv_dir=$(mktemp -d)
fi
make_virtual_env "${py_version}" "${venv_dir}"
# Install TensorFlow explicitly (see http://g/tf-oss/vpEioAGbZ4Q).
install_tensorflow "${tf_version}"
install_tfp "${tf_version}"
pip install tensorflow-hub # Package is the same regardless of TF version.
# Install tf_gan package.
WHEEL_PATH=${venv_dir}/wheel/${py_version}
./pip_pkg.sh ${WHEEL_PATH}/
pip install ${WHEEL_PATH}/tensorflow_gan-*.whl
# Move away from repo directory so "import tensorflow_gan" refers to the
# installed wheel and not to the local fs.
(cd $(mktemp -d) && python -c 'import tensorflow_gan')
# Deactivate virtualenv.
deactivate
}