Skip to content

Instantly share code, notes, and snippets.

@ashaw596
Created July 12, 2021 01:26
Show Gist options
  • Save ashaw596/51c41703e6c95bf0efe8dd370ab20916 to your computer and use it in GitHub Desktop.
Save ashaw596/51c41703e6c95bf0efe8dd370ab20916 to your computer and use it in GitHub Desktop.
Setup.py for fixed librispeech
from setuptools import setup, find_packages
import subprocess
from distutils.command.build import build as _build # type: ignore
import setuptools
# This class handles the pip install mechanism.
class build(_build): # pylint: disable=invalid-name
"""A build command class that will be invoked during package install.
The package built using the current setup.py will be staged and later
installed in the worker using `pip install package'. This class will be
instantiated during install for this specific scenario and will trigger
running the custom commands specified.
"""
sub_commands = _build.sub_commands + [('CustomCommands', None)]
CUSTOM_COMMANDS = [['apt', 'update'], ['apt-get', '--assume-yes', 'install', 'ffmpeg']]
class CustomCommands(setuptools.Command):
"""A setuptools Command class able to run arbitrary commands."""
def initialize_options(self):
pass
def finalize_options(self):
pass
def RunCustomCommand(self, command_list):
print('Running command: %s' % command_list)
p = subprocess.Popen(
command_list,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
# Can use communicate(input='y\n'.encode()) if the command run requires
# some confirmation.
stdout_data, _ = p.communicate()
print('Command output: %s' % stdout_data)
if p.returncode != 0:
raise RuntimeError(
'Command %s failed: exit code: %s' % (command_list, p.returncode))
def run(self):
for command in CUSTOM_COMMANDS:
self.RunCustomCommand(command)
setup(
name='MyPackageName',
version='1.0.0',
url='https://github.com/mypackage.git',
author='Author Name',
author_email='author@gmail.com',
description='Description of my package',
packages=find_packages(),
dependency_links=['https://github.com/ashaw596/datasets/tarball/master#egg=tensorflow_datasets-6.0.1'],
install_requires=[
'tensorflow',
'tensorflow_datasets[librispeech]@https://github.com/ashaw596/datasets/tarball/master#egg=tensorflow_datasets-6.0.1'],
cmdclass={
# Command class instantiated and run during pip install scenarios.
'build': build,
'CustomCommands': CustomCommands,
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment