Unverified Commit af336d66 authored by moto's avatar moto Committed by GitHub
Browse files

Fetch third party sources automatically (#1966)

This commit changes the build process so that the third party code are fetched automatically when `setup.py` is invoked.

This is to allow
1. `build_sdist` to contain the third party library codes, so that source code distribution created at the time release tag is created is complete.
2. It makes it possible to do `pip install https://github.com/pytorch/audio.git`.
    Example:
    ```
    !pip install 'cmake>=3.18' ninja
    !pip install --verbose git+https://github.com/pytorch/audio.git@auto-source
    ```
parent ad899151
......@@ -48,7 +48,6 @@ printf "Installing PyTorch with %s\n" "${cudatoolkit}"
# 2. Install torchaudio
printf "* Installing torchaudio\n"
git submodule update --init --recursive
python setup.py install
# 3. Install Test tools
......
......@@ -42,7 +42,6 @@ fi
# 2. Install torchaudio
printf "* Installing torchaudio\n"
git submodule update --init --recursive
"$root_dir/packaging/vc_env_helper.bat" python setup.py install
# 3. Install Test tools
......
......@@ -20,9 +20,6 @@ jobs:
with:
languages: python, cpp
- name: Update submodules
run: git submodule update --init --recursive
- name: Install Torch
run: |
python -m pip install cmake ninja
......
......@@ -26,7 +26,6 @@ jobs:
python -m pip install --quiet --upgrade pip
python -m pip install --quiet --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
python -m pip install --quiet pytest requests cmake ninja deep-phonemizer
git submodule update --init --recursive
python setup.py install
- name: Run integration test
run: |
......
#!/usr/bin/env python
import os
import re
import sys
import shutil
import subprocess
from pathlib import Path
from setuptools import setup, find_packages
import distutils.command.clean
import torch
from tools import setup_helpers
ROOT_DIR = Path(__file__).parent.resolve()
......@@ -80,6 +82,46 @@ 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_sox_sources():
sox_dir = ROOT_DIR / 'third_party' / 'sox'
cmake_file = sox_dir / 'CMakeLists.txt'
archive_dir = sox_dir / 'archives'
archive_dir.mkdir(exist_ok=True)
with open(cmake_file, 'r') as file_:
for line in file_:
match = re.match(r'^\s*URL\s+(https:\/\/.+)$', line)
if match:
url = match.group(1)
path = archive_dir / os.path.basename(url)
yield path, url
def _fetch_sox_archives():
for dest, url in _parse_sox_sources():
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():
if not (ROOT_DIR / 'third_party' / 'kaldi' / 'submodule' / 'CMakeLists.txt').exists():
_init_submodule()
if os.name != 'nt':
_fetch_sox_archives()
def _main():
sha = _run_cmd(['git', 'rev-parse', 'HEAD'])
branch = _run_cmd(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])
......@@ -93,6 +135,7 @@ def _main():
print('-- Building version', version)
_make_version_file(version, sha)
_fetch_third_party_libraries()
setup(
name="torchaudio",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment