]> jfr.im git - yt-dlp.git/blob - setup.py
[build] Improve `setup.py`
[yt-dlp.git] / setup.py
1 #!/usr/bin/env python3
2
3 import os.path
4 import subprocess
5 import sys
6 import warnings
7
8 try:
9 from setuptools import Command, find_packages, setup
10 setuptools_available = True
11 except ImportError:
12 from distutils.core import Command, setup
13 setuptools_available = False
14
15
16 def read(fname):
17 with open(fname, encoding='utf-8') as f:
18 return f.read()
19
20
21 # Get the version from yt_dlp/version.py without importing the package
22 def read_version(fname):
23 exec(compile(read(fname), fname, 'exec'))
24 return locals()['__version__']
25
26
27 VERSION = read_version('yt_dlp/version.py')
28
29 DESCRIPTION = 'A youtube-dl fork with additional features and patches'
30
31 LONG_DESCRIPTION = '\n\n'.join((
32 'Official repository: <https://github.com/yt-dlp/yt-dlp>',
33 '**PS**: Some links in this document will not work since this is a copy of the README.md from Github',
34 read('README.md')))
35
36 REQUIREMENTS = read('requirements.txt').splitlines()
37
38
39 def packages():
40 if setuptools_available:
41 return find_packages(exclude=('youtube_dl', 'youtube_dlc', 'test', 'ytdlp_plugins'))
42
43 return [
44 'yt_dlp', 'yt_dlp.extractor', 'yt_dlp.downloader', 'yt_dlp.postprocessor', 'yt_dlp.compat',
45 'yt_dlp.extractor.anvato_token_generator',
46 ]
47
48
49 def py2exe_params():
50 import py2exe # noqa: F401
51
52 warnings.warn(
53 'py2exe builds do not support pycryptodomex and needs VC++14 to run. '
54 'The recommended way is to use "pyinst.py" to build using pyinstaller')
55
56 return {
57 'console': [{
58 'script': './yt_dlp/__main__.py',
59 'dest_base': 'yt-dlp',
60 'version': VERSION,
61 'description': DESCRIPTION,
62 'comments': LONG_DESCRIPTION.split('\n')[0],
63 'product_name': 'yt-dlp',
64 'product_version': VERSION,
65 'icon_resources': [(1, 'devscripts/logo.ico')],
66 }],
67 'options': {
68 'py2exe': {
69 'bundle_files': 0,
70 'compressed': 1,
71 'optimize': 2,
72 'dist_dir': './dist',
73 'excludes': ['Crypto', 'Cryptodome'], # py2exe cannot import Crypto
74 'dll_excludes': ['w9xpopen.exe', 'crypt32.dll'],
75 # Modules that are only imported dynamically must be added here
76 'includes': ['yt_dlp.compat._legacy'],
77 }
78 },
79 'zipfile': None
80 }
81
82
83 def build_params():
84 files_spec = [
85 ('share/bash-completion/completions', ['completions/bash/yt-dlp']),
86 ('share/zsh/site-functions', ['completions/zsh/_yt-dlp']),
87 ('share/fish/vendor_completions.d', ['completions/fish/yt-dlp.fish']),
88 ('share/doc/yt_dlp', ['README.txt']),
89 ('share/man/man1', ['yt-dlp.1'])
90 ]
91 data_files = []
92 for dirname, files in files_spec:
93 resfiles = []
94 for fn in files:
95 if not os.path.exists(fn):
96 warnings.warn(f'Skipping file {fn} since it is not present. Try running " make pypi-files " first')
97 else:
98 resfiles.append(fn)
99 data_files.append((dirname, resfiles))
100
101 params = {'data_files': data_files}
102
103 if setuptools_available:
104 params['entry_points'] = {'console_scripts': ['yt-dlp = yt_dlp:main']}
105 else:
106 params['scripts'] = ['yt-dlp']
107 return params
108
109
110 class build_lazy_extractors(Command):
111 description = 'Build the extractor lazy loading module'
112 user_options = []
113
114 def initialize_options(self):
115 pass
116
117 def finalize_options(self):
118 pass
119
120 def run(self):
121 if self.dry_run:
122 print('Skipping build of lazy extractors in dry run mode')
123 return
124 subprocess.run([sys.executable, 'devscripts/make_lazy_extractors.py', 'yt_dlp/extractor/lazy_extractors.py'])
125
126
127 params = py2exe_params() if sys.argv[1:2] == ['py2exe'] else build_params()
128 setup(
129 name='yt-dlp',
130 version=VERSION,
131 maintainer='pukkandan',
132 maintainer_email='pukkandan.ytdlp@gmail.com',
133 description=DESCRIPTION,
134 long_description=LONG_DESCRIPTION,
135 long_description_content_type='text/markdown',
136 url='https://github.com/yt-dlp/yt-dlp',
137 packages=packages(),
138 install_requires=REQUIREMENTS,
139 python_requires='>=3.6',
140 project_urls={
141 'Documentation': 'https://github.com/yt-dlp/yt-dlp#readme',
142 'Source': 'https://github.com/yt-dlp/yt-dlp',
143 'Tracker': 'https://github.com/yt-dlp/yt-dlp/issues',
144 'Funding': 'https://github.com/yt-dlp/yt-dlp/blob/master/Collaborators.md#collaborators',
145 },
146 classifiers=[
147 'Topic :: Multimedia :: Video',
148 'Development Status :: 5 - Production/Stable',
149 'Environment :: Console',
150 'Programming Language :: Python',
151 'Programming Language :: Python :: 3.6',
152 'Programming Language :: Python :: 3.7',
153 'Programming Language :: Python :: 3.8',
154 'Programming Language :: Python :: 3.9',
155 'Programming Language :: Python :: 3.10',
156 'Programming Language :: Python :: 3.11',
157 'Programming Language :: Python :: Implementation',
158 'Programming Language :: Python :: Implementation :: CPython',
159 'Programming Language :: Python :: Implementation :: PyPy',
160 'License :: Public Domain',
161 'Operating System :: OS Independent',
162 ],
163 cmdclass={'build_lazy_extractors': build_lazy_extractors},
164 **params
165 )