Skip to content

Commit

Permalink
BLD: Remove hard installation dep (#974)
Browse files Browse the repository at this point in the history
* Remove hard installation dep

* Update TF required

* Update build for no dependency

* Move to utils

* Remove sys exit
  • Loading branch information
seanpmorgan authored Jan 30, 2020
1 parent c8231fb commit 37f0fd9
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 8 deletions.
7 changes: 5 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ ignore =
# Useful to ignore for "import keras.backend as K"
N812

#imported but unused in __init__.py, that's ok.
per-file-ignores = **/__init__.py:F401
per-file-ignores =
# imported but unused in __init__.py, that's ok.
**/__init__.py:F401
# import not at top okay due to TF installation check
tensorflow_addons/__init__.py:F401,E402
1 change: 1 addition & 0 deletions build_deps/build-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.1.0
11 changes: 9 additions & 2 deletions build_deps/build_pip_pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ function main() {
exit 1
fi

# Check if python3 is available. On Windows VM it is not.
if [ -x "$(command -v python3)" ]; then
_PYTHON_BINARY=python3
else
_PYTHON_BINARY=python
fi

mkdir -p ${DEST}
DEST=$(abspath "${DEST}")
echo "=== destination directory: ${DEST}"
Expand Down Expand Up @@ -72,9 +79,9 @@ function main() {

if [[ -z ${BUILD_FLAG} ]]; then
# Windows has issues with locking library files for deletion so do not fail here
${PYTHON_VERSION:=python} setup.py bdist_wheel || true
${_PYTHON_BINARY} setup.py bdist_wheel || true
else
${PYTHON_VERSION:=python} setup.py bdist_wheel "${2}" || true
${_PYTHON_BINARY} setup.py bdist_wheel "${2}" || true
fi

cp dist/*.whl "${DEST}"
Expand Down
2 changes: 1 addition & 1 deletion build_deps/check_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def check_dependencies(requirement_file_name):
except DistributionNotFound as e:
print(e)
sys.exit(1)
sys.exit(0)


if __name__ == "__main__":
check_dependencies("requirements.txt")
check_dependencies("build_deps/build-requirements.txt")
5 changes: 4 additions & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def generate_shared_lib_name(namespec):
with open("requirements.txt") as f:
_REQUIRED_PKG = f.read().splitlines()

with open("build_deps/build-requirements.txt") as f:
_REQUIRED_PKG.extend(f.read().splitlines())

print()
print("> TensorFlow Addons will link to the framework in a pre-installed TF pacakge...")
print("> Checking installed packages in {}".format(_PYTHON_PATH))
Expand All @@ -116,7 +119,7 @@ def generate_shared_lib_name(namespec):
print("> Installing...")
install_cmd = [_PYTHON_PATH, "-m", "pip", "install"]
install_cmd.extend(_PIP_INSTALL_OPTS)
install_cmd.extend(["-r", "requirements.txt"])
install_cmd.extend(_REQUIRED_PKG)
subprocess.check_call(install_cmd)
else:
print("> Exiting...")
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
tensorflow==2.1.0
typeguard
3 changes: 3 additions & 0 deletions tensorflow_addons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# limitations under the License.
# ==============================================================================
"""Useful extra functionality for TensorFlow maintained by SIG-addons."""
from tensorflow_addons.utils.ensure_tf_install import _ensure_tf_install

_ensure_tf_install()

# Local project imports
from tensorflow_addons import activations
Expand Down
43 changes: 43 additions & 0 deletions tensorflow_addons/utils/ensure_tf_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================


# 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.
"""
import tensorflow as tf
import distutils.version

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

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__
)
)
1 change: 1 addition & 0 deletions tools/ci_testing/addons_cpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ echo ""
export CC_OPT_FLAGS='-mavx'
export TF_NEED_CUDA=0

# Check if python3 is available. On Windows VM it is not.
if [ -x "$(command -v python3)" ]; then
echo 'y' | python3 ./configure.py
else
Expand Down
2 changes: 1 addition & 1 deletion tools/ci_testing/addons_gpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export CUDA_TOOLKIT_PATH="/usr/local/cuda"
export TF_CUDNN_VERSION="7"
export CUDNN_INSTALL_PATH="/usr/lib/x86_64-linux-gnu"

# Check if python3 is available. On Windows it is not.
# Check if python3 is available. On Windows VM it is not.
if [ -x "$(command -v python3)" ]; then
echo 'y' | python3 ./configure.py
else
Expand Down

0 comments on commit 37f0fd9

Please sign in to comment.