setup.py 6.8 KB
Newer Older
H
Hui Zhang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
# Copyright (c) 2020 PaddlePaddle 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.
H
Hui Zhang 已提交
14 15
import contextlib
import inspect
H
Hui Zhang 已提交
16 17
import io
import os
H
Hui Zhang 已提交
18
import subprocess as sp
H
Hui Zhang 已提交
19
import sys
H
Hui Zhang 已提交
20
from pathlib import Path
H
Hui Zhang 已提交
21

H
Hui Zhang 已提交
22
from setuptools import Command
H
Hui Zhang 已提交
23 24
from setuptools import find_packages
from setuptools import setup
H
Hui Zhang 已提交
25 26 27
from setuptools.command.develop import develop
from setuptools.command.install import install

H
Hui Zhang 已提交
28
HERE = Path(os.path.abspath(os.path.dirname(__file__)))
H
Hui Zhang 已提交
29

H
Hui Zhang 已提交
30
VERSION = '0.0.0'
H
huangyuxin 已提交
31

H
Hui Zhang 已提交
32 33 34 35 36 37 38 39 40
base = [
    "editdistance",
    "g2p_en",
    "g2pM",
    "h5py",
    "inflect",
    "jieba",
    "jsonlines",
    "kaldiio",
小湉湉's avatar
小湉湉 已提交
41
    "librosa==0.8.1",
H
Hui Zhang 已提交
42 43 44
    "loguru",
    "matplotlib",
    "nara_wpe",
L
lym0302 已提交
45
    "onnxruntime",
H
Hui Zhang 已提交
46 47 48 49 50 51
    "pandas",
    "paddleaudio",
    "paddlenlp",
    "paddlespeech_feat",
    "praatio==5.0.0",
    "pypinyin",
小湉湉's avatar
小湉湉 已提交
52
    "pypinyin-dict",
H
Hui Zhang 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66
    "python-dateutil",
    "pyworld",
    "resampy==0.2.2",
    "sacrebleu",
    "scipy",
    "sentencepiece~=0.1.96",
    "soundfile~=0.10",
    "textgrid",
    "timer",
    "tqdm",
    "typeguard",
    "visualdl",
    "webrtcvad",
    "yacs~=0.1.8",
L
lym0302 已提交
67
    "prettytable",
L
lym0302 已提交
68
    "zhon",
H
Hui Zhang 已提交
69 70 71 72 73 74
]

server = [
    "fastapi",
    "uvicorn",
    "pattern_singleton",
L
lym0302 已提交
75
    "websockets",
H
Hui Zhang 已提交
76
]
H
huangyuxin 已提交
77

H
huangyuxin 已提交
78
requirements = {
H
Hui Zhang 已提交
79 80
    "install":
    base + server,
H
huangyuxin 已提交
81 82 83 84
    "develop": [
        "ConfigArgParse",
        "coverage",
        "gpustat",
H
huangyuxin 已提交
85
        "paddlespeech_ctcdecoders",
H
huangyuxin 已提交
86 87 88
        "phkit",
        "Pillow",
        "pybind11",
89
        "pypi-kenlm",
H
huangyuxin 已提交
90
        "snakeviz",
91 92
        "sox",
        "soxbindings",
H
huangyuxin 已提交
93 94 95 96 97 98
        "unidecode",
        "yq",
        "pre-commit",
    ]
}

99

H
huangyuxin 已提交
100 101
def write_version_py(filename='paddlespeech/__init__.py'):
    import paddlespeech
102 103
    if hasattr(paddlespeech,
               "__version__") and paddlespeech.__version__ == VERSION:
H
huangyuxin 已提交
104 105 106
        return
    with open(filename, "a") as f:
        f.write(f"\n__version__ = '{VERSION}'\n")
H
huangyuxin 已提交
107

108

H
huangyuxin 已提交
109 110 111 112 113 114 115 116
def remove_version_py(filename='paddlespeech/__init__.py'):
    with open(filename, "r") as f:
        lines = f.readlines()
    with open(filename, "w") as f:
        for line in lines:
            if "__version__" not in line:
                f.write(line)

H
huangyuxin 已提交
117

H
Hui Zhang 已提交
118 119 120 121
@contextlib.contextmanager
def pushd(new_dir):
    old_dir = os.getcwd()
    os.chdir(new_dir)
122
    print(new_dir)
H
Hui Zhang 已提交
123 124
    yield
    os.chdir(old_dir)
125
    print(old_dir)
H
Hui Zhang 已提交
126 127


H
Hui Zhang 已提交
128
def read(*names, **kwargs):
H
Hui Zhang 已提交
129 130 131
    with io.open(
            os.path.join(os.path.dirname(__file__), *names),
            encoding=kwargs.get("encoding", "utf8")) as fp:
H
Hui Zhang 已提交
132 133 134
        return fp.read()


H
Hui Zhang 已提交
135
def check_call(cmd: str, shell=False, executable=None):
H
Hui Zhang 已提交
136
    try:
H
Hui Zhang 已提交
137 138 139 140
        sp.check_call(
            cmd.split(),
            shell=shell,
            executable="/bin/bash" if shell else executable)
H
Hui Zhang 已提交
141 142 143 144 145
    except sp.CalledProcessError as e:
        print(
            f"{__file__}:{inspect.currentframe().f_lineno}: CMD: {cmd}, Error:",
            e.output,
            file=sys.stderr)
H
Hui Zhang 已提交
146
        raise e
H
Hui Zhang 已提交
147 148


