forked from reviewboard/reviewboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·514 lines (397 loc) · 15.6 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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
#!/usr/bin/env python
#
# Setup script for Review Board.
#
# A big thanks to Django project for some of the fixes used in here for
# MacOS X and data files installation.
import json
import os
import subprocess
import sys
from distutils.command.install import INSTALL_SCHEMES
from distutils.core import Command
from setuptools import setup, find_packages
from setuptools.command.develop import develop
from setuptools.command.egg_info import egg_info
from reviewboard import get_package_version, VERSION
from reviewboard.dependencies import (PYTHON_MIN_VERSION,
PYTHON_MIN_VERSION_STR,
build_dependency_list,
package_dependencies,
package_only_dependencies)
is_packaging = ('sdist' in sys.argv or
'bdist_egg' in sys.argv or
'bdist_wheel' in sys.argv or
'install' in sys.argv)
# Make sure this is a version of Python we are compatible with. This should
# prevent people on older versions from unintentionally trying to install
# the source tarball, and failing.
pyver = sys.version_info[:2]
if pyver < PYTHON_MIN_VERSION:
sys.stderr.write(
'Review Board %s is incompatible with your version of Python.\n'
'Please install Review Board 4.0.x or upgrade to Python %s or '
'newer.\n'
% (get_package_version(), PYTHON_MIN_VERSION_STR))
sys.exit(1)
# NOTE: When updating, make sure you update the classifiers below.
SUPPORTED_PYVERS = ['3.7', '3.8', '3.9', '3.10']
if '--all-pyvers' in sys.argv:
new_argv = sys.argv[1:]
new_argv.remove('--all-pyvers')
for pyver in SUPPORTED_PYVERS:
result = os.system(subprocess.list2cmdline(
['python%s' % pyver, __file__] + new_argv))
if result != 0:
sys.exit(result)
sys.exit(0)
if '--pyvers' in sys.argv:
i = sys.argv.index('--pyvers')
pyvers = sys.argv[i + 1].split()
new_argv = sys.argv[1:]
del new_argv[i - 1:i + 1]
for pyver in pyvers:
if pyver not in SUPPORTED_PYVERS:
sys.stderr.write('Python version %s is not in SUPPORTED_PYVERS'
% pyver)
sys.exit(1)
result = os.system(subprocess.list2cmdline(
['python%s' % pyver, __file__] + new_argv))
if result != 0:
sys.exit(result)
sys.exit(0)
# Make sure we're actually in the directory containing setup.py.
root_dir = os.path.dirname(__file__)
if root_dir != '':
os.chdir(root_dir)
# Tell distutils to put the data_files in platform-specific installation
# locations. See here for an explanation:
# http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb
for scheme in INSTALL_SCHEMES.values():
scheme['data'] = scheme['purelib']
if is_packaging:
# If we're packaging, include the package-only dependencies.
package_dependencies = package_dependencies.copy()
package_dependencies.update(package_only_dependencies)
class BuildEggInfoCommand(egg_info):
"""Build the egg information for the package.
If this is called when building a distribution (source, egg, or wheel),
or when installing the package from source, this will kick off tasks for
building static media and string localization files.
"""
def run(self):
"""Build the egg information."""
if is_packaging:
self.run_command('build_media')
self.run_command('build_i18n')
egg_info.run(self)
class DevelopCommand(develop):
"""Installs Review Board in developer mode.
This will install all standard and development dependencies (using Python
wheels and node.js packages from npm) and add the source tree to the
Python module search path. That includes updating the versions of pip
and setuptools on the system.
To speed up subsequent runs, callers can pass ``--no-npm`` to prevent
installing node.js packages.
"""
user_options = develop.user_options + [
(str('no-npm'), None, "Don't install packages from npm"),
(str('use-npm-cache'), None, 'Use npm-cache to install packages'),
(str('with-doc-deps'), None,
'Install documentation-related dependencies'),
]
boolean_options = develop.boolean_options + [
str('no-npm'),
str('use-npm-cache'),
str('with-doc-deps'),
]
def initialize_options(self):
"""Initialize options for the command."""
develop.initialize_options(self)
self.no_npm = None
self.with_doc_deps = None
self.use_npm_cache = None
def install_for_development(self):
"""Install the package for development.
This takes care of the work of installing all dependencies.
"""
if self.no_deps:
# In this case, we don't want to install any of the dependencies
# below. However, it's really unlikely that a user is going to
# want to pass --no-deps.
#
# Instead, what this really does is give us a way to know we've
# been called by `pip install -e .`. That will call us with
# --no-deps, as it's going to actually handle all dependency
# installation, rather than having easy_install do it.
develop.install_for_development(self)
return
# Install the latest pip and setuptools. Note that the order here
# matters, as otherwise a stale setuptools can be left behind,
# causing installation errors.
self._run_pip(['install', '-U', 'setuptools'])
self._run_pip(['install', '-U', 'pip'])
# Install the dependencies using pip instead of easy_install. This
# will use wheels instead of eggs, which are ideal for our users.
if sys.platform == 'darwin':
# We're building on macOS, and some of our dependencies
# (hi there, mercurial!) won't compile using gcc (their default
# in some cases), so we want to force the proper compiler.
os.putenv(b'CC', b'clang')
self._run_pip(['install', '-e', '.'])
self._run_pip(['install', '-r', 'dev-requirements.txt'])
if self.with_doc_deps:
self._run_pip(['install', '-r', 'doc-requirements.txt'])
if not self.no_npm:
if self.use_npm_cache:
self.distribution.command_options['install_node_deps'] = {
'use_npm_cache': ('install_node_deps', 1),
}
self.run_command('install_node_deps')
def _run_pip(self, args):
"""Run pip.
Args:
args (list):
Arguments to pass to :command:`pip`.
Raises:
RuntimeError:
The :command:`pip` command returned a non-zero exit code.
"""
cmd = subprocess.list2cmdline([sys.executable, '-m', 'pip'] + args)
ret = os.system(cmd)
if ret != 0:
raise RuntimeError('Failed to run `%s`' % cmd)
class BuildMediaCommand(Command):
"""Builds static media files for the package.
This requires first having the node.js dependencies installed.
"""
user_options = []
def initialize_options(self):
"""Initialize options for the command.
This is required, but does not actually do anything.
"""
pass
def finalize_options(self):
"""Finalize options for the command.
This is required, but does not actually do anything.
"""
pass
def run(self):
"""Runs the commands to build the static media files.
Raises:
RuntimeError:
Static media failed to build.
"""
retcode = subprocess.call([
sys.executable, 'contrib/internal/build-media.py'])
if retcode != 0:
raise RuntimeError('Failed to build media files')
class BuildI18nCommand(Command):
"""Builds string localization files."""
description = 'Compile message catalogs to .mo'
user_options = []
def initialize_options(self):
"""Initialize options for the command.
This is required, but does not actually do anything.
"""
pass
def finalize_options(self):
"""Finalize options for the command.
This is required, but does not actually do anything.
"""
pass
def run(self):
"""Runs the commands to build the string localization files.
Raises:
RuntimeError:
Localization files failed to build.
"""
retcode = subprocess.call([
sys.executable, 'contrib/internal/build-i18n.py'])
if retcode != 0:
raise RuntimeError('Failed to build i18n files')
class ListNodeDependenciesCommand(Command):
""""Write all node.js dependencies to standard output."""
description = 'Generate a package.json that lists node.js dependencies'
user_options = [
(str('to-stdout'), None,
'Write to standard output instead of a package.json file.')
]
boolean_options = [str('to-stdout')]
def initialize_options(self):
"""Set the command's option defaults."""
self.to_stdout = False
def finalize_options(self):
"""Post-process command options.
This method intentionally left blank.
"""
pass
def run(self):
"""Run the command."""
if self.to_stdout:
self._write_deps(sys.stdout)
else:
with open('package.json', 'w') as f:
self._write_deps(f)
def _write_deps(self, f):
"""Write the packaage.json to the given file handle.
Args:
f (file):
The file handle to write to.
"""
from djblets.dependencies import npm_dependencies
f.write(json.dumps(
{
'name': 'reviewboard',
'private': 'true',
'devDependencies': {},
'dependencies': npm_dependencies,
},
indent=2))
f.write('\n')
class InstallNodeDependenciesCommand(Command):
"""Install all node.js dependencies from npm.
If ``--use-npm-cache`` is passed, this will use :command:`npm-cache`
to install the packages, which is best for Continuous Integration setups.
Otherwise, :command:`npm` is used.
"""
description = \
'Install the node packages required for building static media.'
user_options = [
(str('use-npm-cache'), None, 'Use npm-cache to install packages'),
]
boolean_options = [str('use-npm-cache')]
def initialize_options(self):
"""Initialize options for the command."""
self.use_npm_cache = None
def finalize_options(self):
"""Finalize options for the command.
This is required, but does not actually do anything.
"""
pass
def run(self):
"""Run the commands to install packages from npm.
Raises:
RuntimeError:
There was an error finding or invoking the package manager.
"""
if self.use_npm_cache:
npm_command = 'npm-cache'
else:
npm_command = 'npm'
try:
subprocess.check_call([npm_command, '--version'])
except subprocess.CalledProcessError:
raise RuntimeError(
'Unable to locate %s in the path, which is needed to '
'install dependencies required to build this package.'
% npm_command)
# By this point, dependencies should be installed for us. We're also
# using the same exact dependencies as Djblets, so no need to
# duplicate that list.
self.run_command('list_node_deps')
print('Installing node.js modules...')
result = os.system('%s install' % npm_command)
os.unlink('package.json')
if result != 0:
raise RuntimeError(
'One or more node.js modules could not be installed.')
def build_entrypoints(prefix, entrypoints):
"""Build and return a list of entrypoints from a module prefix and list.
This is a utility function to help with constructing entrypoints to pass
to :py:func:`~setuptools.setup`. It takes a module prefix and a condensed
list of tuples of entrypoint names and relative module/class paths.
Args:
prefix (unicode):
The prefix for each module path.
entrypoints (list of tuple):
A list of tuples of entries for the entrypoints. Each tuple
contains an entrypoint name and a relative path to append to the
prefix.
Returns:
list of unicode:
A list of entrypoint items.
"""
result = []
for entrypoint_id, rel_class_name in entrypoints:
if ':' in rel_class_name:
sep = '.'
else:
sep = ':'
result.append('%s = %s%s%s' % (entrypoint_id, prefix, sep,
rel_class_name))
return result
PACKAGE_NAME = 'ReviewBoard'
with open('README.rst', 'r') as fp:
long_description = fp.read()
setup(
name=PACKAGE_NAME,
version=get_package_version(),
license='MIT',
description=(
'Review Board, a fully-featured web-based code and document '
'review tool made with love <3'
),
long_description=long_description,
author='Beanbag, Inc.',
author_email='[email protected]',
url='https://www.reviewboard.org/',
download_url=('https://downloads.reviewboard.org/releases/%s/%s.%s/'
% (PACKAGE_NAME, VERSION[0], VERSION[1])),
packages=find_packages(exclude=['tests']),
entry_points={
'console_scripts': build_entrypoints(
'reviewboard.cmdline',
[
('rb-site', 'rbsite:main'),
('rbext', 'rbext:main'),
('rbssh', 'rbssh:main'),
]
),
},
install_requires=build_dependency_list(package_dependencies),
extras_require={
'elasticsearch1': ['elasticsearch~=1.0'],
'elasticsearch2': ['elasticsearch~=2.0'],
'elasticsearch5': ['elasticsearch~=5.0'],
'elasticsearch7': ['elasticsearch~=7.0'],
'ldap': ['python-ldap>=3.3.1'],
'mercurial': ['mercurial'],
'mysql': ['mysqlclient>=1.4'],
'p4': ['p4python'],
'postgres': ['psycopg2-binary'],
's3': ['django-storages>=1.8,<1.9'],
'saml': ['python3-saml'],
'subvertpy': ['subvertpy'],
'swift': ['django-storage-swift'],
},
include_package_data=True,
zip_safe=False,
cmdclass={
'develop': DevelopCommand,
'egg_info': BuildEggInfoCommand,
'build_media': BuildMediaCommand,
'build_i18n': BuildI18nCommand,
'install_node_deps': InstallNodeDependenciesCommand,
'list_node_deps': ListNodeDependenciesCommand,
},
python_requires='>=3.7',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Topic :: Software Development',
'Topic :: Software Development :: Quality Assurance',
],
)