From 115add43876964956917bf596c1d0b148c5b3c26 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Tue, 9 Aug 2022 01:08:47 +0530 Subject: [devscripts] Create `utils` and refactor --- devscripts/utils.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 devscripts/utils.py (limited to 'devscripts/utils.py') diff --git a/devscripts/utils.py b/devscripts/utils.py new file mode 100644 index 000000000..aa17a5f7f --- /dev/null +++ b/devscripts/utils.py @@ -0,0 +1,35 @@ +import argparse +import functools + + +def read_file(fname): + with open(fname, encoding='utf-8') as f: + return f.read() + + +def write_file(fname, content): + with open(fname, 'w', encoding='utf-8') as f: + return f.write(content) + + +# Get the version without importing the package +def read_version(fname='yt_dlp/version.py'): + exec(compile(read_file(fname), fname, 'exec')) + return locals()['__version__'] + + +def get_filename_args(has_infile=False, default_outfile=None): + parser = argparse.ArgumentParser() + if has_infile: + parser.add_argument('infile', help='Input file') + kwargs = {'nargs': '?', 'default': default_outfile} if default_outfile else {} + parser.add_argument('outfile', **kwargs, help='Output file') + + opts = parser.parse_args() + if has_infile: + return opts.infile, opts.outfile + return opts.outfile + + +def compose_functions(*functions): + return lambda x: functools.reduce(lambda y, f: f(y), functions, x) -- cgit v1.2.3 From 7d61d2306e36d31ad992df4e332be4ff8c708ef8 Mon Sep 17 00:00:00 2001 From: Lesmiscore Date: Fri, 21 Oct 2022 22:26:00 +0900 Subject: [build] Replace `set-output` with `GITHUB_OUTPUT` (#5315) https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ Authored by: Lesmiscore --- devscripts/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'devscripts/utils.py') diff --git a/devscripts/utils.py b/devscripts/utils.py index aa17a5f7f..b91b8e65a 100644 --- a/devscripts/utils.py +++ b/devscripts/utils.py @@ -7,8 +7,8 @@ def read_file(fname): return f.read() -def write_file(fname, content): - with open(fname, 'w', encoding='utf-8') as f: +def write_file(fname, content, mode='w'): + with open(fname, mode, encoding='utf-8') as f: return f.write(content) -- cgit v1.2.3