Skip to content

Commit

Permalink
BLD: add tf 2.0 dependency for addons (tensorflow#474)
Browse files Browse the repository at this point in the history
* BLD: add tf dependency for addons
* DOC: remove note in readme
* BLD: support tfa-nightly
* BLD: pin to 2.0.0-rc0
  • Loading branch information
facaiy authored and seanpmorgan committed Sep 4, 2019
1 parent 28ec920 commit 463f5f8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 61 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ To install the latest version, run the following:
pip install tensorflow-addons
```

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

To use addons:

Expand Down
35 changes: 28 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from __future__ import print_function

import os
import platform
import sys

from datetime import datetime
Expand All @@ -39,24 +40,44 @@

DOCLINES = __doc__.split('\n')

TFA_NIGHTLY = 'tfa-nightly'
TFA_RELEASE = 'tensorflow-addons'

if '--nightly' in sys.argv:
project_name = TFA_NIGHTLY
nightly_idx = sys.argv.index('--nightly')
sys.argv.pop(nightly_idx)
else:
project_name = TFA_RELEASE

# Version
version = {}
base_dir = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(base_dir, "tensorflow_addons", "version.py")) as fp:
# yapf: disable
exec(fp.read(), version)
# yapf: enable

if project_name == TFA_NIGHTLY:
version['__version__'] += datetime.strftime(datetime.today(), "%Y%m%d")

# Dependencies
REQUIRED_PACKAGES = [
'six >= 1.10.0',
]

if '--nightly' in sys.argv:
project_name = 'tfa-nightly'
nightly_idx = sys.argv.index('--nightly')
sys.argv.pop(nightly_idx)
version['__version__'] += datetime.strftime(datetime.today(), "%Y%m%d")
else:
project_name = 'tensorflow-addons'
if project_name == TFA_RELEASE:
# TODO: remove if-else condition when tf supports package consolidation.
if platform.system() == 'Linux':
REQUIRED_PACKAGES.append('tensorflow-gpu == 2.0.0-rc0')
else:
REQUIRED_PACKAGES.append('tensorflow == 2.0.0-rc0')
elif project_name == TFA_NIGHTLY:
# TODO: remove if-else condition when tf-nightly supports package consolidation.
if platform.system() == 'Linux':
REQUIRED_PACKAGES.append('tf-nightly-gpu-2.0-preview')
else:
REQUIRED_PACKAGES.append('tf-nightly-2.0-preview')


class BinaryDistribution(Distribution):
Expand Down
58 changes: 5 additions & 53 deletions tensorflow_addons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,6 @@
from __future__ import division
from __future__ import print_function

# We need to put some imports inside a function call below, and the function
# call needs to come before the *actual* imports that populate the
# tensorflow_probability namespace. Hence, we disable this lint check throughout
# the file.
#


# Ensure TensorFlow is importable and its version is sufficiently recent. This
# needs to happen before anything else, since the imports below will try to
# import tensorflow, too.
def _ensure_tf_install():
"""Attempt to import tensorflow, and ensure its version is sufficient.
Raises:
ImportError: if either tensorflow is not importable or its version is
inadequate.
"""
try:
import tensorflow as tf
except ImportError:
# Print more informative error message, then reraise.
print("\n\nFailed to import TensorFlow. Please note that TensorFlow is"
" not installed by default when you install TensorFlow Addons."
" This is so that users can decide whether to install the"
" GPU-enabled TensorFlow package. To use TensorFlow Addons,"
" please install the most recent version of TensorFlow, by"
" following instructions at https://tensorflow.org/install.\n\n")
raise

import distutils.version

#
# Update this whenever we need to depend on a newer TensorFlow release.
#
required_tensorflow_version = "2"

if (distutils.version.LooseVersion(tf.__version__) <
distutils.version.LooseVersion(required_tensorflow_version)):
raise ImportError(
"This version of TensorFlow Addons requires TensorFlow "
"version >= {required}; Detected an installation of version "
"{present}. Please upgrade TensorFlow to proceed.".format(
required=required_tensorflow_version, present=tf.__version__))


_ensure_tf_install()

# Cleanup symbols to avoid polluting namespace.
del _ensure_tf_install
del absolute_import
del division
del print_function

# Local project imports
from tensorflow_addons import activations
from tensorflow_addons import callbacks
Expand All @@ -83,3 +30,8 @@ def _ensure_tf_install():
from tensorflow_addons import text

from tensorflow_addons.version import __version__

# Cleanup symbols to avoid polluting namespace.
del absolute_import
del division
del print_function

0 comments on commit 463f5f8

Please sign in to comment.