[cleanup] Misc (#11311)
[yt-dlp3.git] / Makefile
blob6c72ead1efa4048ced0d0bf5a4951990ca67e711
1 all: lazy-extractors yt-dlp doc pypi-files
2 clean: clean-test clean-dist
3 clean-all: clean clean-cache
4 completions: completion-bash completion-fish completion-zsh
5 doc: README.md CONTRIBUTING.md CONTRIBUTORS issuetemplates supportedsites
6 ot: offlinetest
7 tar: yt-dlp.tar.gz
9 # Keep this list in sync with pyproject.toml includes/artifacts
10 # intended use: when building a source distribution,
11 # make pypi-files && python3 -m build -sn .
12 pypi-files: AUTHORS Changelog.md LICENSE README.md README.txt supportedsites \
13 completions yt-dlp.1 pyproject.toml setup.cfg devscripts/* test/*
15 .PHONY: all clean clean-all clean-test clean-dist clean-cache \
16 completions completion-bash completion-fish completion-zsh \
17 doc issuetemplates supportedsites ot offlinetest codetest test \
18 tar pypi-files lazy-extractors install uninstall
20 clean-test:
21 rm -rf test/testdata/sigs/player-*.js tmp/ *.annotations.xml *.aria2 *.description *.dump *.frag \
22 *.frag.aria2 *.frag.urls *.info.json *.live_chat.json *.meta *.part* *.tmp *.temp *.unknown_video *.ytdl \
23 *.3gp *.ape *.ass *.avi *.desktop *.f4v *.flac *.flv *.gif *.jpeg *.jpg *.lrc *.m4a *.m4v *.mhtml *.mkv *.mov *.mp3 *.mp4 \
24 *.mpg *.mpga *.oga *.ogg *.opus *.png *.sbv *.srt *.ssa *.swf *.tt *.ttml *.url *.vtt *.wav *.webloc *.webm *.webp
25 clean-dist:
26 rm -rf yt-dlp.1.temp.md yt-dlp.1 README.txt MANIFEST build/ dist/ .coverage cover/ yt-dlp.tar.gz completions/ \
27 yt_dlp/extractor/lazy_extractors.py *.spec CONTRIBUTING.md.tmp yt-dlp yt-dlp.exe yt_dlp.egg-info/ AUTHORS
28 clean-cache:
29 find . \( \
30 -type d -name ".*_cache" -o -type d -name __pycache__ -o -name "*.pyc" -o -name "*.class" \
31 \) -prune -exec rm -rf {} \;
33 completion-bash: completions/bash/yt-dlp
34 completion-fish: completions/fish/yt-dlp.fish
35 completion-zsh: completions/zsh/_yt-dlp
36 lazy-extractors: yt_dlp/extractor/lazy_extractors.py
38 PREFIX ?= /usr/local
39 BINDIR ?= $(PREFIX)/bin
40 MANDIR ?= $(PREFIX)/man
41 SHAREDIR ?= $(PREFIX)/share
42 PYTHON ?= /usr/bin/env python3
43 GNUTAR ?= tar
45 # set markdown input format to "markdown-smart" for pandoc version 2+ and to "markdown" for pandoc prior to version 2
46 PANDOC_VERSION_CMD = pandoc -v 2>/dev/null | head -n1 | cut -d' ' -f2 | head -c1
47 PANDOC_VERSION != $(PANDOC_VERSION_CMD)
48 PANDOC_VERSION ?= $(shell $(PANDOC_VERSION_CMD))
49 MARKDOWN_CMD = if [ "$(PANDOC_VERSION)" = "1" -o "$(PANDOC_VERSION)" = "0" ]; then echo markdown; else echo markdown-smart; fi
50 MARKDOWN != $(MARKDOWN_CMD)
51 MARKDOWN ?= $(shell $(MARKDOWN_CMD))
53 install: lazy-extractors yt-dlp yt-dlp.1 completions
54 mkdir -p $(DESTDIR)$(BINDIR)
55 install -m755 yt-dlp $(DESTDIR)$(BINDIR)/yt-dlp
56 mkdir -p $(DESTDIR)$(MANDIR)/man1
57 install -m644 yt-dlp.1 $(DESTDIR)$(MANDIR)/man1/yt-dlp.1
58 mkdir -p $(DESTDIR)$(SHAREDIR)/bash-completion/completions
59 install -m644 completions/bash/yt-dlp $(DESTDIR)$(SHAREDIR)/bash-completion/completions/yt-dlp
60 mkdir -p $(DESTDIR)$(SHAREDIR)/zsh/site-functions
61 install -m644 completions/zsh/_yt-dlp $(DESTDIR)$(SHAREDIR)/zsh/site-functions/_yt-dlp
62 mkdir -p $(DESTDIR)$(SHAREDIR)/fish/vendor_completions.d
63 install -m644 completions/fish/yt-dlp.fish $(DESTDIR)$(SHAREDIR)/fish/vendor_completions.d/yt-dlp.fish
65 uninstall:
66 rm -f $(DESTDIR)$(BINDIR)/yt-dlp
67 rm -f $(DESTDIR)$(MANDIR)/man1/yt-dlp.1
68 rm -f $(DESTDIR)$(SHAREDIR)/bash-completion/completions/yt-dlp
69 rm -f $(DESTDIR)$(SHAREDIR)/zsh/site-functions/_yt-dlp
70 rm -f $(DESTDIR)$(SHAREDIR)/fish/vendor_completions.d/yt-dlp.fish
72 codetest:
73 ruff check .
74 autopep8 --diff .
76 test:
77 $(PYTHON) -m pytest -Werror
78 $(MAKE) codetest
80 offlinetest: codetest
81 $(PYTHON) -m pytest -Werror -m "not download"
83 CODE_FOLDERS_CMD = find yt_dlp -type f -name '__init__.py' | sed 's,/__init__.py,,' | grep -v '/__' | sort
84 CODE_FOLDERS != $(CODE_FOLDERS_CMD)
85 CODE_FOLDERS ?= $(shell $(CODE_FOLDERS_CMD))
86 CODE_FILES_CMD = for f in $(CODE_FOLDERS) ; do echo "$$f" | sed 's,$$,/*.py,' ; done
87 CODE_FILES != $(CODE_FILES_CMD)
88 CODE_FILES ?= $(shell $(CODE_FILES_CMD))
89 yt-dlp: $(CODE_FILES)
90 mkdir -p zip
91 for d in $(CODE_FOLDERS) ; do \
92 mkdir -p zip/$$d ;\
93 cp -pPR $$d/*.py zip/$$d/ ;\
94 done
95 (cd zip && touch -t 200001010101 $(CODE_FILES))
96 mv zip/yt_dlp/__main__.py zip/
97 (cd zip && zip -q ../yt-dlp $(CODE_FILES) __main__.py)
98 rm -rf zip
99 echo '#!$(PYTHON)' > yt-dlp
100 cat yt-dlp.zip >> yt-dlp
101 rm yt-dlp.zip
102 chmod a+x yt-dlp
104 README.md: $(CODE_FILES) devscripts/make_readme.py
105 COLUMNS=80 $(PYTHON) yt_dlp/__main__.py --ignore-config --help | $(PYTHON) devscripts/make_readme.py
107 CONTRIBUTING.md: README.md devscripts/make_contributing.py
108 $(PYTHON) devscripts/make_contributing.py README.md CONTRIBUTING.md
110 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 $(PYTHON) devscripts/make_issue_template.py .github/ISSUE_TEMPLATE_tmpl/1_broken_site.yml .github/ISSUE_TEMPLATE/1_broken_site.yml
112 $(PYTHON) devscripts/make_issue_template.py .github/ISSUE_TEMPLATE_tmpl/2_site_support_request.yml .github/ISSUE_TEMPLATE/2_site_support_request.yml
113 $(PYTHON) devscripts/make_issue_template.py .github/ISSUE_TEMPLATE_tmpl/3_site_feature_request.yml .github/ISSUE_TEMPLATE/3_site_feature_request.yml
114 $(PYTHON) devscripts/make_issue_template.py .github/ISSUE_TEMPLATE_tmpl/4_bug_report.yml .github/ISSUE_TEMPLATE/4_bug_report.yml
115 $(PYTHON) devscripts/make_issue_template.py .github/ISSUE_TEMPLATE_tmpl/5_feature_request.yml .github/ISSUE_TEMPLATE/5_feature_request.yml
116 $(PYTHON) devscripts/make_issue_template.py .github/ISSUE_TEMPLATE_tmpl/6_question.yml .github/ISSUE_TEMPLATE/6_question.yml
118 supportedsites:
119 $(PYTHON) devscripts/make_supportedsites.py supportedsites.md
121 README.txt: README.md
122 pandoc -f $(MARKDOWN) -t plain README.md -o README.txt
124 yt-dlp.1: README.md devscripts/prepare_manpage.py
125 $(PYTHON) devscripts/prepare_manpage.py yt-dlp.1.temp.md
126 pandoc -s -f $(MARKDOWN) -t man yt-dlp.1.temp.md -o yt-dlp.1
127 rm -f yt-dlp.1.temp.md
129 completions/bash/yt-dlp: $(CODE_FILES) devscripts/bash-completion.in
130 mkdir -p completions/bash
131 $(PYTHON) devscripts/bash-completion.py
133 completions/zsh/_yt-dlp: $(CODE_FILES) devscripts/zsh-completion.in
134 mkdir -p completions/zsh
135 $(PYTHON) devscripts/zsh-completion.py
137 completions/fish/yt-dlp.fish: $(CODE_FILES) devscripts/fish-completion.in
138 mkdir -p completions/fish
139 $(PYTHON) devscripts/fish-completion.py
141 _EXTRACTOR_FILES_CMD = find yt_dlp/extractor -name '*.py' -and -not -name 'lazy_extractors.py'
142 _EXTRACTOR_FILES != $(_EXTRACTOR_FILES_CMD)
143 _EXTRACTOR_FILES ?= $(shell $(_EXTRACTOR_FILES_CMD))
144 yt_dlp/extractor/lazy_extractors.py: devscripts/make_lazy_extractors.py devscripts/lazy_load_template.py $(_EXTRACTOR_FILES)
145 $(PYTHON) devscripts/make_lazy_extractors.py $@
147 yt-dlp.tar.gz: all
148 @$(GNUTAR) -czf yt-dlp.tar.gz --transform "s|^|yt-dlp/|" --owner 0 --group 0 \
149 --exclude '*.DS_Store' \
150 --exclude '*.kate-swp' \
151 --exclude '*.pyc' \
152 --exclude '*.pyo' \
153 --exclude '*~' \
154 --exclude '__pycache__' \
155 --exclude '.*_cache' \
156 --exclude '.git' \
157 -- \
158 README.md supportedsites.md Changelog.md LICENSE \
159 CONTRIBUTING.md Collaborators.md CONTRIBUTORS AUTHORS \
160 Makefile yt-dlp.1 README.txt completions .gitignore \
161 setup.cfg yt-dlp yt_dlp pyproject.toml devscripts test
163 AUTHORS: Changelog.md
164 @if [ -d '.git' ] && command -v git > /dev/null ; then \
165 echo 'Generating $@ from git commit history' ; \
166 git shortlog -s -n HEAD | cut -f2 | sort > $@ ; \
169 CONTRIBUTORS: Changelog.md
170 @if [ -d '.git' ] && command -v git > /dev/null ; then \
171 echo 'Updating $@ from git commit history' ; \
172 $(PYTHON) devscripts/make_changelog.py -v -c > /dev/null ; \