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