diff --git a/.gitignore b/.gitignore index 46fcbcacaa..a886f68762 100644 --- a/.gitignore +++ b/.gitignore @@ -108,3 +108,4 @@ ENV/ # Generated Files test/assets/sinewave.wav +torchaudio/version.py diff --git a/build_tools/travis/install.sh b/build_tools/travis/install.sh index 9c20394b83..be6602a92e 100644 --- a/build_tools/travis/install.sh +++ b/build_tools/travis/install.sh @@ -56,5 +56,5 @@ if [[ "$SKIP_TESTS" != "true" ]]; then conda install --yes pytorch-nightly-cpu -c pytorch # TorchAudio CPP Extensions - pip install . + python setup.py install fi diff --git a/requirements.txt b/requirements.txt index 5b29f820fc..0de9fc4602 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ +torch>=1.1.0 + # Optional for torchaudio.kaldi_io numpy kaldi_io @@ -8,7 +10,7 @@ kaldi_io flake8 # Used for comparison of outputs in tests -librosa +librosa>=0.4.3 scipy # Unit tests with pytest diff --git a/setup.py b/setup.py index 8adecdefb0..091cd15c86 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,8 @@ #!/usr/bin/env python import os import platform +import sys +import subprocess from setuptools import setup, find_packages from torch.utils.cpp_extension import BuildExtension, CppExtension @@ -10,6 +12,11 @@ def check_env_flag(name, default=''): return os.getenv(name, default).upper() in set(['ON', '1', 'YES', 'TRUE', 'Y']) DEBUG = check_env_flag('DEBUG') +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) + eca = [] ela = [] if DEBUG: @@ -19,6 +26,56 @@ def check_env_flag(name, default=''): eca += ['-O0', '-g'] ela += ['-O0', '-g'] + +libraries = [] +include_dirs = [] +extra_objects = [] + +if IS_WHEEL: + 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')] + + # proper link order (sox, flac, lame) + extra_objects += [os.path.join(audio_path, 'third_party/sox/lib/libsox.a')] + 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'] + +if IS_CONDA: + # We want $PREFIX/include for conda (for sox.h) + lib_path = os.path.dirname(sys.executable) + include_dirs += [os.path.join(os.path.dirname(lib_path), 'include')] + + +# Creating the version file +cwd = os.path.dirname(os.path.abspath(__file__)) +version = '0.2.0a0' +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))) + setup( name="torchaudio", version="0.2", @@ -35,7 +92,8 @@ def check_env_flag(name, default=''): "Operating System :: Microsoft :: Windows", "Operating System :: POSIX", "Programming Language :: C++", - "Programming Language :: Python 3", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Multimedia :: Sound/Audio", "Topic :: Scientific/Engineering :: Artificial Intelligence" @@ -46,8 +104,10 @@ def check_env_flag(name, default=''): CppExtension( '_torch_sox', ['torchaudio/torch_sox.cpp'], - libraries=['sox'], + libraries=libraries, + include_dirs=include_dirs, extra_compile_args=eca, + extra_objects=extra_objects, extra_link_args=ela), ], cmdclass={'build_ext': BuildExtension}, diff --git a/torchaudio/__init__.py b/torchaudio/__init__.py index fc2bfb6b22..54fe40f04b 100644 --- a/torchaudio/__init__.py +++ b/torchaudio/__init__.py @@ -4,6 +4,7 @@ import torch import _torch_sox +from .version import __version__, git_version from torchaudio import transforms, datasets, kaldi_io, sox_effects, legacy, compliance