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..c38958737d2 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" @@ -239,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 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-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' 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..dd76869e721 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