forked from saltstack/salt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·429 lines (382 loc) · 15.3 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
#!/usr/bin/env python
'''
The setup script for salt
'''
# For Python 2.5. A no-op on 2.6 and above.
from __future__ import with_statement
import os
import sys
from datetime import datetime
from distutils.cmd import Command
from distutils.command.build import build
from distutils.command.clean import clean
# Change to salt source's directory prior to running any command
try:
SETUP_DIRNAME = os.path.dirname(__file__)
except NameError:
# We're most likely being frozen and __file__ triggered this NameError
# Let's work around that
SETUP_DIRNAME = os.path.dirname(sys.argv[0])
if SETUP_DIRNAME != '':
os.chdir(SETUP_DIRNAME)
# Store a reference to the executing platform
IS_WINDOWS_PLATFORM = sys.platform.startswith('win')
# Use setuptools only if the user opts-in by setting the USE_SETUPTOOLS env var
# Or if setuptools was previously imported (which is the case when using
# 'distribute')
# This ensures consistent behavior but allows for advanced usage with
# virtualenv, buildout, and others.
WITH_SETUPTOOLS = False
if 'USE_SETUPTOOLS' in os.environ or 'setuptools' in sys.modules:
try:
from setuptools import setup
from setuptools.command.install import install
WITH_SETUPTOOLS = True
except ImportError:
WITH_SETUPTOOLS = False
if WITH_SETUPTOOLS is False:
import warnings
from distutils.command.install import install
from distutils.core import setup
warnings.filterwarnings(
'ignore',
'Unknown distribution option: \'(tests_require|install_requires|zip_safe)\'',
UserWarning,
'distutils.dist'
)
try:
# Add the esky bdist target if the module is available
# may require additional modules depending on platform
from esky import bdist_esky
# bbfreeze chosen for its tight integration with distutils
import bbfreeze
HAS_ESKY = True
except ImportError:
HAS_ESKY = False
SALT_VERSION = os.path.join(
os.path.abspath(SETUP_DIRNAME), 'salt', 'version.py'
)
SALT_REQS = os.path.join(
os.path.abspath(SETUP_DIRNAME), 'requirements.txt'
)
SALT_SYSPATHS = os.path.join(
os.path.abspath(SETUP_DIRNAME), 'salt', 'syspaths.py'
)
exec(compile(open(SALT_VERSION).read(), SALT_VERSION, 'exec'))
exec(compile(open(SALT_SYSPATHS).read(), SALT_SYSPATHS, 'exec'))
class TestCommand(Command):
description = 'Run tests'
user_options = [
('runtests-opts=', 'R', 'Command line options to pass to runtests.py')
]
def initialize_options(self):
self.runtests_opts = None
def finalize_options(self):
pass
def run(self):
from subprocess import Popen
self.run_command('build')
build_cmd = self.get_finalized_command('build_ext')
runner = os.path.abspath('tests/runtests.py')
test_cmd = sys.executable + ' {0}'.format(runner)
if self.runtests_opts:
test_cmd += ' {0}'.format(self.runtests_opts)
print('running test')
test_process = Popen(
test_cmd, shell=True,
stdout=sys.stdout, stderr=sys.stderr,
cwd=build_cmd.build_lib
)
test_process.communicate()
sys.exit(test_process.returncode)
class Clean(clean):
def run(self):
clean.run(self)
# Let's clean compiled *.py[c,o]
remove_extensions = ('.pyc', '.pyo')
for subdir in ('salt', 'tests', 'doc'):
root = os.path.join(os.path.dirname(__file__), subdir)
for dirname, dirnames, filenames in os.walk(root):
for filename in filenames:
for ext in remove_extensions:
if filename.endswith(ext):
os.remove(os.path.join(dirname, filename))
break
INSTALL_VERSION_TEMPLATE = '''\
# This file was auto-generated by salt's setup on \
{date:%A, %d %B %Y @ %H:%m:%S UTC}.
__version__ = {version!r}
__version_info__ = {version_info!r}
'''
INSTALL_SYSPATHS_TEMPLATE = '''\
# This file was auto-generated by salt's setup on \
{date:%A, %d %B %Y @ %H:%m:%S UTC}.
ROOT_DIR = {root_dir!r}
CONFIG_DIR = {config_dir!r}
CACHE_DIR = {cache_dir!r}
SOCK_DIR = {sock_dir!r}
SRV_ROOT_DIR= {srv_root_dir!r}
BASE_FILE_ROOTS_DIR = {base_file_roots_dir!r}
BASE_PILLAR_ROOTS_DIR = {base_pillar_roots_dir!r}
BASE_MASTER_ROOTS_DIR = {base_master_roots_dir!r}
LOGS_DIR = {logs_dir!r}
PIDFILE_DIR = {pidfile_dir!r}
'''
class Build(build):
def run(self):
# Run build.run function
build.run(self)
if getattr(self.distribution, 'running_salt_install', False):
# If our install attribute is present and set to True, we'll go
# ahead and write our install time python modules.
# Write the version file
version_file_path = os.path.join(
self.build_lib, 'salt', '_version.py'
)
open(version_file_path, 'w').write(
INSTALL_VERSION_TEMPLATE.format(
date=datetime.utcnow(),
version=__version__,
version_info=__version_info__
)
)
# Write the system paths file
system_paths_file_path = os.path.join(
self.build_lib, 'salt', '_syspaths.py'
)
open(system_paths_file_path, 'w').write(
INSTALL_SYSPATHS_TEMPLATE.format(
date=datetime.utcnow(),
root_dir=self.distribution.salt_root_dir,
config_dir=self.distribution.salt_config_dir,
cache_dir=self.distribution.salt_cache_dir,
sock_dir=self.distribution.salt_sock_dir,
srv_root_dir=self.distribution.salt_srv_root_dir,
base_file_roots_dir=self.distribution.salt_base_file_roots_dir,
base_pillar_roots_dir=self.distribution.salt_base_pillar_roots_dir,
base_master_roots_dir=self.distribution.salt_base_master_roots_dir,
logs_dir=self.distribution.salt_logs_dir,
pidfile_dir=self.distribution.salt_pidfile_dir,
)
)
class Install(install):
user_options = install.user_options + [
('salt-root-dir=', None,
'Salt\'s pre-configured root directory'),
('salt-config-dir=', None,
'Salt\'s pre-configured configuration directory'),
('salt-cache-dir=', None,
'Salt\'s pre-configured cache directory'),
('salt-sock-dir=', None,
'Salt\'s pre-configured socket directory'),
('salt-srv-root-dir=', None,
'Salt\'s pre-configured service directory'),
('salt-base-file-roots-dir=', None,
'Salt\'s pre-configured file roots directory'),
('salt-base-pillar-roots-dir=', None,
'Salt\'s pre-configured pillar roots directory'),
('salt-base-master-roots-dir=', None,
'Salt\'s pre-configured master roots directory'),
('salt-logs-dir=', None,
'Salt\'s pre-configured logs directory'),
('salt-pidfile-dir=', None,
'Salt\'s pre-configured pidfiles directory'),
]
def initialize_options(self):
install.initialize_options(self)
self.salt_root_dir = ROOT_DIR
self.salt_config_dir = CONFIG_DIR
self.salt_cache_dir = CACHE_DIR
self.salt_sock_dir = SOCK_DIR
self.salt_srv_root_dir = SRV_ROOT_DIR
self.salt_base_file_roots_dir = BASE_FILE_ROOTS_DIR
self.salt_base_pillar_roots_dir = BASE_PILLAR_ROOTS_DIR
self.salt_base_master_roots_dir = BASE_MASTER_ROOTS_DIR
self.salt_logs_dir = LOGS_DIR
self.salt_pidfile_dir = PIDFILE_DIR
def finalize_options(self):
install.finalize_options(self)
for optname in ('root_dir', 'config_dir', 'cache_dir', 'sock_dir',
'srv_root_dir', 'base_file_roots_dir',
'base_pillar_roots_dir', 'base_master_roots_dir',
'logs_dir', 'pidfile_dir'):
optvalue = getattr(self, 'salt_{0}'.format(optname))
if not optvalue:
raise RuntimeError(
'The value of --salt-{0} needs a proper path value'.format(
optname.replace('_', '-')
)
)
setattr(self.distribution, 'salt_{0}'.format(optname), optvalue)
def run(self):
# Let's set the running_salt_install attribute so we can add
# _version.py in the build command
self.distribution.running_salt_install = True
# Run install.run
install.run(self)
NAME = 'salt'
VER = __version__
DESC = ('Portable, distributed, remote execution and '
'configuration management system')
with open(SALT_REQS) as f:
REQUIREMENTS = [line for line in f.read().split('\n') if line]
SETUP_KWARGS = {'name': NAME,
'version': VER,
'description': DESC,
'author': 'Thomas S Hatch',
'author_email': '[email protected]',
'url': 'http://saltstack.org',
'cmdclass': {
'test': TestCommand,
'clean': Clean,
'build': Build,
'install': Install
},
'classifiers': ['Programming Language :: Python',
'Programming Language :: Cython',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
('License :: OSI Approved ::'
' Apache Software License'),
'Operating System :: POSIX :: Linux',
'Topic :: System :: Clustering',
'Topic :: System :: Distributed Computing',
],
'packages': ['salt',
'salt.cli',
'salt.client',
'salt.client.ssh',
'salt.client.ssh.wrapper',
'salt.ext',
'salt.auth',
'salt.wheel',
'salt.tops',
'salt.grains',
'salt.modules',
'salt.pillar',
'salt.renderers',
'salt.returners',
'salt.runners',
'salt.states',
'salt.fileserver',
'salt.search',
'salt.output',
'salt.utils',
'salt.utils.decorators',
'salt.utils.validate',
'salt.roster',
'salt.log',
'salt.log.handlers',
'salt.templates',
],
'package_data': {'salt.templates': [
'rh_ip/*.jinja',
'virt/*.jinja'
]
},
'data_files': [('share/man/man1',
['doc/man/salt-master.1',
'doc/man/salt-key.1',
'doc/man/salt.1',
'doc/man/salt-cp.1',
'doc/man/salt-call.1',
'doc/man/salt-syndic.1',
'doc/man/salt-run.1',
'doc/man/salt-ssh.1',
'doc/man/salt-minion.1',
]),
('share/man/man7', ['doc/man/salt.7']),
],
# Required for esky builds
'install_requires': REQUIREMENTS,
# The dynamic module loading in salt.modules makes this
# package zip unsafe. Required for esky builds
'zip_safe': False
}
# bbfreeze explicit includes
# Sometimes the auto module traversal doesn't find everything, so we
# explicitly add it. The auto dependency tracking especially does not work for
# imports occurring in salt.modules, as they are loaded at salt runtime.
# Specifying includes that don't exist doesn't appear to cause a freezing
# error.
FREEZER_INCLUDES = [
'zmq.core.*',
'zmq.utils.*',
'ast',
'difflib',
'distutils',
'distutils.version',
'numbers',
'json',
'M2Crypto',
'Cookie',
'asyncore',
'fileinput',
'email',
'email.mime.*',
]
if IS_WINDOWS_PLATFORM:
FREEZER_INCLUDES.extend([
'win32api',
'win32file',
'win32con',
'win32security',
'ntsecuritycon',
'_winreg',
'wmi',
'site',
])
SETUP_KWARGS['install_requires'].append('WMI')
elif sys.platform.startswith('linux'):
FREEZER_INCLUDES.append('spwd')
try:
import yum
FREEZER_INCLUDES.append('yum')
except ImportError:
pass
if HAS_ESKY:
# if the user has the esky / bbfreeze libraries installed, add the
# appropriate kwargs to setup
OPTIONS = SETUP_KWARGS.get('options', {})
OPTIONS['bdist_esky'] = {
'freezer_module': 'bbfreeze',
'freezer_options': {
'includes': FREEZER_INCLUDES
}
}
SETUP_KWARGS['options'] = OPTIONS
if WITH_SETUPTOOLS:
SETUP_KWARGS['entry_points'] = {
'console_scripts': ['salt-master = salt.scripts:salt_master',
'salt-minion = salt.scripts:salt_minion',
'salt-syndic = salt.scripts:salt_syndic',
'salt-key = salt.scripts:salt_key',
'salt-cp = salt.scripts:salt_cp',
'salt-call = salt.scripts:salt_call',
'salt-run = salt.scripts:salt_run',
'salt-ssh = salt.scripts:salt_ssh',
'salt = salt.scripts:salt_main'
],
}
# Required for running the tests suite
SETUP_KWARGS['dependency_links'] = [
'https://github.com/saltstack/salt-testing/tarball/develop#egg=SaltTesting'
]
SETUP_KWARGS['tests_require'] = ['SaltTesting']
else:
SETUP_KWARGS['scripts'] = ['scripts/salt-master',
'scripts/salt-minion',
'scripts/salt-syndic',
'scripts/salt-key',
'scripts/salt-cp',
'scripts/salt-call',
'scripts/salt-run',
'scripts/salt-ssh',
'scripts/salt']
if __name__ == '__main__':
setup(**SETUP_KWARGS)