-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsetup.py
executable file
·298 lines (266 loc) · 8.53 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/usr/bin/env python
# **************************************************************************************************
# PYTOOLBOX - TOOLBOX FOR PYTHON SCRIPTS
#
# Main Developer : David Fischer (david.fischer.ch@gmail.com)
# Copyright : Copyright (c) 2012-2024 David Fischer. All rights reserved.
#
# **************************************************************************************************
#
# This file is part of David Fischer's pytoolbox Project.
#
# This project is free software: you can redistribute it and/or modify it under the terms of the
# EUPL v. 1.1 as provided by the European Commission. This project is distributed in the hope that
# it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.
#
# See the European Union Public License for more details.
#
# You should have received a copy of the EUPL General Public License along with this project.
# If not, see he EUPL licence v1.1 is available in 22 languages:
# 22-07-2013, <https://joinup.ec.europa.eu/software/page/eupl/licence-eupl>
#
# Retrieved from https://github.com/davidfischer-ch/pytoolbox.git
from __future__ import annotations
from pathlib import Path
import itertools
import subprocess
import sys
from setuptools.command import develop, install
import setuptools
import pytoolbox
if sys.argv[-1] == 'test':
sys.exit('Run pytest instead.')
install_requires: list[str] = [
'argparse',
'python-magic',
'pytz',
'requests',
'ruamel.yaml',
'termcolor'
]
try:
import grp
_ = grp
except ImportError:
# Required on Windows
install_requires.append('python-magic-bin')
extras_require: dict[str, list[str]] = {
'atlassian': [
'jira'
],
'aws': [
'boto3'
],
'django': [
'django'
],
'django_filter': [
'django-filter'
],
'django_formtools': [
'django-formtools'
],
'flask': [
'flask'
],
'imaging': [
'pillow',
'PyGObject'
],
'jinja2': [
'jinja2'
],
'mongodb': [
'pymongo'
],
'network': [
'tldextract'
],
'pandas': [
'ezodf',
'lxml',
'pandas'
],
'rest_framework': [
'django-oauth-toolkit',
'djangorestframework>=3'
],
'selenium': [
'selenium'
],
'smpte2022': [
'fastxor'
],
'vision': [
'dlib',
'keras',
'numpy',
'opencv-python',
'tensorflow'
],
'voluptuous': [
'voluptuous'
]
}
features: list[str] = ['all'] + sorted(extras_require) + ['doc', 'test']
labels: dict[str, str] = {
# Features
'all': 'All Modules',
'atlassian': 'Atlassian',
'aws': 'AWS',
'django': 'Django',
'django_filter': 'Django Filter',
'django_formtools': 'Django Form Tools',
'flask': 'Flask',
'imaging': 'Imaging',
'jinja2': 'Jinja2',
'logging': 'Logging',
'mongodb': 'MongoDB',
'network': 'Networking',
'pandas': 'Pandas',
'rest_framework': 'Django REST Framework',
'selenium': 'Selenium',
'smpte2022': 'SMPTE-2022',
'unittest': 'Unit Test',
'vision': 'Vision',
'voluptuous': 'Voluptuous',
# Actions
'doc': 'Pytoolbox Docs',
'test': 'Pytoolbox Tests',
}
extras_require.update({
'all': sorted(set(itertools.chain.from_iterable(extras_require.values()))),
'doc': [
'sphinx>=7.2.6', # 2024-03-19 Released 2023-09-14
'sphinx-rtd-theme>=2.0.0' # 2024-03-19 Released 2023-11-28
],
'test': [
'colored>=2.2.4', # 2024-03-19 Released 2023-12-19
'coverage>=7.4.4', # 2024-03-19 Released 2024-03-14
'flake8>=7.0.0', # 2024-03-19 Released 2024-01-05
'mypy>=1.9.0', # 2024-03-19 Released 2024-03-08
'pylint>=3.1.0', # 2024-03-19 Released 2024-02-25
'pytest>=8.1.1', # 2024-03-19 Released 2024-03-09
'pytest-cov>=4.1.0', # 2024-03-19 Released 2023-05-24
'pytest-pylint>=0.21.0', # 2024-03-19 Released 2023-10-06
'pytest-ruff>=0.3.1', # 2024-03-19 Released 2024-03-09
'ruff>=0.3.3', # 2024-03-19 Released 2024-03-15
# Stubs
'PyGObject-stubs>=2.10.0', # 2024-03-19 Released 2023-11-16
'types-pytz>=2024.1.0.20240203', # 2024-03-19 Released 2024-02-03
'types-requests>=2.31.0.20240311', # 2024-03-19 Released 2023-10-18
'types-urllib3>=1.26.25.14' # 2024-03-19 Released 2023-07-20
]
})
def get_command_with_extras(cls: type) -> type:
class WithExtra(cls):
user_options = [
*cls.user_options,
*[
(
f"extra-{feature.replace('_', '-')}", None,
f'Install dependencies for {labels[feature]}.'
) for feature in features
]
]
boolean_options = [
*getattr(cls, 'boolean_options', []),
'extra-all',
*[o[0] for o in user_options]
]
def initialize_options(self):
cls.initialize_options(self)
for feature in features:
setattr(self, f'extra_{feature}', None)
def finalize_options(self):
cls.finalize_options(self)
for feature in features:
if getattr(self, f'extra_{feature}'):
print(f'Enable dependencies for {labels[feature]}')
self.distribution.install_requires.extend(
self.distribution.extras_require[feature])
return WithExtra
class DocsCommand(setuptools.Command): # pylint:disable=duplicate-code
description = 'Generate documentation using Sphinx'
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
from pytoolbox import filesystem
project = Path(__file__).resolve().parent
source = project / 'docs' / 'source'
# Cleanup previously generated restructured files
for path in filesystem.find_recursive(source, r'^pytoolbox.*\.rst$', regex=True):
filesystem.remove(path)
subprocess.run([
'sphinx-apidoc',
'--force',
'--module-first',
'--separate',
'-o', source,
project / 'pytoolbox'
], check=True)
filesystem.remove(project / 'docs' / 'build' / 'html', recursive=True)
subprocess.run(['make', 'html'], cwd=project / 'docs', check=True)
long_description = Path('README.rst').read_text(encoding='utf-8')
setuptools.setup(
cmdclass={
'docs': DocsCommand,
'develop': get_command_with_extras(develop.develop),
'install': get_command_with_extras(install.install)
},
name='pytoolbox',
python_requires='>=3.11',
version=pytoolbox.__version__,
packages=setuptools.find_packages(exclude=['tests']),
package_data={
'pytoolbox.ai.vision.face.detect': ['data/*'],
'pytoolbox.ai.vision.face.recognize': ['data/*']
},
extras_require=extras_require,
install_requires=install_requires,
tests_require=extras_require['test'],
# Meta-data for upload to PyPI
author='David Fischer',
author_email='david@fisch3r.net',
classifiers=[
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Framework :: Django',
'Framework :: Flask',
'License :: OSI Approved :: European Union Public Licence 1.1 (EUPL 1.1)',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: Libraries :: Python Modules'
],
description='Toolbox for Python scripts',
keywords=[
'celery',
'ffmpeg',
'django',
'flask',
'json',
'juju',
'mock',
'pillow',
'rsync',
'rtp',
'selenium',
'smpte 2022-1',
'screen',
'subprocess'
],
license='EUPL 1.1',
long_description=long_description,
url='https://github.com/davidfischer-ch/pytoolbox'
)