setup.py 50 KB

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