Skip to content

Commit 84bb63f

Browse files
seanpmorganWindQAQ
authored andcommitted
ENH: Automate build (#271)
* Add automated build process * Update README * Update gitignore * Add build scripts * Update travis doc * Nit: remove extra line
1 parent 64803a0 commit 84bb63f

File tree

9 files changed

+238
-50
lines changed

9 files changed

+238
-50
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,4 @@ wheels/
3838
/artifacts
3939

4040
# Addons
41-
.*
4241
/docs/

.travis.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
dist: xenial
2+
language: minimal
3+
4+
git:
5+
quiet: true
6+
7+
services:
8+
- docker
9+
10+
install:
11+
- curl https://bootstrap.pypa.io/get-pip.py | sudo -H python
12+
- sudo -H python -m pip install -q -U twine --ignore-installed six
13+
- twine --version
14+
15+
stages:
16+
- test
17+
- build
18+
19+
jobs:
20+
include:
21+
# Linux Tests
22+
- stage: test
23+
name: "Test on Ubuntu 14.04"
24+
script:
25+
- docker run --rm -v ${PWD}:/addons -w /addons tensorflow/tensorflow:nightly-custom-op make unit-test
26+
27+
# Linux Builds
28+
- stage: build
29+
name: "Build on Ubuntu 14.04 for Python 2.7 3.4 3.5 3.6"
30+
script:
31+
- docker run --rm -v $PWD:/addons -w /addons tensorflow/tensorflow:nightly-custom-op tools/ci_build/builds/release_linux.sh
32+
after_success:
33+
- twine upload -u $PYPI_USER -p $PYPI_PW wheelhouse/*.whl
34+
35+
# MacOS Builds
36+
- stage: build
37+
name: "Build on MacOS for Python 2.7 3.4 3.5 3.6"
38+
os: osx
39+
osx_image: xcode10
40+
script:
41+
- bash -x -e tools/ci_build/builds/release_macos.sh
42+
after_success:
43+
- twine upload -u $PYPI_USER -p $PYPI_PW wheelhouse/*.whl

README.md

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,52 @@ developments that cannot be integrated into core TensorFlow
3939
| [tfa.seq2seq](tensorflow_addons/seq2seq/README.md) | Google | @qlzh727 |
4040
| [tfa.text](tensorflow_addons/text/README.md) | SIG-Addons | @seanpmorgan @facaiy |
4141

42+
## Installation
43+
#### Stable Builds
44+
To install the latest version, run the following:
45+
```
46+
pip install tensorflow-addons
47+
```
48+
49+
**Note:** You will also need [`tensorflow==2.0.0.a0`](https://www.tensorflow.org/alpha) installed.
50+
51+
To use addons:
52+
53+
```python
54+
import tensorflow as tf
55+
import tensorflow_addons as tfa
56+
```
57+
58+
#### Nightly Builds
59+
There are also nightly builds of TensorFlow Addons under the pip package
60+
`tfa-nightly`, which is built against `tf-nightly-2.0-preview`. Nightly builds
61+
include newer features, but may be less stable than the versioned releases.
62+
63+
```
64+
pip install tfa-nightly
65+
```
66+
67+
#### Installing from Source
68+
You can also install from source. This requires the [Bazel](
69+
https://bazel.build/) build system.
70+
71+
```
72+
git clone https://github.com/tensorflow/addons.git
73+
cd addons
74+
75+
# This script links project with TensorFlow dependency
76+
./configure.sh
77+
78+
bazel build build_pip_pkg
79+
bazel-bin/build_pip_pkg artifacts
80+
81+
pip install artifacts/tensorflow_addons-*.whl
82+
```
83+
84+
## Examples
85+
See [`examples/`](examples/)
86+
for end-to-end examples of various addons.
87+
4288
## Core Concepts
4389

4490
#### Standardized API within Subpackages
@@ -94,45 +140,6 @@ warning.
94140
2. 90 days gives maintainers ample time to fix their code.
95141

96142

97-
## Examples
98-
See [`examples/`](examples/)
99-
for end-to-end examples of various addons.
100-
101-
## Installation
102-
#### Stable Builds
103-
To install the latest version, run the following:
104-
```
105-
pip install tensorflow-addons
106-
```
107-
108-
**Note:** You will also need [`tensorflow==2.0.0.a0`](https://www.tensorflow.org/alpha) installed.
109-
110-
To use addons:
111-
112-
```python
113-
import tensorflow as tf
114-
import tensorflow_addons as tfa
115-
```
116-
117-
#### Installing from Source
118-
You can also install from source. This requires the [Bazel](
119-
https://bazel.build/) build system.
120-
121-
**Note:** If building from master you must install `tf-nightly-2.0-preview` in the process.
122-
123-
```
124-
git clone https://github.com/tensorflow/addons.git
125-
cd addons
126-
127-
# This script links project with TensorFlow dependency
128-
./configure.sh
129-
130-
bazel build build_pip_pkg
131-
bazel-bin/build_pip_pkg artifacts
132-
133-
pip install artifacts/tensorflow_addons-*.whl
134-
```
135-
136143
## Contributing
137144
TF-Addons is a community led open source project. As such, the project
138145
depends on public contributions, bug-fixes, and documentation. Please

build_pip_pkg.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ function abspath() {
2626

2727
function main() {
2828
DEST=${1}
29+
BUILD_FLAG=${2}
30+
2931
if [[ -z ${DEST} ]]; then
3032
echo "No destination dir provided"
3133
exit 1
@@ -47,7 +49,11 @@ function main() {
4749
pushd ${TMPDIR}
4850
echo $(date) : "=== Building wheel"
4951

50-
python setup.py bdist_wheel > /dev/null
52+
if [[ -z ${BUILD_FLAG} ]]; then
53+
${PYTHON_VERSION:=python} setup.py bdist_wheel > /dev/null
54+
else
55+
${PYTHON_VERSION:=python} setup.py bdist_wheel "${2}" > /dev/null
56+
fi
5157

5258
cp dist/*.whl "${DEST}"
5359
popd

configure.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -40,11 +40,11 @@ case $reply in
4040
[yY]*) echo "Installing...";;
4141
* ) echo "Goodbye!"; exit;;
4242
esac
43-
pip install $QUIET_FLAG -r requirements.txt
43+
${PYTHON_VERSION:=python} -m pip install $QUIET_FLAG -r requirements.txt
4444

45-
TF_CFLAGS=( $(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_compile_flags()))') )
46-
TF_LFLAGS="$(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))')"
47-
TF_CXX11_ABI_FLAG=( $(python -c 'import tensorflow as tf; print(tf.sysconfig.CXX11_ABI_FLAG)') )
45+
TF_CFLAGS=( $(${PYTHON_VERSION} -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_compile_flags()))') )
46+
TF_LFLAGS="$(${PYTHON_VERSION} -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))')"
47+
TF_CXX11_ABI_FLAG=( $(${PYTHON_VERSION} -c 'import tensorflow as tf; print(tf.sysconfig.CXX11_ABI_FLAG)') )
4848

4949
SHARED_LIBRARY_DIR=${TF_LFLAGS:2}
5050
SHARED_LIBRARY_NAME=$(echo $TF_LFLAGS | rev | cut -d":" -f1 | rev)

setup.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@
1717
TensorFlow Addons is a repository of contributions that conform to
1818
well-established API patterns,but implement new functionality not available in
1919
core TensorFlow.TensorFlow natively supports a large number of operators,
20-
layers, metrics, losses, and optimizers. However, in a fast movingfield like
20+
layers, metrics, losses, and optimizers. However, in a fast moving field like
2121
ML, there are many interesting new developments that cannot be integrated into
2222
core TensorFlow (because their broad applicability is not yet clear, or it is
23-
mostly used by a smallersubset of the community).
23+
mostly used by a smaller subset of the community).
2424
"""
2525

2626
from __future__ import absolute_import
2727
from __future__ import division
2828
from __future__ import print_function
2929

3030
import os
31+
import sys
3132

33+
from datetime import datetime
3234
from setuptools import find_packages
3335
from setuptools import setup
3436
from setuptools.dist import Distribution
@@ -46,7 +48,13 @@
4648
'six >= 1.10.0',
4749
]
4850

49-
project_name = 'tensorflow-addons'
51+
if '--nightly' in sys.argv:
52+
project_name = 'tfa-nightly'
53+
nightly_idx = sys.argv.index('--nightly')
54+
sys.argv.pop(nightly_idx)
55+
version['__version__'] += datetime.strftime(datetime.today(), "%Y%m%d")
56+
else:
57+
project_name = 'tensorflow-addons'
5058

5159

5260
class BinaryDistribution(Distribution):
@@ -78,7 +86,6 @@ def has_ext_modules(self):
7886
'Programming Language :: Python :: 3.4',
7987
'Programming Language :: Python :: 3.5',
8088
'Programming Language :: Python :: 3.6',
81-
'Programming Language :: Python :: 3.7',
8289
'Topic :: Scientific/Engineering :: Mathematics',
8390
'Topic :: Software Development :: Libraries :: Python Modules',
8491
'Topic :: Software Development :: Libraries',
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2019 The TensorFlow Authors. 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+
set -e -x
17+
18+
PYTHON_VERSIONS="python2.7 python3.4 python3.5 python3.6"
19+
curl -sSOL https://bootstrap.pypa.io/get-pip.py
20+
add-apt-repository -y ppa:deadsnakes/ppa
21+
22+
for version in ${PYTHON_VERSIONS}; do
23+
export PYTHON_VERSION=${version}
24+
apt-get -y -qq update && apt-get -y -qq install ${PYTHON_VERSION}
25+
26+
${PYTHON_VERSION} get-pip.py -q
27+
${PYTHON_VERSION} -m pip --version
28+
29+
#Link TF dependency
30+
yes 'y' | ./configure.sh --quiet
31+
32+
# Build
33+
bazel build \
34+
--noshow_progress \
35+
--noshow_loading_progress \
36+
--verbose_failures \
37+
--test_output=errors \
38+
build_pip_pkg
39+
40+
# Package Whl
41+
bazel-bin/build_pip_pkg artifacts --nightly
42+
43+
# Uncomment and use this command for release branches
44+
#bazel-bin/build_pip_pkg artifacts
45+
done
46+
47+
# Verify Wheels
48+
./tools/ci_build/builds/wheel_verify.sh
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2019 The TensorFlow Authors. 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+
set -e -x
17+
18+
PYTHON_VERSIONS="2.7.15 3.4.9 3.5.6 3.6.6"
19+
curl -sSOL https://bootstrap.pypa.io/get-pip.py
20+
brew update
21+
brew tap bazelbuild/tap
22+
brew install bazelbuild/tap/bazel
23+
eval "$(pyenv init -)"
24+
25+
for version in ${PYTHON_VERSIONS}; do
26+
export PYENV_VERSION=${version}
27+
pyenv install -s $PYENV_VERSION
28+
29+
python get-pip.py -q
30+
python -m pip install -q delocate
31+
32+
#Link TF dependency
33+
yes 'y' | sudo ./configure.sh --quiet
34+
35+
# Build
36+
bazel build \
37+
--noshow_progress \
38+
--noshow_loading_progress \
39+
--verbose_failures \
40+
--test_output=errors \
41+
build_pip_pkg
42+
43+
# Package Whl
44+
bazel-bin/build_pip_pkg artifacts --nightly
45+
46+
# Uncomment and use this command for release branches
47+
#bazel-bin/build_pip_pkg artifacts
48+
done
49+
50+
## Verify Wheel
51+
./tools/ci_build/builds/wheel_verify.sh
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
# Copyright 2019 The TensorFlow Authors. 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 -e
18+
19+
ls artifacts/*
20+
for f in artifacts/*.whl; do
21+
if [[ $(uname) == "Darwin" ]]; then
22+
delocate-wheel -w wheelhouse $f
23+
else
24+
auditwheel repair $f
25+
fi
26+
done
27+
ls wheelhouse/*

0 commit comments

Comments
 (0)