setup.py 4.28 KB
Newer Older
Soumith Chintala's avatar
Soumith Chintala committed
1
#!/usr/bin/env python
2
3
import os
import platform
4
5
import sys
import subprocess
Soumith Chintala's avatar
Soumith Chintala committed
6
7

from setuptools import setup, find_packages
8
from torch.utils.cpp_extension import BuildExtension, CppExtension
Soumith Chintala's avatar
Soumith Chintala committed
9

10
11
12
13
14

def check_env_flag(name, default=''):
    return os.getenv(name, default).upper() in set(['ON', '1', 'YES', 'TRUE', 'Y'])

DEBUG = check_env_flag('DEBUG')
15
16
17
18
19
IS_WHEEL = check_env_flag('IS_WHEEL')
IS_CONDA = check_env_flag('IS_CONDA')

print('DEBUG:', DEBUG, 'IS_WHEEL:', IS_WHEEL, 'IS_CONDA:', IS_CONDA)

20
21
22
23
24
25
26
27
28
eca = []
ela = []
if DEBUG:
    if platform.system() == 'Windows':
        ela += ['/DEBUG:FULL']
    else:
        eca += ['-O0', '-g']
        ela += ['-O0', '-g']

29
30
31
32
33

libraries = []
include_dirs = []
extra_objects = []

34
35
36
37
# Hypothetically, the conda distribution could rely on an external sox,
# but the library is pretty small and it is not available on the default
# anaconda channel.  So we statically link it in, just as we do with wheels.
if IS_WHEEL or IS_CONDA:
38
39
40
41
42
    audio_path = os.path.dirname(os.path.abspath(__file__))

    include_dirs += [os.path.join(audio_path, 'third_party/flac/include')]
    include_dirs += [os.path.join(audio_path, 'third_party/lame/include')]
    include_dirs += [os.path.join(audio_path, 'third_party/sox/include')]
43
    include_dirs += [os.path.join(audio_path, 'third_party/mad/include')]
44

45
46
47
    # proper link order (sox, mad, flac, lame)
    # (the most important thing is that dependencies come after a libraryl
    # e.g., sox comes first)
48
    extra_objects += [os.path.join(audio_path, 'third_party/sox/lib/libsox.a')]
49
    extra_objects += [os.path.join(audio_path, 'third_party/mad/lib/libmad.a')]
50
51
52
53
54
55
56
57
    extra_objects += [os.path.join(audio_path, 'third_party/flac/lib/libFLAC.a')]
    extra_objects += [os.path.join(audio_path, 'third_party/lame/lib/libmp3lame.a')]
else:
    libraries += ['sox']


# Creating the version file
cwd = os.path.dirname(os.path.abspath(__file__))
58
version = '0.4.0a0'
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
sha = 'Unknown'

try:
    sha = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=cwd).decode('ascii').strip()
except Exception:
    pass

if os.getenv('TORCHAUDIO_BUILD_VERSION'):
    assert os.getenv('TORCHAUDIO_BUILD_NUMBER') is not None
    build_number = int(os.getenv('TORCHAUDIO_BUILD_NUMBER'))
    version = os.getenv('TORCHAUDIO_BUILD_VERSION')
    if build_number > 1:
        version += '.post' + str(build_number)
elif sha != 'Unknown':
    version += '+' + sha[:7]
print('-- Building version ' + version)

version_path = os.path.join(cwd, 'torchaudio', 'version.py')
with open(version_path, 'w') as f:
    f.write("__version__ = '{}'\n".format(version))
    f.write("git_version = {}\n".format(repr(sha)))

81
pytorch_package_name = os.getenv('TORCHAUDIO_PYTORCH_DEPENDENCY_NAME', 'torch')
82
83
84
85
86
pytorch_package_version = os.getenv('TORCHAUDIO_PYTORCH_DEPENDENCY_VERSION')

pytorch_package_dep = pytorch_package_name
if pytorch_package_version is not None:
    pytorch_package_dep += "==" + pytorch_package_version
87

Soumith Chintala's avatar
Soumith Chintala committed
88
setup(
89
90
    name=os.getenv('TORCHAUDIO_PACKAGE_NAME', "torchaudio"),
    version=version,
Soumith Chintala's avatar
Soumith Chintala committed
91
92
    description="An audio package for PyTorch",
    url="https://github.com/pytorch/audio",
93
    author="Soumith Chintala, David Pollack, Sean Naren, Peter Goldsborough",
Soumith Chintala's avatar
Soumith Chintala committed
94
    author_email="soumith@pytorch.org",
Hong Xu's avatar
Hong Xu committed
95
96
97
98
99
100
101
102
103
    classifiers=[
        "Environment :: Plugins",
        "Intended Audience :: Developers",
        "Intended Audience :: Science/Research",
        "License :: OSI Approved :: BSD License",
        "Operating System :: MacOS :: MacOS X",
        "Operating System :: Microsoft :: Windows",
        "Operating System :: POSIX",
        "Programming Language :: C++",
104
105
        "Programming Language :: Python :: 2.7",
        "Programming Language :: Python :: 3",
Hong Xu's avatar
Hong Xu committed
106
107
108
109
        "Programming Language :: Python :: Implementation :: CPython",
        "Topic :: Multimedia :: Sound/Audio",
        "Topic :: Scientific/Engineering :: Artificial Intelligence"
    ],
Soumith Chintala's avatar
Soumith Chintala committed
110
111
    # Exclude the build files.
    packages=find_packages(exclude=["build"]),
112
113
    ext_modules=[
        CppExtension(
114
115
            '_torch_sox',
            ['torchaudio/torch_sox.cpp'],
116
117
            libraries=libraries,
            include_dirs=include_dirs,
118
            extra_compile_args=eca,
119
            extra_objects=extra_objects,
120
            extra_link_args=ela),
Soumith Chintala's avatar
Soumith Chintala committed
121
    ],
122
    cmdclass={'build_ext': BuildExtension},
123
    install_requires=[pytorch_package_dep]
124
)