[cleanup] Misc

This commit is contained in:
pukkandan 2023-03-04 22:40:08 +05:30
parent eb8fd6d044
commit 392389b7df
No known key found for this signature in database
GPG key ID: 7EEE9E1E817D0A39
8 changed files with 46 additions and 38 deletions

View file

@ -1,5 +1,6 @@
import argparse
import functools
import subprocess
def read_file(fname):
@ -12,8 +13,8 @@ def write_file(fname, content, mode='w'):
return f.write(content)
# Get the version without importing the package
def read_version(fname='yt_dlp/version.py'):
"""Get the version without importing the package"""
exec(compile(read_file(fname), fname, 'exec'))
return locals()['__version__']
@ -33,3 +34,13 @@ def get_filename_args(has_infile=False, default_outfile=None):
def compose_functions(*functions):
return lambda x: functools.reduce(lambda y, f: f(y), functions, x)
def run_process(*args, **kwargs):
kwargs.setdefault('text', True)
kwargs.setdefault('check', True)
kwargs.setdefault('capture_output', True)
if kwargs['text']:
kwargs.setdefault('encoding', 'utf-8')
kwargs.setdefault('errors', 'replace')
return subprocess.run(args, **kwargs)