Skip to content

Commit

Permalink
Replace libsox with stub
Browse files Browse the repository at this point in the history
  • Loading branch information
mthrok committed Jul 26, 2023
1 parent 49e9ed9 commit ca1eea6
Show file tree
Hide file tree
Showing 15 changed files with 170 additions and 281 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/unittest-linux/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fi
# Note: installing librosa via pip fail because it will try to compile numba.
(
set -x
conda install -y -c conda-forge ${NUMBA_DEV_CHANNEL} 'librosa==0.10.0' parameterized 'requests>=2.20' 'ffmpeg>=5,<7'
conda install -y -c conda-forge ${NUMBA_DEV_CHANNEL} sox libvorbis 'librosa==0.10.0' parameterized 'requests>=2.20' 'ffmpeg>=5,<7'
pip install kaldi-io SoundFile coverage pytest pytest-cov 'scipy==1.7.3' expecttest unidecode inflect Pillow sentencepiece pytorch-lightning 'protobuf<4.21.0' demucs tinytag pyroomacoustics flashlight-text git+https://github.com/kpu/kenlm
)
# Install fairseq
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
conda install \
--quiet --yes \
-c conda-forge \
pandoc doxygen pysoundfile
sox libvorbis pandoc doxygen pysoundfile
pip install --progress-bar off \
git+https://github.com/kpu/kenlm/ flashlight-text \
-r docs/requirements.txt -r docs/requirements-tutorials.txt
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/unittest-linux-cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jobs:
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_AUDIO_OUT_DEVICE=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MACOS=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_TEMPORARY_DISABLED=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_DECODER=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_ENCODER=true
echo '::endgroup::'
set -euxo pipefail
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/unittest-linux-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_CUDA_SMALL_MEMORY=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_ON_PYTHON_310=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_TEMPORARY_DISABLED=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_DECODER=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_ENCODER=true
# Set CHANNEL
if [[(${GITHUB_EVENT_NAME} = 'pull_request' && (${GITHUB_BASE_REF} = 'release'*)) || (${GITHUB_REF} = 'refs/heads/release'*) ]]; then
Expand Down Expand Up @@ -76,7 +78,7 @@ jobs:
--quiet --yes \
-c conda-forge \
-c numba/label/dev \
'librosa==0.10.0' parameterized 'requests>=2.20'
sox libvorbis 'librosa==0.10.0' parameterized 'requests>=2.20'
pip3 install --progress-bar off \
kaldi-io \
SoundFile \
Expand All @@ -101,7 +103,6 @@ jobs:
echo "::endgroup::"
echo "::group::Run tests"
export PATH="${PWD}/third_party/install/bin/:${PATH}"
declare -a args=(
'-v'
'--cov=torchaudio'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/unittest-macos-cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_sentencepiece=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_AUDIO_OUT_DEVICE=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_TEMPORARY_DISABLED=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_DECODER=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_ENCODER=true
echo '::endgroup::'
set -euxo pipefail
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/unittest-windows-cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_sentencepiece=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_AUDIO_OUT_DEVICE=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MACOS=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_TEMPORARY_DISABLED=true
.github/scripts/unittest-windows/setup_env.sh
.github/scripts/unittest-windows/install.sh
Expand Down
33 changes: 0 additions & 33 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import re
import shutil
import subprocess
import sys
from pathlib import Path

import torch
Expand Down Expand Up @@ -83,18 +82,6 @@ def _get_packages(branch_name, tag):
return find_packages(exclude=exclude)


def _init_submodule():
print(" --- Initializing submodules")
try:
subprocess.check_call(["git", "submodule", "init"])
subprocess.check_call(["git", "submodule", "update"])
except Exception:
print(" --- Submodule initalization failed")
print("Please run:\n\tgit submodule update --init --recursive")
sys.exit(1)
print(" --- Initialized submodule")


def _parse_url(path):
with open(path, "r") as file_:
for line in file_:
Expand All @@ -104,32 +91,13 @@ def _parse_url(path):
yield url


def _parse_sources():
third_party_dir = ROOT_DIR / "third_party"
libs = ["sox"]
archive_dir = third_party_dir / "archives"
archive_dir.mkdir(exist_ok=True)
for lib in libs:
cmake_file = third_party_dir / lib / "CMakeLists.txt"
for url in _parse_url(cmake_file):
path = archive_dir / os.path.basename(url)
yield path, url


def _fetch_archives(src):
for dest, url in src:
if not dest.exists():
print(f" --- Fetching {os.path.basename(dest)}")
torch.hub.download_url_to_file(url, dest, progress=False)


def _fetch_third_party_libraries():
# Revert this when a submodule is added again
# _init_submodule()
if os.name != "nt":
_fetch_archives(_parse_sources())


def _main():
sha = _run_cmd(["git", "rev-parse", "HEAD"])
branch = _run_cmd(["git", "rev-parse", "--abbrev-ref", "HEAD"])
Expand All @@ -143,7 +111,6 @@ def _main():
print("-- Building version", version)

_make_version_file(version, sha)
_fetch_third_party_libraries()

with open("README.md") as f:
long_description = f.read()
Expand Down
26 changes: 4 additions & 22 deletions test/torchaudio_unittest/common_utils/case_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import torch
import torchaudio
from torch.testing._internal.common_utils import TestCase as PytorchTestCase
from torchaudio._internal.module_utils import is_module_available
from torchaudio._internal.module_utils import eval_env, is_module_available
from torchaudio.utils.ffmpeg_utils import get_video_decoders, get_video_encoders

from .backend_utils import set_audio_backend
Expand Down Expand Up @@ -143,24 +143,6 @@ def is_cuda_ctc_decoder_available():
return _IS_CUDA_CTC_DECODER_AVAILABLE


def _eval_env(var, default):
if var not in os.environ:
return default

val = os.environ.get(var, "0")
trues = ["1", "true", "TRUE", "on", "ON", "yes", "YES"]
falses = ["0", "false", "FALSE", "off", "OFF", "no", "NO"]
if val in trues:
return True
if val not in falses:
# fmt: off
raise RuntimeError(
f"Unexpected environment variable value `{var}={val}`. "
f"Expected one of {trues + falses}")
# fmt: on
return False


def _fail(reason):
def deco(test_item):
if isinstance(test_item, type):
Expand All @@ -185,7 +167,7 @@ def _pass(test_item):
return test_item


_IN_CI = _eval_env("CI", default=False)
_IN_CI = eval_env("CI", default=False)


def _skipIf(condition, reason, key):
Expand All @@ -195,7 +177,7 @@ def _skipIf(condition, reason, key):
# In CI, default to fail, so as to prevent accidental skip.
# In other env, default to skip
var = f"TORCHAUDIO_TEST_ALLOW_SKIP_IF_{key}"
skip_allowed = _eval_env(var, default=not _IN_CI)
skip_allowed = eval_env(var, default=not _IN_CI)
if skip_allowed:
return unittest.skip(reason)
return _fail(f"{reason} But the test cannot be skipped. (CI={_IN_CI}, {var}={skip_allowed}.)")
Expand Down Expand Up @@ -268,7 +250,7 @@ def skipIfNoSoxEncoder(ext):
key="NO_CUCTC_DECODER",
)
skipIfRocm = _skipIf(
_eval_env("TORCHAUDIO_TEST_WITH_ROCM", default=False),
eval_env("TORCHAUDIO_TEST_WITH_ROCM", default=False),
reason="The test doesn't currently work on the ROCm stack.",
key="ON_ROCM",
)
Expand Down
Loading

0 comments on commit ca1eea6

Please sign in to comment.