From c487cf00101525ff836d59a2a42ef63e85ea9556 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Sun, 17 Apr 2022 22:48:50 +0530 Subject: [PATCH] [cleanup] Misc --- Makefile | 12 +++-- devscripts/make_issue_template.py | 1 - devscripts/make_readme.py | 46 ++++++++++++---- pytest.ini | 4 -- setup.cfg | 32 ++++++++++- setup.py | 2 +- tox.ini | 16 ------ yt_dlp/YoutubeDL.py | 14 +++-- yt_dlp/__init__.py | 1 + yt_dlp/downloader/common.py | 1 + yt_dlp/downloader/dash.py | 2 +- yt_dlp/downloader/external.py | 34 ++++++------ yt_dlp/downloader/hls.py | 2 +- yt_dlp/downloader/http.py | 16 +++--- yt_dlp/downloader/niconico.py | 6 +-- yt_dlp/downloader/youtube_live_chat.py | 5 +- yt_dlp/extractor/common.py | 6 +-- yt_dlp/extractor/testurl.py | 2 +- yt_dlp/update.py | 35 ++++++------ yt_dlp/utils.py | 73 +++++++++++--------------- 20 files changed, 171 insertions(+), 139 deletions(-) delete mode 100644 pytest.ini delete mode 100644 tox.ini diff --git a/Makefile b/Makefile index 0ff5626ada..3e5885c1d6 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,9 @@ tar: yt-dlp.tar.gz # Keep this list in sync with MANIFEST.in # intended use: when building a source distribution, # make pypi-files && python setup.py sdist -pypi-files: AUTHORS Changelog.md LICENSE README.md README.txt supportedsites completions yt-dlp.1 devscripts/* test/* +pypi-files: + AUTHORS Changelog.md LICENSE README.md README.txt supportedsites \ + completions yt-dlp.1 requirements.txt devscripts/* test/* .PHONY: all clean install test tar pypi-files completions ot offlinetest codetest supportedsites @@ -91,10 +93,10 @@ yt-dlp: yt_dlp/*.py yt_dlp/*/*.py rm yt-dlp.zip chmod a+x yt-dlp -README.md: yt_dlp/*.py yt_dlp/*/*.py +README.md: yt_dlp/*.py yt_dlp/*/*.py devscripts/make_readme.py COLUMNS=80 $(PYTHON) yt_dlp/__main__.py --ignore-config --help | $(PYTHON) devscripts/make_readme.py -CONTRIBUTING.md: README.md +CONTRIBUTING.md: README.md devscripts/make_contributing.py $(PYTHON) devscripts/make_contributing.py README.md CONTRIBUTING.md issuetemplates: devscripts/make_issue_template.py .github/ISSUE_TEMPLATE_tmpl/1_broken_site.yml .github/ISSUE_TEMPLATE_tmpl/2_site_support_request.yml .github/ISSUE_TEMPLATE_tmpl/3_site_feature_request.yml .github/ISSUE_TEMPLATE_tmpl/4_bug_report.yml .github/ISSUE_TEMPLATE_tmpl/5_feature_request.yml yt_dlp/version.py @@ -111,7 +113,7 @@ supportedsites: README.txt: README.md pandoc -f $(MARKDOWN) -t plain README.md -o README.txt -yt-dlp.1: README.md +yt-dlp.1: README.md devscripts/prepare_manpage.py $(PYTHON) devscripts/prepare_manpage.py yt-dlp.1.temp.md pandoc -s -f $(MARKDOWN) -t man yt-dlp.1.temp.md -o yt-dlp.1 rm -f yt-dlp.1.temp.md @@ -147,7 +149,7 @@ yt-dlp.tar.gz: all CONTRIBUTING.md Collaborators.md CONTRIBUTORS AUTHORS \ Makefile MANIFEST.in yt-dlp.1 README.txt completions \ setup.py setup.cfg yt-dlp yt_dlp requirements.txt \ - devscripts test tox.ini pytest.ini + devscripts test AUTHORS: .mailmap git shortlog -s -n | cut -f2 | sort > AUTHORS diff --git a/devscripts/make_issue_template.py b/devscripts/make_issue_template.py index 811a3e9b57..5a309008e2 100644 --- a/devscripts/make_issue_template.py +++ b/devscripts/make_issue_template.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import io import optparse diff --git a/devscripts/make_readme.py b/devscripts/make_readme.py index fd234bf58f..15c4a7c7dc 100755 --- a/devscripts/make_readme.py +++ b/devscripts/make_readme.py @@ -2,6 +2,7 @@ # yt-dlp --help | make_readme.py # This must be run in a console of correct width +import functools import re import sys @@ -12,19 +13,44 @@ EPILOG_START = 'See full documentation' -helptext = sys.stdin.read() -if isinstance(helptext, bytes): - helptext = helptext.decode() +def take_section(text, start=None, end=None, *, shift=0): + return text[ + text.index(start) + shift if start else None: + text.index(end) + shift if end else None + ] -start, end = helptext.index(f'\n {OPTIONS_START}'), helptext.index(f'\n{EPILOG_START}') -options = re.sub(r'(?m)^ (\w.+)$', r'## \1', helptext[start + 1: end + 1]) + +def apply_patch(text, patch): + return re.sub(*patch, text) + + +options = take_section(sys.stdin.read(), f'\n {OPTIONS_START}', f'\n{EPILOG_START}', shift=1) + +switch_col_width = len(re.search(r'(?m)^\s{5,}', options).group()) +delim = f'\n{" " * switch_col_width}' + +PATCHES = ( + ( # Headings + r'(?m)^ (\w.+\n)( (?=\w))?', + r'## \1' + ), + ( # Do not split URLs + rf'({delim[:-1]})? (?P