149 150 151 152 153 154
def _remove(files: str):
    for f in files:
        f.unlink()


def _post_install(install_lib_dir):
H
Hui Zhang 已提交
155 156
    # tools/make
    tool_dir = HERE / "tools"
157
    _remove(tool_dir.glob("*.done"))
H
Hui Zhang 已提交
158
    with pushd(tool_dir):
H
Hui Zhang 已提交
159
        check_call("make")
H
Hui Zhang 已提交
160
    print("tools install.")
H
Hui Zhang 已提交
161

H
Hui Zhang 已提交
162
    # ctcdecoder
163
    ctcdecoder_dir = HERE / 'third_party/ctc_decoders'
H
Hui Zhang 已提交
164 165 166 167
    with pushd(ctcdecoder_dir):
        check_call("bash -e setup.sh")
    print("ctcdecoder install.")

H
Hui Zhang 已提交
168

H
Hui Zhang 已提交
169 170 171
class DevelopCommand(develop):
    def run(self):
        develop.run(self)
172
        # must after develop.run, or pkg install by shell will not see
H
Hui Zhang 已提交
173 174 175 176 177 178 179 180
        self.execute(_post_install, (self.install_lib, ), msg="Post Install...")


class InstallCommand(install):
    def run(self):
        install.run(self)


181
    # cmd: python setup.py upload
H
Hui Zhang 已提交
182 183 184 185 186 187 188 189 190 191 192 193 194
class UploadCommand(Command):
    description = "Build and publish the package."
    user_options = []

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):
        try:
            print("Removing previous dist/ ...")
H
Hui Zhang 已提交
195
            shutil.rmtree(str(HERE / "dist"))
H
Hui Zhang 已提交
196 197 198 199 200 201 202 203 204
        except OSError:
            pass
        print("Building source distribution...")
        sp.check_call([sys.executable, "setup.py", "sdist"])
        print("Uploading package to PyPi...")
        sp.check_call(["twine", "upload", "dist/*"])
        sys.exit()


H
huangyuxin 已提交
205 206
write_version_py()

H
Hui Zhang 已提交
207 208
setup_info = dict(
    # Metadata
H
Hui Zhang 已提交
209
    name='paddlespeech',
H
huangyuxin 已提交
210
    version=VERSION,
211 212 213 214
    author='PaddlePaddle Speech and Language Team',
    author_email='paddlesl@baidu.com',
    url='https://github.com/PaddlePaddle/PaddleSpeech',
    license='Apache 2.0',
H
Hui Zhang 已提交
215
    description='Speech tools and models based on Paddlepaddle',
H
Hui Zhang 已提交
216
    long_description=read("README.md"),
H
Hui Zhang 已提交
217
    long_description_content_type="text/markdown",
H
Hui Zhang 已提交
218 219 220 221
    keywords=[
        "speech",
        "asr",
        "tts",
222 223
        "speaker verfication",
        "speech classfication",
H
Hui Zhang 已提交
224 225 226
        "text frontend",
        "MFA",
        "paddlepaddle",
227 228 229
        "beam search",
        "ctcdecoder",
        "deepspeech2",
H
Hui Zhang 已提交
230 231 232 233 234 235 236
        "transformer",
        "conformer",
        "fastspeech",
        "vocoder",
        "pwgan",
        "gan",
    ],
H
huangyuxin 已提交
237
    python_requires='>=3.7',
H
huangyuxin 已提交
238
    install_requires=requirements["install"],
H
Hui Zhang 已提交
239
    extras_require={
H
huangyuxin 已提交
240 241
        'develop':
        requirements["develop"],
H
Hui Zhang 已提交
242 243 244 245
        'doc': [
            "sphinx", "sphinx-rtd-theme", "numpydoc", "myst_parser",
            "recommonmark>=0.5.0", "sphinx-markdown-tables", "sphinx-autobuild"
        ],
H
Hui Zhang 已提交
246
    },
H
Hui Zhang 已提交
247 248 249 250 251
    cmdclass={
        'develop': DevelopCommand,
        'install': InstallCommand,
        'upload': UploadCommand,
    },
H
Hui Zhang 已提交
252 253

    # Package info
J
Jackwaterveg 已提交
254
    packages=find_packages(include=('paddlespeech*')),
H
Hui Zhang 已提交
255 256
    zip_safe=True,
    classifiers=[
257
        'Development Status :: 5 - Production/Stable',
H
Hui Zhang 已提交
258 259 260 261
        'Intended Audience :: Developers',
        'Intended Audience :: Science/Research',
        'Topic :: Scientific/Engineering :: Artificial Intelligence',
        'License :: OSI Approved :: Apache Software License',
H
Hui Zhang 已提交
262 263
        'Programming Language :: Python',
        'Programming Language :: Python :: 3',
H
Hui Zhang 已提交
264
        'Programming Language :: Python :: 3.7',
H
Hui Zhang 已提交
265
        'Programming Language :: Python :: 3.8',
266
        'Programming Language :: Python :: 3.9',
K
KP 已提交
267 268
    ],
    entry_points={
L
lym0302 已提交
269 270
        'console_scripts': [
            'paddlespeech=paddlespeech.cli.entry:_execute',
L
lym0302 已提交
271 272
            'paddlespeech_server=paddlespeech.server.entry:server_execute',
            'paddlespeech_client=paddlespeech.server.entry:client_execute'
L
lym0302 已提交
273
        ]
K
KP 已提交
274
    })
H
Hui Zhang 已提交
275 276

setup(**setup_info)
H
huangyuxin 已提交
277 278

remove_version_py()