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