setup.py 49 KB

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