Skip to content

Commit f0692c7

Browse files
authored
BLD: add tf 2.0 dependency for addons (#474) (#480)
* BLD: add tf dependency for addons * DOC: remove note in readme * BLD: support tfa-nightly * BLD: pin to 2.0.0-rc0
1 parent 2ae9768 commit f0692c7

File tree

3 files changed

+33
-61
lines changed

3 files changed

+33
-61
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ To install the latest version, run the following:
4747
pip install tensorflow-addons
4848
```
4949

50-
**Note:** You will also need [`tensorflow==2.0.0-beta1`](https://www.tensorflow.org/beta) installed.
5150

5251
To use addons:
5352

setup.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from __future__ import print_function
3030

3131
import os
32+
import platform
3233
import sys
3334

3435
from datetime import datetime
@@ -39,24 +40,44 @@
3940

4041
DOCLINES = __doc__.split('\n')
4142

43+
TFA_NIGHTLY = 'tfa-nightly'
44+
TFA_RELEASE = 'tensorflow-addons'
45+
46+
if '--nightly' in sys.argv:
47+
project_name = TFA_NIGHTLY
48+
nightly_idx = sys.argv.index('--nightly')
49+
sys.argv.pop(nightly_idx)
50+
else:
51+
project_name = TFA_RELEASE
52+
53+
# Version
4254
version = {}
4355
base_dir = os.path.dirname(os.path.abspath(__file__))
4456
with open(os.path.join(base_dir, "tensorflow_addons", "version.py")) as fp:
4557
# yapf: disable
4658
exec(fp.read(), version)
4759
# yapf: enable
4860

61+
if project_name == TFA_NIGHTLY:
62+
version['__version__'] += datetime.strftime(datetime.today(), "%Y%m%d")
63+
64+
# Dependencies
4965
REQUIRED_PACKAGES = [
5066
'six >= 1.10.0',
5167
]
5268

53-
if '--nightly' in sys.argv:
54-
project_name = 'tfa-nightly'
55-
nightly_idx = sys.argv.index('--nightly')
56-
sys.argv.pop(nightly_idx)
57-
version['__version__'] += datetime.strftime(datetime.today(), "%Y%m%d")
58-
else:
59-
project_name = 'tensorflow-addons'
69+
if project_name == TFA_RELEASE:
70+
# TODO: remove if-else condition when tf supports package consolidation.
71+
if platform.system() == 'Linux':
72+
REQUIRED_PACKAGES.append('tensorflow-gpu == 2.0.0-rc0')
73+
else:
74+
REQUIRED_PACKAGES.append('tensorflow == 2.0.0-rc0')
75+
elif project_name == TFA_NIGHTLY:
76+
# TODO: remove if-else condition when tf-nightly supports package consolidation.
77+
if platform.system() == 'Linux':
78+
REQUIRED_PACKAGES.append('tf-nightly-gpu-2.0-preview')
79+
else:
80+
REQUIRED_PACKAGES.append('tf-nightly-2.0-preview')
6081

6182

6283
class BinaryDistribution(Distribution):

tensorflow_addons/__init__.py

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,59 +17,6 @@
1717
from __future__ import division
1818
from __future__ import print_function
1919

20-
# We need to put some imports inside a function call below, and the function
21-
# call needs to come before the *actual* imports that populate the
22-
# tensorflow_probability namespace. Hence, we disable this lint check throughout
23-
# the file.
24-
#
25-
26-
27-
# Ensure TensorFlow is importable and its version is sufficiently recent. This
28-
# needs to happen before anything else, since the imports below will try to
29-
# import tensorflow, too.
30-
def _ensure_tf_install():
31-
"""Attempt to import tensorflow, and ensure its version is sufficient.
32-
33-
Raises:
34-
ImportError: if either tensorflow is not importable or its version is
35-
inadequate.
36-
"""
37-
try:
38-
import tensorflow as tf
39-
except ImportError:
40-
# Print more informative error message, then reraise.
41-
print("\n\nFailed to import TensorFlow. Please note that TensorFlow is"
42-
" not installed by default when you install TensorFlow Addons."
43-
" This is so that users can decide whether to install the"
44-
" GPU-enabled TensorFlow package. To use TensorFlow Addons,"
45-
" please install the most recent version of TensorFlow, by"
46-
" following instructions at https://tensorflow.org/install.\n\n")
47-
raise
48-
49-
import distutils.version
50-
51-
#
52-
# Update this whenever we need to depend on a newer TensorFlow release.
53-
#
54-
required_tensorflow_version = "2"
55-
56-
if (distutils.version.LooseVersion(tf.__version__) <
57-
distutils.version.LooseVersion(required_tensorflow_version)):
58-
raise ImportError(
59-
"This version of TensorFlow Addons requires TensorFlow "
60-
"version >= {required}; Detected an installation of version "
61-
"{present}. Please upgrade TensorFlow to proceed.".format(
62-
required=required_tensorflow_version, present=tf.__version__))
63-
64-
65-
_ensure_tf_install()
66-
67-
# Cleanup symbols to avoid polluting namespace.
68-
del _ensure_tf_install
69-
del absolute_import
70-
del division
71-
del print_function
72-
7320
# Local project imports
7421
from tensorflow_addons import activations
7522
from tensorflow_addons import callbacks
@@ -83,3 +30,8 @@ def _ensure_tf_install():
8330
from tensorflow_addons import text
8431

8532
from tensorflow_addons.version import __version__
33+
34+
# Cleanup symbols to avoid polluting namespace.
35+
del absolute_import
36+
del division
37+
del print_function

0 commit comments

Comments
 (0)