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 @@ OPTIONS_END = 'CONFIGURATION' 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