setup.py 50 KB

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