forked from saltstack/salt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·323 lines (285 loc) · 11.1 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
#!/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
from distutils.sysconfig import get_python_lib, PREFIX
# 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)
# 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:
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'
)
exec(compile(open(salt_version).read(), salt_version, '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'):
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}
'''
class Build(build):
def run(self):
# Run build.run function
build.run(self)
# If our install attribute is present and set to True, we'll go ahead
# and write our install time _version.py file.
if getattr(self.distribution, 'running_salt_install', False):
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__
)
)
class Install(install):
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')
mod_path = os.path.join(get_python_lib(), 'salt/modules')
doc_path = os.path.join(PREFIX, 'share/doc', NAME + '-' + VER)
example_path = os.path.join(doc_path, 'examples')
template_path = os.path.join(example_path, 'templates')
if 'SYSCONFDIR' in os.environ:
etc_path = os.environ['SYSCONFDIR']
else:
etc_path = os.path.join(os.path.dirname(PREFIX), 'etc')
with open(salt_reqs) as f:
lines = f.read().split('\n')
requirements = [line for line in lines if line]
setup_kwargs = {'name': NAME,
'version': VER,
'description': DESC,
'author': 'Thomas S Hatch',
'author_email': 'thatch45@gmail.com',
'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.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.ssh',
'salt.roster',
],
'package_data': {'salt.modules': ['rh_ip/*.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-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',
]
if sys.platform.startswith('win'):
freezer_includes.extend([
'win32api',
'win32file',
'win32con',
'win32security',
'ntsecuritycon',
'_winreg',
'wmi',
])
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)