setup.py 2.9 KB
Newer Older
K
KP 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
# Copyright (c) 2021 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.
K
KP 已提交
14 15 16
import glob
import os

K
KP 已提交
17
import setuptools
K
KP 已提交
18
from setuptools.command.install import install
K
KP 已提交
19
from setuptools.command.test import test
K
KP 已提交
20 21

# set the version here
H
Hui Zhang 已提交
22
VERSION = '0.2.0'
H
huangyuxin 已提交
23 24


K
KP 已提交
25
# Inspired by the example at https://pytest.org/latest/goodpractises.html
K
KP 已提交
26
class TestCommand(test):
K
KP 已提交
27
    def finalize_options(self):
K
KP 已提交
28
        test.finalize_options(self)
K
KP 已提交
29 30 31
        self.test_args = []
        self.test_suite = True

K
KP 已提交
32 33 34 35
    def run(self):
        self.run_benchmark()
        super(TestCommand, self).run()

K
KP 已提交
36 37 38 39 40
    def run_tests(self):
        # Run nose ensuring that argv simulates running nosetests directly
        import nose
        nose.run_exit(argv=['nosetests', '-w', 'tests'])

K
KP 已提交
41 42 43 44
    def run_benchmark(self):
        for benchmark_item in glob.glob('tests/benchmark/*py'):
            os.system(f'pytest {benchmark_item}')

K
KP 已提交
45 46 47 48 49 50

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


H
huangyuxin 已提交
51 52
def write_version_py(filename='paddleaudio/__init__.py'):
    import paddleaudio
53 54
    if hasattr(paddleaudio,
               "__version__") and paddleaudio.__version__ == VERSION:
H
huangyuxin 已提交
55 56
        return
    with open(filename, "a") as f:
K
KP 已提交
57
        f.write(f"__version__ = '{VERSION}'")
H
huangyuxin 已提交
58

59

H
huangyuxin 已提交
60 61 62 63 64 65 66
def remove_version_py(filename='paddleaudio/__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 已提交
67

68

H
huangyuxin 已提交
69
write_version_py()
K
KP 已提交
70 71 72

setuptools.setup(
    name="paddleaudio",
H
huangyuxin 已提交
73
    version=VERSION,
K
KP 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    author="",
    author_email="",
    description="PaddleAudio, in development",
    long_description="",
    long_description_content_type="text/markdown",
    url="",
    packages=setuptools.find_packages(include=['paddleaudio*']),
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
    python_requires='>=3.6',
    install_requires=[
        'numpy >= 1.15.0',
        'scipy >= 1.0.0',
        'resampy >= 0.2.2',
        'soundfile >= 0.9.0',
        'colorlog',
H
Hui Zhang 已提交
93 94
        'dtaidistance >= 2.3.6',
        'mcd >= 0.4',
K
KP 已提交
95
    ],
K
KP 已提交
96 97
    setup_requires=[
        'nose', 'librosa==0.8.1', 'soundfile==0.10.3.post1',
K
KP 已提交
98
        'torchaudio==0.10.2', 'pytest-benchmark'
K
KP 已提交
99
    ],
K
KP 已提交
100 101
    cmdclass={
        'install': InstallCommand,
K
KP 已提交
102
        'test': TestCommand,
K
KP 已提交
103
    }, )
H
huangyuxin 已提交
104

105
remove_version_py()