From c0100cc54747a5bf28c9afe39496db2f45aefde5 Mon Sep 17 00:00:00 2001 From: Ping Yu <4018+pyu10055@users.noreply.github.com> Date: Wed, 23 Sep 2020 21:50:06 -0700 Subject: [PATCH 1/4] update the tf deps and moved PyInquirer to extra_requires --- tfjs-converter/README.md | 3 ++- tfjs-converter/python/README.md | 5 ++++ tfjs-converter/python/build-pip-package.sh | 5 ++++ tfjs-converter/python/extra-requirements.txt | 1 + tfjs-converter/python/requirements.txt | 3 +-- tfjs-converter/python/setup.py | 23 +++++++++++++++++++ .../python/tensorflowjs/converters/wizard.py | 7 +++++- 7 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 tfjs-converter/python/extra-requirements.txt diff --git a/tfjs-converter/README.md b/tfjs-converter/README.md index 5adfe656f5c..31e42b103f9 100644 --- a/tfjs-converter/README.md +++ b/tfjs-converter/README.md @@ -48,8 +48,9 @@ virtualenv --no-site-packages venv __1. Install the TensorFlow.js pip package:__ +Install the library with interactive CLI: ```bash - pip install tensorflowjs + pip install tensorflowjs[wizard] ``` __2. Run the converter script provided by the pip package:__ diff --git a/tfjs-converter/python/README.md b/tfjs-converter/python/README.md index 8cb7d29b21c..ab58b3bfa47 100644 --- a/tfjs-converter/python/README.md +++ b/tfjs-converter/python/README.md @@ -2,3 +2,8 @@ The **tensorflowjs** pip package contains libraries and tools for [TensorFlow.js](https://js.tensorflow.org). + +Use following command to install the library with support of interactive CLI: +```bash +pip install tensorflowjs[wizard] +``` diff --git a/tfjs-converter/python/build-pip-package.sh b/tfjs-converter/python/build-pip-package.sh index afe28e64407..092f6fa146e 100755 --- a/tfjs-converter/python/build-pip-package.sh +++ b/tfjs-converter/python/build-pip-package.sh @@ -158,6 +158,11 @@ echo echo "Copying requirements.txt" cp "${SCRIPTS_DIR}/requirements.txt" "${TMP_DIR}/" +# Copy requirements.txt +echo +echo "Copying extra-requirements.txt" +cp "${SCRIPTS_DIR}/extra-requirements.txt" "${TMP_DIR}/" + # Copy README.md. echo echo "Copying README.md" diff --git a/tfjs-converter/python/extra-requirements.txt b/tfjs-converter/python/extra-requirements.txt new file mode 100644 index 00000000000..25f9746471d --- /dev/null +++ b/tfjs-converter/python/extra-requirements.txt @@ -0,0 +1 @@ +PyInquirer==1.0.3: wizard diff --git a/tfjs-converter/python/requirements.txt b/tfjs-converter/python/requirements.txt index e5d75b6d071..e5655c9a5ef 100644 --- a/tfjs-converter/python/requirements.txt +++ b/tfjs-converter/python/requirements.txt @@ -1,6 +1,5 @@ h5py>=2.8.0 numpy>=1.16.4,<1.19.0 six>=1.12.0 -tensorflow-cpu>=2.1.0,<3 tensorflow-hub==0.7.0 -PyInquirer==1.0.3 +tensorflow>=2.1.0,<3 diff --git a/tfjs-converter/python/setup.py b/tfjs-converter/python/setup.py index e2ad3c1db96..f1d8ef139ec 100644 --- a/tfjs-converter/python/setup.py +++ b/tfjs-converter/python/setup.py @@ -25,6 +25,28 @@ def _get_requirements(file): with open(os.path.join(DIR_NAME, file), 'r') as requirements: return requirements.readlines() +def get_extra_requires(path, add_all=True): + import re + from collections import defaultdict + + with open(path) as fp: + extra_deps = defaultdict(set) + for k in fp: + if k.strip() and not k.startswith('#'): + tags = set() + if ':' in k: + k, v = k.split(':') + tags.update(vv.strip() for vv in v.split(',')) + tags.add(re.split('[<=>]', k)[0]) + for t in tags: + extra_deps[t].add(k) + + # add tag `all` at the end + if add_all: + extra_deps['all'] = set(vv for v in extra_deps.values() for vv in v) + + return extra_deps + CONSOLE_SCRIPTS = [ 'tensorflowjs_converter = tensorflowjs.converters.converter:pip_main', 'tensorflowjs_wizard = tensorflowjs.converters.wizard:pip_main', @@ -78,6 +100,7 @@ def _get_requirements(file): 'tensorflowjs/op_list': ['*.json'] }, install_requires=_get_requirements('requirements.txt'), + extras_require=get_extra_requires('extra-requirements.txt'), entry_points={ 'console_scripts': CONSOLE_SCRIPTS, }, diff --git a/tfjs-converter/python/tensorflowjs/converters/wizard.py b/tfjs-converter/python/tensorflowjs/converters/wizard.py index 9e23f99611c..d463b62012e 100644 --- a/tfjs-converter/python/tensorflowjs/converters/wizard.py +++ b/tfjs-converter/python/tensorflowjs/converters/wizard.py @@ -23,7 +23,12 @@ import tempfile import traceback -import PyInquirer +try: + import PyInquirer +except ImportError: + sys.exit("""Please install PyInquirer using following command: + `pip install PyInquirer==1.0.3`""") + import h5py import tensorflow.compat.v2 as tf from tensorflow.core.framework import types_pb2 From 8ec928b5483e261a3b2c4b000d39bbedd46fa23f Mon Sep 17 00:00:00 2001 From: Ping Yu <4018+pyu10055@users.noreply.github.com> Date: Thu, 24 Sep 2020 07:48:40 -0700 Subject: [PATCH 2/4] fix pylint error --- tfjs-converter/python/tensorflowjs/converters/wizard.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tfjs-converter/python/tensorflowjs/converters/wizard.py b/tfjs-converter/python/tensorflowjs/converters/wizard.py index d463b62012e..dd76869e721 100644 --- a/tfjs-converter/python/tensorflowjs/converters/wizard.py +++ b/tfjs-converter/python/tensorflowjs/converters/wizard.py @@ -26,8 +26,8 @@ try: import PyInquirer except ImportError: - sys.exit("""Please install PyInquirer using following command: - `pip install PyInquirer==1.0.3`""") + sys.exit("""Please install PyInquirer using following command: + pip install PyInquirer==1.0.3""") import h5py import tensorflow.compat.v2 as tf From 7162b777e5ebdc233973f69972ab93077e603f4f Mon Sep 17 00:00:00 2001 From: Ping Yu <4018+pyu10055@users.noreply.github.com> Date: Thu, 24 Sep 2020 09:52:44 -0700 Subject: [PATCH 3/4] add extra parameter for pip installation --- tfjs-converter/python/build-pip-package.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tfjs-converter/python/build-pip-package.sh b/tfjs-converter/python/build-pip-package.sh index 092f6fa146e..c38958737d2 100755 --- a/tfjs-converter/python/build-pip-package.sh +++ b/tfjs-converter/python/build-pip-package.sh @@ -244,7 +244,7 @@ for VENV_PYTHON_BIN in ${VENV_PYTHON_BINS}; do pushd "${TEST_ON_INSTALL_DIR}" > /dev/null - pip install "${WHEEL_PATH}" + pip install "${WHEEL_PATH}[wizard]" echo "Successfully installed ${WHEEL_PATH} for $(python --version 2>&1)." echo From 2f3088a1961adadfb7196ec5c05e12d15b3368c4 Mon Sep 17 00:00:00 2001 From: Ping Yu <4018+pyu10055@users.noreply.github.com> Date: Thu, 24 Sep 2020 10:17:50 -0700 Subject: [PATCH 4/4] fixed run-python-tests.sh script missing pip package failure --- tfjs-converter/python/requirements-dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tfjs-converter/python/requirements-dev.txt b/tfjs-converter/python/requirements-dev.txt index 7fcbaf740f1..1e6d88ffe2d 100644 --- a/tfjs-converter/python/requirements-dev.txt +++ b/tfjs-converter/python/requirements-dev.txt @@ -1,3 +1,4 @@ -r requirements.txt +PyInquirer==1.0.3 pylint==1.9.4; python_version < '3.0' pylint==2.5.0; python_version > '3.0'