setup.py 51 KB

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