From 60ad9e3f2c684d847dc61136576039a7260f639b Mon Sep 17 00:00:00 2001 From: Hui Zhang Date: Wed, 20 Oct 2021 08:39:56 +0000 Subject: [PATCH] tools make --- requirements.txt | 2 +- setup.py | 55 ++++++++++++++++++++++++++++----- tools/Makefile | 2 +- tools/extras/install_autolog.sh | 17 ++++++++++ 4 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 tools/extras/install_autolog.sh diff --git a/requirements.txt b/requirements.txt index 2bad7e9e8..db5c584b2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -39,4 +39,4 @@ timer pyworld jieba phkit -yq +yq \ No newline at end of file diff --git a/setup.py b/setup.py index 2387eadb4..5d7d467f8 100644 --- a/setup.py +++ b/setup.py @@ -14,6 +14,9 @@ import io import os import re +from pathlib import Path +import contextlib +import inspect from setuptools import find_packages from setuptools import setup @@ -22,7 +25,7 @@ from setuptools.command.develop import develop from setuptools.command.install import install import subprocess as sp -HERE = os.path.abspath(os.path.dirname(__file__)) +HERE = Path(os.path.abspath(os.path.dirname(__file__))) def read(*names, **kwargs): @@ -36,16 +39,52 @@ long_description = read("README.md") deps = [d.strip() for d in read('requirements.txt').split()] +@contextlib.contextmanager +def pushd(new_dir): + old_dir = os.getcwd() + os.chdir(new_dir) + try: + yield + finally: + os.chdir(old_dir) + + +def check_call(cmd: str, shell=False, executable=None): + try: + sp.check_call(cmd.split(), + shell=shell, + executable="/bin/bash" if shell else executable) + except sp.CalledProcessError as e: + print( + f"{__file__}:{inspect.currentframe().f_lineno}: CMD: {cmd}, Error:", + e.output, + file=sys.stderr) + + def _pre_install(): - sp.check_call("apt-get update -y".split()) - sp.check_call("apt-get install -y".split() + - 'vim tig tree sox pkg-config'.split() + - 'libsndfile1 libflac-dev libogg-dev'.split() + - 'libvorbis-dev libboost-dev swig python3-dev'.split()) + # apt + check_call("apt-get update -y") + check_call("apt-get install -y " + 'vim tig tree sox pkg-config ' + + 'libsndfile1 libflac-dev libogg-dev ' + + 'libvorbis-dev libboost-dev swig python3-dev ') + # tools/make + tool_dir = HERE / "tools" + for f in tool_dir.glob("*.done"): + f.unlink() + with pushd(tool_dir): + check_call("make", True) def _post_install(install_lib_dir): - pass + # ctcdecoder + check_call( + "pushd deepspeech/decoders/ctcdecoder/swig && bash setup.sh && popd") + + # install third_party + check_call("pushd third_party && bash install.sh && popd") + + # install autolog + check_call("pushd tools/extras && bash install_autolog.sh && popd") class DevelopCommand(develop): @@ -76,7 +115,7 @@ class UploadCommand(Command): def run(self): try: print("Removing previous dist/ ...") - shutil.rmtree(os.path.join(HERE, "dist")) + shutil.rmtree(str(HERE / "dist")) except OSError: pass print("Building source distribution...") diff --git a/tools/Makefile b/tools/Makefile index 5690ea91e..79305a47b 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -24,7 +24,7 @@ clean: kenlm.done: # Ubuntu 16.04 透過 apt 會安裝 boost 1.58.0 # it seems that boost (1.54.0) requires higher version. After I switched to g++-5 it compiles normally. - apt install -y build-essential cmake libboost-system-dev libboost-thread-dev libboost-program-options-dev libboost-test-dev libeigen3-dev zlib1g-dev libbz2-dev liblzma-dev + apt install -y --allow-unauthenticated build-essential cmake libboost-system-dev libboost-thread-dev libboost-program-options-dev libboost-test-dev libeigen3-dev zlib1g-dev libbz2-dev liblzma-dev apt-get install -y gcc-5 g++-5 && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50 && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 50 test -d kenlm || wget -O - https://kheafield.com/code/kenlm.tar.gz --no-check-certificate | tar xz rm -rf kenlm/build && mkdir -p kenlm/build && cd kenlm/build && cmake .. && make -j4 && make install diff --git a/tools/extras/install_autolog.sh b/tools/extras/install_autolog.sh new file mode 100644 index 000000000..95d10bced --- /dev/null +++ b/tools/extras/install_autolog.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +#install auto-log +python -c "import auto_log" +if [ $? != 0 ]; then + info_msg "Install auto_log into default system path" + test -d AutoLog || git clone https://github.com/LDOUBLEV/AutoLog + if [ $? != 0 ]; then + error_msg "Download auto_log failed !!!" + exit 1 + fi + cd AutoLog + pip install -r requirements.txt + python setup.py install + cd .. + rm -rf AutoLog +fi \ No newline at end of file