1
0

setup.py 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. '''
  4. The setup script for salt
  5. '''
  6. # pylint: disable=file-perms,ungrouped-imports,wrong-import-order,wrong-import-position,repr-flag-used-in-string
  7. # pylint: disable=3rd-party-local-module-not-gated,resource-leakage
  8. # pylint: disable=C0111,E1101,E1103,F0401,W0611,W0201,W0232,R0201,R0902,R0903
  9. # For Python 2.5. A no-op on 2.6 and above.
  10. from __future__ import absolute_import, print_function, with_statement
  11. import os
  12. import sys
  13. import glob
  14. import time
  15. import operator
  16. import platform
  17. try:
  18. from urllib2 import urlopen
  19. except ImportError:
  20. from urllib.request import urlopen # pylint: disable=no-name-in-module
  21. from datetime import datetime
  22. # pylint: disable=E0611
  23. import distutils.dist
  24. from distutils import log
  25. from distutils.cmd import Command
  26. from distutils.errors import DistutilsArgError
  27. from distutils.command.build import build
  28. from distutils.command.clean import clean
  29. from distutils.command.sdist import sdist
  30. from distutils.command.install_lib import install_lib
  31. from distutils.version import LooseVersion # pylint: disable=blacklisted-module
  32. from ctypes.util import find_library
  33. # pylint: enable=E0611
  34. try:
  35. import zmq
  36. HAS_ZMQ = True
  37. except ImportError:
  38. HAS_ZMQ = False
  39. try:
  40. DATE = datetime.utcfromtimestamp(int(os.environ['SOURCE_DATE_EPOCH']))
  41. except (KeyError, ValueError):
  42. DATE = datetime.utcnow()
  43. # Change to salt source's directory prior to running any command
  44. try:
  45. SETUP_DIRNAME = os.path.dirname(__file__)
  46. except NameError:
  47. # We're most likely being frozen and __file__ triggered this NameError
  48. # Let's work around that
  49. SETUP_DIRNAME = os.path.dirname(sys.argv[0])
  50. if SETUP_DIRNAME != '':
  51. os.chdir(SETUP_DIRNAME)
  52. SETUP_DIRNAME = os.path.abspath(SETUP_DIRNAME)
  53. BOOTSTRAP_SCRIPT_DISTRIBUTED_VERSION = os.environ.get(
  54. # The user can provide a different bootstrap-script version.
  55. # ATTENTION: A tag for that version MUST exist
  56. 'BOOTSTRAP_SCRIPT_VERSION',
  57. # If no bootstrap-script version was provided from the environment, let's
  58. # provide the one we define.
  59. 'v2014.06.21'
  60. )
  61. # Store a reference to the executing platform
  62. IS_WINDOWS_PLATFORM = sys.platform.startswith('win')
  63. if IS_WINDOWS_PLATFORM:
  64. IS_SMARTOS_PLATFORM = False
  65. else:
  66. # os.uname() not available on Windows.
  67. IS_SMARTOS_PLATFORM = os.uname()[0] == 'SunOS' and os.uname()[3].startswith('joyent_')
  68. # Store a reference whether if we're running under Python 3 and above
  69. IS_PY3 = sys.version_info > (3,)
  70. # Use setuptools only if the user opts-in by setting the USE_SETUPTOOLS env var
  71. # Or if setuptools was previously imported (which is the case when using
  72. # 'distribute')
  73. # This ensures consistent behavior but allows for advanced usage with
  74. # virtualenv, buildout, and others.
  75. WITH_SETUPTOOLS = False
  76. if 'USE_SETUPTOOLS' in os.environ or 'setuptools' in sys.modules:
  77. try:
  78. from setuptools import setup
  79. from setuptools.command.develop import develop
  80. from setuptools.command.install import install
  81. from setuptools.command.sdist import sdist
  82. from setuptools.command.egg_info import egg_info
  83. WITH_SETUPTOOLS = True
  84. except ImportError:
  85. WITH_SETUPTOOLS = False
  86. if WITH_SETUPTOOLS is False:
  87. import warnings
  88. # pylint: disable=E0611
  89. from distutils.command.install import install
  90. from distutils.core import setup
  91. # pylint: enable=E0611
  92. warnings.filterwarnings(
  93. 'ignore',
  94. 'Unknown distribution option: \'(extras_require|tests_require|install_requires|zip_safe)\'',
  95. UserWarning,
  96. 'distutils.dist'
  97. )
  98. try:
  99. # Add the esky bdist target if the module is available
  100. # may require additional modules depending on platform
  101. from esky import bdist_esky
  102. # bbfreeze chosen for its tight integration with distutils
  103. import bbfreeze
  104. HAS_ESKY = True
  105. except ImportError:
  106. HAS_ESKY = False
  107. SALT_VERSION = os.path.join(os.path.abspath(SETUP_DIRNAME), 'salt', 'version.py')
  108. SALT_VERSION_HARDCODED = os.path.join(os.path.abspath(SETUP_DIRNAME), 'salt', '_version.py')
  109. SALT_SYSPATHS_HARDCODED = os.path.join(os.path.abspath(SETUP_DIRNAME), 'salt', '_syspaths.py')
  110. SALT_REQS = os.path.join(os.path.abspath(SETUP_DIRNAME), 'requirements', 'base.txt')
  111. SALT_ZEROMQ_REQS = os.path.join(os.path.abspath(SETUP_DIRNAME), 'requirements', 'zeromq.txt')
  112. SALT_RAET_REQS = os.path.join(os.path.abspath(SETUP_DIRNAME), 'requirements', 'raet.txt')
  113. SALT_WINDOWS_REQS = os.path.join(os.path.abspath(SETUP_DIRNAME), 'pkg', 'windows', 'req.txt')
  114. SALT_LONG_DESCRIPTION_FILE = os.path.join(os.path.abspath(SETUP_DIRNAME), 'README.rst')
  115. # Salt SSH Packaging Detection
  116. PACKAGED_FOR_SALT_SSH_FILE = os.path.join(os.path.abspath(SETUP_DIRNAME), '.salt-ssh-package')
  117. PACKAGED_FOR_SALT_SSH = os.path.isfile(PACKAGED_FOR_SALT_SSH_FILE)
  118. # pylint: disable=W0122
  119. exec(compile(open(SALT_VERSION).read(), SALT_VERSION, 'exec'))
  120. # pylint: enable=W0122
  121. # ----- Helper Functions -------------------------------------------------------------------------------------------->
  122. def _parse_op(op):
  123. '''
  124. >>> _parse_op('>')
  125. 'gt'
  126. >>> _parse_op('>=')
  127. 'ge'
  128. >>> _parse_op('=>')
  129. 'ge'
  130. >>> _parse_op('=> ')
  131. 'ge'
  132. >>> _parse_op('<')
  133. 'lt'
  134. >>> _parse_op('<=')
  135. 'le'
  136. >>> _parse_op('==')
  137. 'eq'
  138. >>> _parse_op(' <= ')
  139. 'le'
  140. '''
  141. op = op.strip()
  142. if '>' in op:
  143. if '=' in op:
  144. return 'ge'
  145. else:
  146. return 'gt'
  147. elif '<' in op:
  148. if '=' in op:
  149. return 'le'
  150. else:
  151. return 'lt'
  152. elif '!' in op:
  153. return 'ne'
  154. else:
  155. return 'eq'
  156. def _parse_ver(ver):
  157. '''
  158. >>> _parse_ver("'3.4' # pyzmq 17.1.0 stopped building wheels for python3.4")
  159. '3.4'
  160. >>> _parse_ver('"3.4"')
  161. '3.4'
  162. >>> _parse_ver('"2.6.17"')
  163. '2.6.17'
  164. '''
  165. if '#' in ver:
  166. ver, _ = ver.split('#', 1)
  167. ver = ver.strip()
  168. return ver.strip('\'').strip('"')
  169. def _check_ver(pyver, op, wanted):
  170. '''
  171. >>> _check_ver('2.7.15', 'gt', '2.7')
  172. True
  173. >>> _check_ver('2.7.15', 'gt', '2.7.15')
  174. False
  175. >>> _check_ver('2.7.15', 'ge', '2.7.15')
  176. True
  177. >>> _check_ver('2.7.15', 'eq', '2.7.15')
  178. True
  179. '''
  180. pyver = distutils.version.LooseVersion(pyver)
  181. wanted = distutils.version.LooseVersion(wanted)
  182. if IS_PY3:
  183. if not isinstance(pyver, str):
  184. pyver = str(pyver)
  185. if not isinstance(wanted, str):
  186. wanted = str(wanted)
  187. return getattr(operator, '__{}__'.format(op))(pyver, wanted)
  188. def _parse_requirements_file(requirements_file):
  189. parsed_requirements = []
  190. with open(requirements_file) as rfh:
  191. for line in rfh.readlines():
  192. line = line.strip()
  193. if not line or line.startswith(('#', '-r')):
  194. continue
  195. if IS_WINDOWS_PLATFORM:
  196. if 'libcloud' in line:
  197. continue
  198. if IS_PY3 and 'futures' in line.lower():
  199. # Python 3 already has futures, installing it will only break
  200. # the current python installation whenever futures is imported
  201. continue
  202. try:
  203. pkg, pyverspec = line.rsplit(';', 1)
  204. except ValueError:
  205. pkg, pyverspec = line, ''
  206. pyverspec = pyverspec.strip()
  207. if pyverspec:
  208. _, op, ver = pyverspec.split(' ', 2)
  209. if not _check_ver(platform.python_version(), _parse_op(op), _parse_ver(ver)):
  210. continue
  211. parsed_requirements.append(pkg)
  212. return parsed_requirements
  213. # <---- Helper Functions ---------------------------------------------------------------------------------------------
  214. # ----- Custom Distutils/Setuptools Commands ------------------------------------------------------------------------>
  215. class WriteSaltVersion(Command):
  216. description = 'Write salt\'s hardcoded version file'
  217. user_options = []
  218. def initialize_options(self):
  219. '''
  220. Abstract method that is required to be overwritten
  221. '''
  222. def finalize_options(self):
  223. '''
  224. Abstract method that is required to be overwritten
  225. '''
  226. def run(self):
  227. if not os.path.exists(SALT_VERSION_HARDCODED) or self.distribution.with_salt_version:
  228. # Write the version file
  229. if getattr(self.distribution, 'salt_version_hardcoded_path', None) is None:
  230. print('This command is not meant to be called on it\'s own')
  231. exit(1)
  232. if not self.distribution.with_salt_version:
  233. salt_version = __saltstack_version__ # pylint: disable=undefined-variable
  234. else:
  235. from salt.version import SaltStackVersion
  236. salt_version = SaltStackVersion.parse(self.distribution.with_salt_version)
  237. # pylint: disable=E0602
  238. open(self.distribution.salt_version_hardcoded_path, 'w').write(
  239. INSTALL_VERSION_TEMPLATE.format(
  240. date=DATE,
  241. full_version_info=salt_version.full_info
  242. )
  243. )
  244. # pylint: enable=E0602
  245. class GenerateSaltSyspaths(Command):
  246. description = 'Generate salt\'s hardcoded syspaths file'
  247. def initialize_options(self):
  248. pass
  249. def finalize_options(self):
  250. pass
  251. def run(self):
  252. # Write the syspaths file
  253. if getattr(self.distribution, 'salt_syspaths_hardcoded_path', None) is None:
  254. print('This command is not meant to be called on it\'s own')
  255. exit(1)
  256. # Write the system paths file
  257. open(self.distribution.salt_syspaths_hardcoded_path, 'w').write(
  258. INSTALL_SYSPATHS_TEMPLATE.format(
  259. date=DATE,
  260. root_dir=self.distribution.salt_root_dir,
  261. share_dir=self.distribution.salt_share_dir,
  262. config_dir=self.distribution.salt_config_dir,
  263. cache_dir=self.distribution.salt_cache_dir,
  264. sock_dir=self.distribution.salt_sock_dir,
  265. srv_root_dir=self.distribution.salt_srv_root_dir,
  266. base_file_roots_dir=self.distribution.salt_base_file_roots_dir,
  267. base_pillar_roots_dir=self.distribution.salt_base_pillar_roots_dir,
  268. base_master_roots_dir=self.distribution.salt_base_master_roots_dir,
  269. base_thorium_roots_dir=self.distribution.salt_base_thorium_roots_dir,
  270. logs_dir=self.distribution.salt_logs_dir,
  271. pidfile_dir=self.distribution.salt_pidfile_dir,
  272. spm_parent_path=self.distribution.salt_spm_parent_dir,
  273. spm_formula_path=self.distribution.salt_spm_formula_dir,
  274. spm_pillar_path=self.distribution.salt_spm_pillar_dir,
  275. spm_reactor_path=self.distribution.salt_spm_reactor_dir,
  276. home_dir=self.distribution.salt_home_dir,
  277. )
  278. )
  279. class WriteSaltSshPackagingFile(Command):
  280. description = 'Write salt\'s ssh packaging file'
  281. user_options = []
  282. def initialize_options(self):
  283. '''
  284. Abstract method that is required to be overwritten
  285. '''
  286. def finalize_options(self):
  287. '''
  288. Abstract method that is required to be overwritten
  289. '''
  290. def run(self):
  291. if not os.path.exists(PACKAGED_FOR_SALT_SSH_FILE):
  292. # Write the salt-ssh packaging file
  293. if getattr(self.distribution, 'salt_ssh_packaging_file', None) is None:
  294. print('This command is not meant to be called on it\'s own')
  295. exit(1)
  296. # pylint: disable=E0602
  297. open(self.distribution.salt_ssh_packaging_file, 'w').write('Packaged for Salt-SSH\n')
  298. # pylint: enable=E0602
  299. if WITH_SETUPTOOLS:
  300. class Develop(develop):
  301. user_options = develop.user_options + [
  302. ('write-salt-version', None,
  303. 'Generate Salt\'s _version.py file which allows proper version '
  304. 'reporting. This defaults to False on develop/editable setups. '
  305. 'If WRITE_SALT_VERSION is found in the environment this flag is '
  306. 'switched to True.'),
  307. ('generate-salt-syspaths', None,
  308. 'Generate Salt\'s _syspaths.py file which allows tweaking some '
  309. 'common paths that salt uses. This defaults to False on '
  310. 'develop/editable setups. If GENERATE_SALT_SYSPATHS is found in '
  311. 'the environment this flag is switched to True.'),
  312. ('mimic-salt-install', None,
  313. 'Mimmic the install command when running the develop command. '
  314. 'This will generate salt\'s _version.py and _syspaths.py files. '
  315. 'Generate Salt\'s _syspaths.py file which allows tweaking some '
  316. 'This defaults to False on develop/editable setups. '
  317. 'If MIMIC_INSTALL is found in the environment this flag is '
  318. 'switched to True.')
  319. ]
  320. boolean_options = develop.boolean_options + [
  321. 'write-salt-version',
  322. 'generate-salt-syspaths',
  323. 'mimic-salt-install'
  324. ]
  325. def initialize_options(self):
  326. develop.initialize_options(self)
  327. self.write_salt_version = False
  328. self.generate_salt_syspaths = False
  329. self.mimic_salt_install = False
  330. def finalize_options(self):
  331. develop.finalize_options(self)
  332. if 'WRITE_SALT_VERSION' in os.environ:
  333. self.write_salt_version = True
  334. if 'GENERATE_SALT_SYSPATHS' in os.environ:
  335. self.generate_salt_syspaths = True
  336. if 'MIMIC_SALT_INSTALL' in os.environ:
  337. self.mimic_salt_install = True
  338. if self.mimic_salt_install:
  339. self.write_salt_version = True
  340. self.generate_salt_syspaths = True
  341. def run(self):
  342. if IS_WINDOWS_PLATFORM:
  343. # Download the required DLLs
  344. self.distribution.salt_download_windows_dlls = True
  345. self.run_command('download-windows-dlls')
  346. self.distribution.salt_download_windows_dlls = None
  347. if self.write_salt_version is True:
  348. self.distribution.running_salt_install = True
  349. self.distribution.salt_version_hardcoded_path = SALT_VERSION_HARDCODED
  350. self.run_command('write_salt_version')
  351. if self.generate_salt_syspaths:
  352. self.distribution.salt_syspaths_hardcoded_path = SALT_SYSPATHS_HARDCODED
  353. self.run_command('generate_salt_syspaths')
  354. # Resume normal execution
  355. develop.run(self)
  356. class DownloadWindowsDlls(Command):
  357. description = 'Download required DLL\'s for windows'
  358. def initialize_options(self):
  359. pass
  360. def finalize_options(self):
  361. pass
  362. def run(self):
  363. if getattr(self.distribution, 'salt_download_windows_dlls', None) is None:
  364. print('This command is not meant to be called on it\'s own')
  365. exit(1)
  366. import pip
  367. # pip has moved many things to `_internal` starting with pip 10
  368. if LooseVersion(pip.__version__) < LooseVersion('10.0'):
  369. from pip.utils.logging import indent_log # pylint: disable=no-name-in-module
  370. else:
  371. from pip._internal.utils.logging import indent_log # pylint: disable=no-name-in-module
  372. platform_bits, _ = platform.architecture()
  373. url = 'https://repo.saltstack.com/windows/dependencies/{bits}/{fname}.dll'
  374. dest = os.path.join(os.path.dirname(sys.executable), '{fname}.dll')
  375. with indent_log():
  376. for fname in ('libeay32', 'libsodium', 'ssleay32', 'msvcr120'):
  377. # See if the library is already on the system
  378. if find_library(fname):
  379. continue
  380. furl = url.format(bits=platform_bits[:2], fname=fname)
  381. fdest = dest.format(fname=fname)
  382. if not os.path.exists(fdest):
  383. log.info('Downloading {0}.dll to {1} from {2}'.format(fname, fdest, furl))
  384. try:
  385. import requests
  386. from contextlib import closing
  387. with closing(requests.get(furl, stream=True)) as req:
  388. if req.status_code == 200:
  389. with open(fdest, 'wb') as wfh:
  390. for chunk in req.iter_content(chunk_size=4096):
  391. if chunk: # filter out keep-alive new chunks
  392. wfh.write(chunk)
  393. wfh.flush()
  394. else:
  395. log.error(
  396. 'Failed to download {0}.dll to {1} from {2}'.format(
  397. fname, fdest, furl
  398. )
  399. )
  400. except ImportError:
  401. req = urlopen(furl)
  402. if req.getcode() == 200:
  403. with open(fdest, 'wb') as wfh:
  404. if IS_PY3:
  405. while True:
  406. chunk = req.read(4096)
  407. if len(chunk) == 0:
  408. break
  409. wfh.write(chunk)
  410. wfh.flush()
  411. else:
  412. while True:
  413. for chunk in req.read(4096):
  414. if not chunk:
  415. break
  416. wfh.write(chunk)
  417. wfh.flush()
  418. else:
  419. log.error(
  420. 'Failed to download {0}.dll to {1} from {2}'.format(
  421. fname, fdest, furl
  422. )
  423. )
  424. class Sdist(sdist):
  425. def make_release_tree(self, base_dir, files):
  426. if self.distribution.ssh_packaging:
  427. self.distribution.salt_ssh_packaging_file = PACKAGED_FOR_SALT_SSH_FILE
  428. self.run_command('write_salt_ssh_packaging_file')
  429. self.filelist.files.append(os.path.basename(PACKAGED_FOR_SALT_SSH_FILE))
  430. if not IS_PY3 and not isinstance(base_dir, str):
  431. # Work around some bad code in distutils which logs unicode paths
  432. # against a str format string.
  433. base_dir = base_dir.encode('utf-8')
  434. sdist.make_release_tree(self, base_dir, files)
  435. # Let's generate salt/_version.py to include in the sdist tarball
  436. self.distribution.running_salt_sdist = True
  437. self.distribution.salt_version_hardcoded_path = os.path.join(
  438. base_dir, 'salt', '_version.py'
  439. )
  440. self.run_command('write_salt_version')
  441. def make_distribution(self):
  442. sdist.make_distribution(self)
  443. if self.distribution.ssh_packaging:
  444. os.unlink(PACKAGED_FOR_SALT_SSH_FILE)
  445. class CloudSdist(Sdist): # pylint: disable=too-many-ancestors
  446. user_options = Sdist.user_options + [
  447. ('download-bootstrap-script', None,
  448. 'Download the latest stable bootstrap-salt.sh script. This '
  449. 'can also be triggered by having `DOWNLOAD_BOOTSTRAP_SCRIPT=1` as an '
  450. 'environment variable.')
  451. ]
  452. boolean_options = Sdist.boolean_options + [
  453. 'download-bootstrap-script'
  454. ]
  455. def initialize_options(self):
  456. Sdist.initialize_options(self)
  457. self.skip_bootstrap_download = True
  458. self.download_bootstrap_script = False
  459. def finalize_options(self):
  460. Sdist.finalize_options(self)
  461. if 'SKIP_BOOTSTRAP_DOWNLOAD' in os.environ:
  462. log('Please stop using \'SKIP_BOOTSTRAP_DOWNLOAD\' and use ' # pylint: disable=not-callable
  463. '\'DOWNLOAD_BOOTSTRAP_SCRIPT\' instead')
  464. if 'DOWNLOAD_BOOTSTRAP_SCRIPT' in os.environ:
  465. download_bootstrap_script = os.environ.get(
  466. 'DOWNLOAD_BOOTSTRAP_SCRIPT', '0'
  467. )
  468. self.download_bootstrap_script = download_bootstrap_script == '1'
  469. def run(self):
  470. if self.download_bootstrap_script is True:
  471. # Let's update the bootstrap-script to the version defined to be
  472. # distributed. See BOOTSTRAP_SCRIPT_DISTRIBUTED_VERSION above.
  473. url = (
  474. 'https://github.com/saltstack/salt-bootstrap/raw/{0}'
  475. '/bootstrap-salt.sh'.format(
  476. BOOTSTRAP_SCRIPT_DISTRIBUTED_VERSION
  477. )
  478. )
  479. deploy_path = os.path.join(
  480. SETUP_DIRNAME,
  481. 'salt',
  482. 'cloud',
  483. 'deploy',
  484. 'bootstrap-salt.sh'
  485. )
  486. log.info(
  487. 'Updating bootstrap-salt.sh.'
  488. '\n\tSource: {0}'
  489. '\n\tDestination: {1}'.format(
  490. url,
  491. deploy_path
  492. )
  493. )
  494. try:
  495. import requests
  496. req = requests.get(url)
  497. if req.status_code == 200:
  498. script_contents = req.text.encode(req.encoding)
  499. else:
  500. log.error(
  501. 'Failed to update the bootstrap-salt.sh script. HTTP '
  502. 'Error code: {0}'.format(
  503. req.status_code
  504. )
  505. )
  506. except ImportError:
  507. req = urlopen(url)
  508. if req.getcode() == 200:
  509. script_contents = req.read()
  510. else:
  511. log.error(
  512. 'Failed to update the bootstrap-salt.sh script. HTTP '
  513. 'Error code: {0}'.format(
  514. req.getcode()
  515. )
  516. )
  517. try:
  518. with open(deploy_path, 'w') as fp_:
  519. fp_.write(script_contents)
  520. except (OSError, IOError) as err:
  521. log.error(
  522. 'Failed to write the updated script: {0}'.format(err)
  523. )
  524. # Let's the rest of the build command
  525. Sdist.run(self)
  526. def write_manifest(self):
  527. # We only need to ship the scripts which are supposed to be installed
  528. dist_scripts = self.distribution.scripts
  529. for script in self.filelist.files[:]:
  530. if not script.startswith('scripts/'):
  531. continue
  532. if script not in dist_scripts:
  533. self.filelist.files.remove(script)
  534. return Sdist.write_manifest(self)
  535. class TestCommand(Command):
  536. description = 'Run tests'
  537. user_options = [
  538. ('runtests-opts=', 'R', 'Command line options to pass to runtests.py')
  539. ]
  540. def initialize_options(self):
  541. self.runtests_opts = None
  542. def finalize_options(self):
  543. '''
  544. Abstract method that is required to be overwritten
  545. '''
  546. def run(self):
  547. from subprocess import Popen
  548. self.run_command('build')
  549. build_cmd = self.get_finalized_command('build_ext')
  550. runner = os.path.abspath('tests/runtests.py')
  551. test_cmd = sys.executable + ' {0}'.format(runner)
  552. if self.runtests_opts:
  553. test_cmd += ' {0}'.format(self.runtests_opts)
  554. print('running test')
  555. test_process = Popen(
  556. test_cmd, shell=True,
  557. stdout=sys.stdout, stderr=sys.stderr,
  558. cwd=build_cmd.build_lib
  559. )
  560. test_process.communicate()
  561. sys.exit(test_process.returncode)
  562. class Clean(clean):
  563. def run(self):
  564. clean.run(self)
  565. # Let's clean compiled *.py[c,o]
  566. for subdir in ('salt', 'tests', 'doc'):
  567. root = os.path.join(os.path.dirname(__file__), subdir)
  568. for dirname, _, _ in os.walk(root):
  569. for to_remove_filename in glob.glob('{0}/*.py[oc]'.format(dirname)):
  570. os.remove(to_remove_filename)
  571. INSTALL_VERSION_TEMPLATE = '''\
  572. # This file was auto-generated by salt's setup
  573. from salt.version import SaltStackVersion
  574. __saltstack_version__ = SaltStackVersion{full_version_info!r}
  575. '''
  576. INSTALL_SYSPATHS_TEMPLATE = '''\
  577. # This file was auto-generated by salt's setup on \
  578. {date:%A, %d %B %Y @ %H:%m:%S UTC}.
  579. ROOT_DIR = {root_dir!r}
  580. SHARE_DIR = {share_dir!r}
  581. CONFIG_DIR = {config_dir!r}
  582. CACHE_DIR = {cache_dir!r}
  583. SOCK_DIR = {sock_dir!r}
  584. SRV_ROOT_DIR= {srv_root_dir!r}
  585. BASE_FILE_ROOTS_DIR = {base_file_roots_dir!r}
  586. BASE_PILLAR_ROOTS_DIR = {base_pillar_roots_dir!r}
  587. BASE_MASTER_ROOTS_DIR = {base_master_roots_dir!r}
  588. BASE_THORIUM_ROOTS_DIR = {base_thorium_roots_dir!r}
  589. LOGS_DIR = {logs_dir!r}
  590. PIDFILE_DIR = {pidfile_dir!r}
  591. SPM_PARENT_PATH = {spm_parent_path!r}
  592. SPM_FORMULA_PATH = {spm_formula_path!r}
  593. SPM_PILLAR_PATH = {spm_pillar_path!r}
  594. SPM_REACTOR_PATH = {spm_reactor_path!r}
  595. HOME_DIR = {home_dir!r}
  596. '''
  597. class Build(build):
  598. def run(self):
  599. # Run build.run function
  600. build.run(self)
  601. if getattr(self.distribution, 'with_salt_version', False):
  602. # Write the hardcoded salt version module salt/_version.py
  603. self.distribution.salt_version_hardcoded_path = os.path.join(
  604. self.build_lib, 'salt', '_version.py'
  605. )
  606. self.run_command('write_salt_version')
  607. if getattr(self.distribution, 'running_salt_install', False):
  608. # If our install attribute is present and set to True, we'll go
  609. # ahead and write our install time python modules.
  610. # Write the hardcoded salt version module salt/_version.py
  611. self.run_command('write_salt_version')
  612. # Write the system paths file
  613. self.distribution.salt_syspaths_hardcoded_path = os.path.join(
  614. self.build_lib, 'salt', '_syspaths.py'
  615. )
  616. self.run_command('generate_salt_syspaths')
  617. class Install(install):
  618. def initialize_options(self):
  619. install.initialize_options(self)
  620. def finalize_options(self):
  621. install.finalize_options(self)
  622. def run(self):
  623. # Let's set the running_salt_install attribute so we can add
  624. # _version.py in the build command
  625. self.distribution.running_salt_install = True
  626. self.distribution.salt_version_hardcoded_path = os.path.join(
  627. self.build_lib, 'salt', '_version.py'
  628. )
  629. if IS_WINDOWS_PLATFORM:
  630. # Download the required DLLs
  631. self.distribution.salt_download_windows_dlls = True
  632. self.run_command('download-windows-dlls')
  633. self.distribution.salt_download_windows_dlls = None
  634. # Run install.run
  635. install.run(self)
  636. class InstallLib(install_lib):
  637. def run(self):
  638. executables = [
  639. 'salt/templates/git/ssh-id-wrapper',
  640. 'salt/templates/lxc/salt_tarball',
  641. ]
  642. install_lib.run(self)
  643. # input and outputs match 1-1
  644. inp = self.get_inputs()
  645. out = self.get_outputs()
  646. chmod = []
  647. for idx, inputfile in enumerate(inp):
  648. for executable in executables:
  649. if inputfile.endswith(executable):
  650. chmod.append(idx)
  651. for idx in chmod:
  652. filename = out[idx]
  653. os.chmod(filename, 0o755)
  654. # <---- Custom Distutils/Setuptools Commands -------------------------------------------------------------------------
  655. # ----- Custom Distribution Class ----------------------------------------------------------------------------------->
  656. # We use this to override the package name in case --ssh-packaging is passed to
  657. # setup.py or the special .salt-ssh-package is found
  658. class SaltDistribution(distutils.dist.Distribution):
  659. '''
  660. Just so it's completely clear
  661. Under windows, the following scripts should be installed:
  662. * salt-call
  663. * salt-cp
  664. * salt-minion
  665. * salt-syndic
  666. * salt-unity
  667. * spm
  668. When packaged for salt-ssh, the following scripts should be installed:
  669. * salt-call
  670. * salt-run
  671. * salt-ssh
  672. * salt-cloud
  673. Under windows, the following scripts should be omitted from the salt-ssh
  674. package:
  675. * salt-cloud
  676. * salt-run
  677. Under *nix, all scripts should be installed
  678. '''
  679. global_options = distutils.dist.Distribution.global_options + [
  680. ('ssh-packaging', None, 'Run in SSH packaging mode'),
  681. ('salt-transport=', None, 'The transport to prepare salt for. Choices are \'zeromq\' '
  682. '\'raet\' or \'both\'. Defaults to \'zeromq\'', 'zeromq')] + [
  683. ('with-salt-version=', None, 'Set a fixed version for Salt instead calculating it'),
  684. # Salt's Paths Configuration Settings
  685. ('salt-root-dir=', None,
  686. 'Salt\'s pre-configured root directory'),
  687. ('salt-share-dir=', None,
  688. 'Salt\'s pre-configured share directory'),
  689. ('salt-config-dir=', None,
  690. 'Salt\'s pre-configured configuration directory'),
  691. ('salt-cache-dir=', None,
  692. 'Salt\'s pre-configured cache directory'),
  693. ('salt-sock-dir=', None,
  694. 'Salt\'s pre-configured socket directory'),
  695. ('salt-srv-root-dir=', None,
  696. 'Salt\'s pre-configured service directory'),
  697. ('salt-base-file-roots-dir=', None,
  698. 'Salt\'s pre-configured file roots directory'),
  699. ('salt-base-pillar-roots-dir=', None,
  700. 'Salt\'s pre-configured pillar roots directory'),
  701. ('salt-base-master-roots-dir=', None,
  702. 'Salt\'s pre-configured master roots directory'),
  703. ('salt-logs-dir=', None,
  704. 'Salt\'s pre-configured logs directory'),
  705. ('salt-pidfile-dir=', None,
  706. 'Salt\'s pre-configured pidfiles directory'),
  707. ('salt-spm-formula-dir=', None,
  708. 'Salt\'s pre-configured SPM formulas directory'),
  709. ('salt-spm-pillar-dir=', None,
  710. 'Salt\'s pre-configured SPM pillar directory'),
  711. ('salt-spm-reactor-dir=', None,
  712. 'Salt\'s pre-configured SPM reactor directory'),
  713. ('salt-home-dir=', None,
  714. 'Salt\'s pre-configured user home directory'),
  715. ]
  716. def __init__(self, attrs=None):
  717. distutils.dist.Distribution.__init__(self, attrs)
  718. self.ssh_packaging = PACKAGED_FOR_SALT_SSH
  719. self.salt_transport = None
  720. # Salt Paths Configuration Settings
  721. self.salt_root_dir = None
  722. self.salt_share_dir = None
  723. self.salt_config_dir = None
  724. self.salt_cache_dir = None
  725. self.salt_sock_dir = None
  726. self.salt_srv_root_dir = None
  727. self.salt_base_file_roots_dir = None
  728. self.salt_base_thorium_roots_dir = None
  729. self.salt_base_pillar_roots_dir = None
  730. self.salt_base_master_roots_dir = None
  731. self.salt_logs_dir = None
  732. self.salt_pidfile_dir = None
  733. self.salt_spm_parent_dir = None
  734. self.salt_spm_formula_dir = None
  735. self.salt_spm_pillar_dir = None
  736. self.salt_spm_reactor_dir = None
  737. self.salt_home_dir = None
  738. # Salt version
  739. self.with_salt_version = None
  740. self.name = 'salt-ssh' if PACKAGED_FOR_SALT_SSH else 'salt'
  741. self.salt_version = __version__ # pylint: disable=undefined-variable
  742. self.description = 'Portable, distributed, remote execution and configuration management system'
  743. kwargs = {}
  744. if IS_PY3:
  745. kwargs['encoding'] = 'utf-8'
  746. with open(SALT_LONG_DESCRIPTION_FILE, **kwargs) as f:
  747. self.long_description = f.read()
  748. self.long_description_content_type = 'text/x-rst'
  749. self.author = 'Thomas S Hatch'
  750. self.author_email = 'thatch45@gmail.com'
  751. self.url = 'http://saltstack.org'
  752. self.cmdclass.update({'test': TestCommand,
  753. 'clean': Clean,
  754. 'build': Build,
  755. 'sdist': Sdist,
  756. 'install': Install,
  757. 'write_salt_version': WriteSaltVersion,
  758. 'generate_salt_syspaths': GenerateSaltSyspaths,
  759. 'write_salt_ssh_packaging_file': WriteSaltSshPackagingFile})
  760. if not IS_WINDOWS_PLATFORM:
  761. self.cmdclass.update({'sdist': CloudSdist,
  762. 'install_lib': InstallLib})
  763. if IS_WINDOWS_PLATFORM:
  764. self.cmdclass.update({'download-windows-dlls': DownloadWindowsDlls})
  765. if WITH_SETUPTOOLS:
  766. self.cmdclass.update({'develop': Develop})
  767. self.license = 'Apache Software License 2.0'
  768. self.packages = self.discover_packages()
  769. self.zip_safe = False
  770. if HAS_ESKY:
  771. self.setup_esky()
  772. self.update_metadata()
  773. def update_metadata(self):
  774. for attrname in dir(self):
  775. if attrname.startswith('__'):
  776. continue
  777. attrvalue = getattr(self, attrname, None)
  778. if attrvalue == 0:
  779. continue
  780. if attrname == 'salt_version':
  781. attrname = 'version'
  782. if hasattr(self.metadata, 'set_{0}'.format(attrname)):
  783. getattr(self.metadata, 'set_{0}'.format(attrname))(attrvalue)
  784. elif hasattr(self.metadata, attrname):
  785. try:
  786. setattr(self.metadata, attrname, attrvalue)
  787. except AttributeError:
  788. pass
  789. def discover_packages(self):
  790. modules = []
  791. for root, _, files in os.walk(os.path.join(SETUP_DIRNAME, 'salt')):
  792. if '__init__.py' not in files:
  793. continue
  794. modules.append(os.path.relpath(root, SETUP_DIRNAME).replace(os.sep, '.'))
  795. return modules
  796. # ----- Static Data -------------------------------------------------------------------------------------------->
  797. @property
  798. def _property_classifiers(self):
  799. return ['Programming Language :: Python',
  800. 'Programming Language :: Cython',
  801. 'Programming Language :: Python :: 2.6',
  802. 'Programming Language :: Python :: 2.7',
  803. 'Development Status :: 5 - Production/Stable',
  804. 'Environment :: Console',
  805. 'Intended Audience :: Developers',
  806. 'Intended Audience :: Information Technology',
  807. 'Intended Audience :: System Administrators',
  808. 'License :: OSI Approved :: Apache Software License',
  809. 'Operating System :: POSIX :: Linux',
  810. 'Topic :: System :: Clustering',
  811. 'Topic :: System :: Distributed Computing']
  812. @property
  813. def _property_dependency_links(self):
  814. return ['https://github.com/saltstack/salt-testing/tarball/develop#egg=SaltTesting']
  815. @property
  816. def _property_tests_require(self):
  817. return ['SaltTesting']
  818. # <---- Static Data ----------------------------------------------------------------------------------------------
  819. # ----- Dynamic Data -------------------------------------------------------------------------------------------->
  820. @property
  821. def _property_package_data(self):
  822. package_data = {'salt.templates': ['rh_ip/*.jinja',
  823. 'debian_ip/*.jinja',
  824. 'virt/*.jinja',
  825. 'git/*',
  826. 'lxc/*',
  827. ]}
  828. if not IS_WINDOWS_PLATFORM:
  829. package_data['salt.cloud'] = ['deploy/*.sh']
  830. if not self.ssh_packaging and not PACKAGED_FOR_SALT_SSH:
  831. package_data['salt.daemons.flo'] = ['*.flo']
  832. return package_data
  833. @property
  834. def _property_data_files(self):
  835. # Data files common to all scenarios
  836. data_files = [
  837. ('share/man/man1', ['doc/man/salt-call.1', 'doc/man/salt-run.1']),
  838. ('share/man/man7', ['doc/man/salt.7'])
  839. ]
  840. if self.ssh_packaging or PACKAGED_FOR_SALT_SSH:
  841. data_files[0][1].append('doc/man/salt-ssh.1')
  842. if IS_WINDOWS_PLATFORM:
  843. return data_files
  844. data_files[0][1].append('doc/man/salt-cloud.1')
  845. return data_files
  846. if IS_WINDOWS_PLATFORM:
  847. data_files[0][1].extend(['doc/man/salt-cp.1',
  848. 'doc/man/salt-key.1',
  849. 'doc/man/salt-minion.1',
  850. 'doc/man/salt-syndic.1',
  851. 'doc/man/salt-unity.1',
  852. 'doc/man/spm.1'])
  853. return data_files
  854. # *nix, so, we need all man pages
  855. data_files[0][1].extend(['doc/man/salt-api.1',
  856. 'doc/man/salt-cloud.1',
  857. 'doc/man/salt-cp.1',
  858. 'doc/man/salt-key.1',
  859. 'doc/man/salt-master.1',
  860. 'doc/man/salt-minion.1',
  861. 'doc/man/salt-proxy.1',
  862. 'doc/man/spm.1',
  863. 'doc/man/salt.1',
  864. 'doc/man/salt-ssh.1',
  865. 'doc/man/salt-syndic.1',
  866. 'doc/man/salt-unity.1'])
  867. return data_files
  868. @property
  869. def _property_install_requires(self):
  870. install_requires = _parse_requirements_file(SALT_REQS)
  871. if self.salt_transport == 'zeromq':
  872. install_requires += _parse_requirements_file(SALT_ZEROMQ_REQS)
  873. elif self.salt_transport == 'raet':
  874. install_requires += _parse_requirements_file(SALT_RAET_REQS)
  875. if IS_WINDOWS_PLATFORM:
  876. install_requires = _parse_requirements_file(SALT_WINDOWS_REQS)
  877. return install_requires
  878. @property
  879. def _property_extras_require(self):
  880. if self.ssh_packaging:
  881. return {}
  882. return {'RAET': _parse_requirements_file(SALT_RAET_REQS)}
  883. @property
  884. def _property_scripts(self):
  885. # Scripts common to all scenarios
  886. scripts = ['scripts/salt-call', 'scripts/salt-run']
  887. if self.ssh_packaging or PACKAGED_FOR_SALT_SSH:
  888. scripts.append('scripts/salt-ssh')
  889. if IS_WINDOWS_PLATFORM:
  890. return scripts
  891. scripts.extend(['scripts/salt-cloud', 'scripts/spm'])
  892. return scripts
  893. if IS_WINDOWS_PLATFORM:
  894. scripts.extend(['scripts/salt-cp',
  895. 'scripts/salt-key',
  896. 'scripts/salt-minion',
  897. 'scripts/salt-syndic',
  898. 'scripts/salt-unity',
  899. 'scripts/spm'])
  900. return scripts
  901. # *nix, so, we need all scripts
  902. scripts.extend(['scripts/salt',
  903. 'scripts/salt-api',
  904. 'scripts/salt-cloud',
  905. 'scripts/salt-cp',
  906. 'scripts/salt-key',
  907. 'scripts/salt-master',
  908. 'scripts/salt-minion',
  909. 'scripts/salt-proxy',
  910. 'scripts/salt-ssh',
  911. 'scripts/salt-syndic',
  912. 'scripts/salt-unity',
  913. 'scripts/spm'])
  914. return scripts
  915. @property
  916. def _property_entry_points(self):
  917. # console scripts common to all scenarios
  918. scripts = ['salt-call = salt.scripts:salt_call',
  919. 'salt-run = salt.scripts:salt_run']
  920. if self.ssh_packaging or PACKAGED_FOR_SALT_SSH:
  921. scripts.append('salt-ssh = salt.scripts:salt_ssh')
  922. if IS_WINDOWS_PLATFORM:
  923. return {'console_scripts': scripts}
  924. scripts.append('salt-cloud = salt.scripts:salt_cloud')
  925. return {'console_scripts': scripts}
  926. if IS_WINDOWS_PLATFORM:
  927. scripts.extend(['salt-cp = salt.scripts:salt_cp',
  928. 'salt-key = salt.scripts:salt_key',
  929. 'salt-minion = salt.scripts:salt_minion',
  930. 'salt-syndic = salt.scripts:salt_syndic',
  931. 'salt-unity = salt.scripts:salt_unity',
  932. 'spm = salt.scripts:salt_spm'])
  933. return {'console_scripts': scripts}
  934. # *nix, so, we need all scripts
  935. scripts.extend(['salt = salt.scripts:salt_main',
  936. 'salt-api = salt.scripts:salt_api',
  937. 'salt-cloud = salt.scripts:salt_cloud',
  938. 'salt-cp = salt.scripts:salt_cp',
  939. 'salt-key = salt.scripts:salt_key',
  940. 'salt-master = salt.scripts:salt_master',
  941. 'salt-minion = salt.scripts:salt_minion',
  942. 'salt-ssh = salt.scripts:salt_ssh',
  943. 'salt-syndic = salt.scripts:salt_syndic',
  944. 'salt-unity = salt.scripts:salt_unity',
  945. 'spm = salt.scripts:salt_spm'])
  946. return {'console_scripts': scripts}
  947. # <---- Dynamic Data ---------------------------------------------------------------------------------------------
  948. # ----- Esky Setup ---------------------------------------------------------------------------------------------->
  949. def setup_esky(self):
  950. opt_dict = self.get_option_dict('bdist_esky')
  951. opt_dict['freezer_module'] = ('setup script', 'bbfreeze')
  952. opt_dict['freezer_options'] = ('setup script', {'includes': self.get_esky_freezer_includes()})
  953. @property
  954. def _property_freezer_options(self):
  955. return {'includes': self.get_esky_freezer_includes()}
  956. def get_esky_freezer_includes(self):
  957. # Sometimes the auto module traversal doesn't find everything, so we
  958. # explicitly add it. The auto dependency tracking especially does not work for
  959. # imports occurring in salt.modules, as they are loaded at salt runtime.
  960. # Specifying includes that don't exist doesn't appear to cause a freezing
  961. # error.
  962. freezer_includes = [
  963. 'zmq.core.*',
  964. 'zmq.utils.*',
  965. 'ast',
  966. 'csv',
  967. 'difflib',
  968. 'distutils',
  969. 'distutils.version',
  970. 'numbers',
  971. 'json',
  972. 'M2Crypto',
  973. 'Cookie',
  974. 'asyncore',
  975. 'fileinput',
  976. 'sqlite3',
  977. 'email',
  978. 'email.mime.*',
  979. 'requests',
  980. 'sqlite3',
  981. ]
  982. if HAS_ZMQ and hasattr(zmq, 'pyzmq_version_info'):
  983. if HAS_ZMQ and zmq.pyzmq_version_info() >= (0, 14):
  984. # We're freezing, and when freezing ZMQ needs to be installed, so this
  985. # works fine
  986. if 'zmq.core.*' in freezer_includes:
  987. # For PyZMQ >= 0.14, freezing does not need 'zmq.core.*'
  988. freezer_includes.remove('zmq.core.*')
  989. if IS_WINDOWS_PLATFORM:
  990. freezer_includes.extend([
  991. 'imp',
  992. 'win32api',
  993. 'win32file',
  994. 'win32con',
  995. 'win32com',
  996. 'win32net',
  997. 'win32netcon',
  998. 'win32gui',
  999. 'win32security',
  1000. 'ntsecuritycon',
  1001. 'pywintypes',
  1002. 'pythoncom',
  1003. '_winreg',
  1004. 'wmi',
  1005. 'site',
  1006. 'psutil',
  1007. 'pytz',
  1008. ])
  1009. elif IS_SMARTOS_PLATFORM:
  1010. # we have them as requirements in pkg/smartos/esky/requirements.txt
  1011. # all these should be safe to force include
  1012. freezer_includes.extend([
  1013. 'cherrypy',
  1014. 'python-dateutil',
  1015. 'pyghmi',
  1016. 'croniter',
  1017. 'mako',
  1018. 'gnupg',
  1019. ])
  1020. elif sys.platform.startswith('linux'):
  1021. freezer_includes.append('spwd')
  1022. try:
  1023. import yum # pylint: disable=unused-variable
  1024. freezer_includes.append('yum')
  1025. except ImportError:
  1026. pass
  1027. elif sys.platform.startswith('sunos'):
  1028. # (The sledgehammer approach)
  1029. # Just try to include everything
  1030. # (This may be a better way to generate freezer_includes generally)
  1031. try:
  1032. from bbfreeze.modulegraph.modulegraph import ModuleGraph
  1033. mgraph = ModuleGraph(sys.path[:])
  1034. for arg in glob.glob('salt/modules/*.py'):
  1035. mgraph.run_script(arg)
  1036. for mod in mgraph.flatten():
  1037. if type(mod).__name__ != 'Script' and mod.filename:
  1038. freezer_includes.append(str(os.path.basename(mod.identifier)))
  1039. except ImportError:
  1040. pass
  1041. # Include C extension that convinces esky to package up the libsodium C library
  1042. # This is needed for ctypes to find it in libnacl which is in turn needed for raet
  1043. # see pkg/smartos/esky/sodium_grabber{.c,_installer.py}
  1044. freezer_includes.extend([
  1045. 'sodium_grabber',
  1046. 'ioflo',
  1047. 'raet',
  1048. 'libnacl',
  1049. ])
  1050. return freezer_includes
  1051. # <---- Esky Setup -----------------------------------------------------------------------------------------------
  1052. # ----- Overridden Methods -------------------------------------------------------------------------------------->
  1053. def parse_command_line(self):
  1054. args = distutils.dist.Distribution.parse_command_line(self)
  1055. if not self.ssh_packaging and PACKAGED_FOR_SALT_SSH:
  1056. self.ssh_packaging = 1
  1057. if self.ssh_packaging:
  1058. self.metadata.name = 'salt-ssh'
  1059. self.salt_transport = 'ssh'
  1060. elif self.salt_transport is None:
  1061. self.salt_transport = 'zeromq'
  1062. if self.salt_transport not in ('zeromq', 'raet', 'both', 'ssh', 'none'):
  1063. raise DistutilsArgError(
  1064. 'The value of --salt-transport needs be \'zeromq\', '
  1065. '\'raet\', \'both\', \'ssh\' or \'none\' not \'{0}\''.format(
  1066. self.salt_transport
  1067. )
  1068. )
  1069. # Setup our property functions after class initialization and
  1070. # after parsing the command line since most are set to None
  1071. # ATTENTION: This should be the last step before returning the args or
  1072. # some of the requirements won't be correctly set
  1073. for funcname in dir(self):
  1074. if not funcname.startswith('_property_'):
  1075. continue
  1076. property_name = funcname.split('_property_', 1)[-1]
  1077. setattr(self, property_name, getattr(self, funcname))
  1078. return args
  1079. # <---- Overridden Methods ---------------------------------------------------------------------------------------
  1080. # <---- Custom Distribution Class ------------------------------------------------------------------------------------
  1081. if __name__ == '__main__':
  1082. setup(distclass=SaltDistribution)