1
0

setup.py 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  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 :: 2.6",
  917. "Programming Language :: Python :: 2.7",
  918. "Development Status :: 5 - Production/Stable",
  919. "Environment :: Console",
  920. "Intended Audience :: Developers",
  921. "Intended Audience :: Information Technology",
  922. "Intended Audience :: System Administrators",
  923. "License :: OSI Approved :: Apache Software License",
  924. "Operating System :: POSIX :: Linux",
  925. "Topic :: System :: Clustering",
  926. "Topic :: System :: Distributed Computing",
  927. ]
  928. @property
  929. def _property_dependency_links(self):
  930. return [
  931. "https://github.com/saltstack/salt-testing/tarball/develop#egg=SaltTesting"
  932. ]
  933. @property
  934. def _property_tests_require(self):
  935. return ["SaltTesting"]
  936. # <---- Static Data ----------------------------------------------------------------------------------------------
  937. # ----- Dynamic Data -------------------------------------------------------------------------------------------->
  938. @property
  939. def _property_package_data(self):
  940. package_data = {
  941. "salt.templates": [
  942. "rh_ip/*.jinja",
  943. "debian_ip/*.jinja",
  944. "virt/*.jinja",
  945. "git/*",
  946. "lxc/*",
  947. ]
  948. }
  949. if not IS_WINDOWS_PLATFORM:
  950. package_data["salt.cloud"] = ["deploy/*.sh"]
  951. if not self.ssh_packaging and not PACKAGED_FOR_SALT_SSH:
  952. package_data["salt.daemons.flo"] = ["*.flo"]
  953. return package_data
  954. @property
  955. def _property_data_files(self):
  956. # Data files common to all scenarios
  957. data_files = [
  958. ("share/man/man1", ["doc/man/salt-call.1", "doc/man/salt-run.1"]),
  959. ("share/man/man7", ["doc/man/salt.7"]),
  960. ]
  961. if self.ssh_packaging or PACKAGED_FOR_SALT_SSH:
  962. data_files[0][1].append("doc/man/salt-ssh.1")
  963. if IS_WINDOWS_PLATFORM:
  964. return data_files
  965. data_files[0][1].append("doc/man/salt-cloud.1")
  966. return data_files
  967. if IS_WINDOWS_PLATFORM:
  968. data_files[0][1].extend(
  969. [
  970. "doc/man/salt-cp.1",
  971. "doc/man/salt-key.1",
  972. "doc/man/salt-minion.1",
  973. "doc/man/salt-syndic.1",
  974. "doc/man/salt-unity.1",
  975. "doc/man/spm.1",
  976. ]
  977. )
  978. return data_files
  979. # *nix, so, we need all man pages
  980. data_files[0][1].extend(
  981. [
  982. "doc/man/salt-api.1",
  983. "doc/man/salt-cloud.1",
  984. "doc/man/salt-cp.1",
  985. "doc/man/salt-key.1",
  986. "doc/man/salt-master.1",
  987. "doc/man/salt-minion.1",
  988. "doc/man/salt-proxy.1",
  989. "doc/man/spm.1",
  990. "doc/man/salt.1",
  991. "doc/man/salt-ssh.1",
  992. "doc/man/salt-syndic.1",
  993. "doc/man/salt-unity.1",
  994. ]
  995. )
  996. return data_files
  997. @property
  998. def _property_install_requires(self):
  999. if IS_OSX_PLATFORM:
  1000. install_requires = []
  1001. for reqfile in SALT_OSX_REQS:
  1002. install_requires += _parse_requirements_file(reqfile)
  1003. return install_requires
  1004. if IS_WINDOWS_PLATFORM:
  1005. install_requires = []
  1006. for reqfile in SALT_WINDOWS_REQS:
  1007. install_requires += _parse_requirements_file(reqfile)
  1008. return install_requires
  1009. install_requires = _parse_requirements_file(SALT_REQS)
  1010. if self.salt_transport == "zeromq":
  1011. install_requires += _parse_requirements_file(SALT_CRYPTO_REQS)
  1012. install_requires += _parse_requirements_file(SALT_ZEROMQ_REQS)
  1013. return install_requires
  1014. @property
  1015. def _property_scripts(self):
  1016. # Scripts common to all scenarios
  1017. scripts = ["scripts/salt-call", "scripts/salt-run"]
  1018. if self.ssh_packaging or PACKAGED_FOR_SALT_SSH:
  1019. scripts.append("scripts/salt-ssh")
  1020. if IS_WINDOWS_PLATFORM:
  1021. return scripts
  1022. scripts.extend(["scripts/salt-cloud", "scripts/spm"])
  1023. return scripts
  1024. if IS_WINDOWS_PLATFORM:
  1025. scripts.extend(
  1026. [
  1027. "scripts/salt-cp",
  1028. "scripts/salt-key",
  1029. "scripts/salt-minion",
  1030. "scripts/salt-syndic",
  1031. "scripts/salt-unity",
  1032. "scripts/spm",
  1033. ]
  1034. )
  1035. return scripts
  1036. # *nix, so, we need all scripts
  1037. scripts.extend(
  1038. [
  1039. "scripts/salt",
  1040. "scripts/salt-api",
  1041. "scripts/salt-cloud",
  1042. "scripts/salt-cp",
  1043. "scripts/salt-key",
  1044. "scripts/salt-master",
  1045. "scripts/salt-minion",
  1046. "scripts/salt-proxy",
  1047. "scripts/salt-ssh",
  1048. "scripts/salt-syndic",
  1049. "scripts/salt-unity",
  1050. "scripts/spm",
  1051. ]
  1052. )
  1053. return scripts
  1054. @property
  1055. def _property_entry_points(self):
  1056. # console scripts common to all scenarios
  1057. scripts = [
  1058. "salt-call = salt.scripts:salt_call",
  1059. "salt-run = salt.scripts:salt_run",
  1060. ]
  1061. if self.ssh_packaging or PACKAGED_FOR_SALT_SSH:
  1062. scripts.append("salt-ssh = salt.scripts:salt_ssh")
  1063. if IS_WINDOWS_PLATFORM:
  1064. return {"console_scripts": scripts}
  1065. scripts.append("salt-cloud = salt.scripts:salt_cloud")
  1066. return {"console_scripts": scripts}
  1067. if IS_WINDOWS_PLATFORM:
  1068. scripts.extend(
  1069. [
  1070. "salt-cp = salt.scripts:salt_cp",
  1071. "salt-key = salt.scripts:salt_key",
  1072. "salt-minion = salt.scripts:salt_minion",
  1073. "salt-syndic = salt.scripts:salt_syndic",
  1074. "salt-unity = salt.scripts:salt_unity",
  1075. "spm = salt.scripts:salt_spm",
  1076. ]
  1077. )
  1078. return {"console_scripts": scripts}
  1079. # *nix, so, we need all scripts
  1080. scripts.extend(
  1081. [
  1082. "salt = salt.scripts:salt_main",
  1083. "salt-api = salt.scripts:salt_api",
  1084. "salt-cloud = salt.scripts:salt_cloud",
  1085. "salt-cp = salt.scripts:salt_cp",
  1086. "salt-key = salt.scripts:salt_key",
  1087. "salt-master = salt.scripts:salt_master",
  1088. "salt-minion = salt.scripts:salt_minion",
  1089. "salt-ssh = salt.scripts:salt_ssh",
  1090. "salt-syndic = salt.scripts:salt_syndic",
  1091. "salt-unity = salt.scripts:salt_unity",
  1092. "spm = salt.scripts:salt_spm",
  1093. ]
  1094. )
  1095. return {"console_scripts": scripts}
  1096. # <---- Dynamic Data ---------------------------------------------------------------------------------------------
  1097. # ----- Esky Setup ---------------------------------------------------------------------------------------------->
  1098. def setup_esky(self):
  1099. opt_dict = self.get_option_dict("bdist_esky")
  1100. opt_dict["freezer_module"] = ("setup script", "bbfreeze")
  1101. opt_dict["freezer_options"] = (
  1102. "setup script",
  1103. {"includes": self.get_esky_freezer_includes()},
  1104. )
  1105. @property
  1106. def _property_freezer_options(self):
  1107. return {"includes": self.get_esky_freezer_includes()}
  1108. def get_esky_freezer_includes(self):
  1109. # Sometimes the auto module traversal doesn't find everything, so we
  1110. # explicitly add it. The auto dependency tracking especially does not work for
  1111. # imports occurring in salt.modules, as they are loaded at salt runtime.
  1112. # Specifying includes that don't exist doesn't appear to cause a freezing
  1113. # error.
  1114. freezer_includes = [
  1115. "zmq.core.*",
  1116. "zmq.utils.*",
  1117. "ast",
  1118. "csv",
  1119. "difflib",
  1120. "distutils",
  1121. "distutils.version",
  1122. "numbers",
  1123. "json",
  1124. "M2Crypto",
  1125. "Cookie",
  1126. "asyncore",
  1127. "fileinput",
  1128. "sqlite3",
  1129. "email",
  1130. "email.mime.*",
  1131. "requests",
  1132. "sqlite3",
  1133. ]
  1134. if HAS_ZMQ and hasattr(zmq, "pyzmq_version_info"):
  1135. if HAS_ZMQ and zmq.pyzmq_version_info() >= (0, 14):
  1136. # We're freezing, and when freezing ZMQ needs to be installed, so this
  1137. # works fine
  1138. if "zmq.core.*" in freezer_includes:
  1139. # For PyZMQ >= 0.14, freezing does not need 'zmq.core.*'
  1140. freezer_includes.remove("zmq.core.*")
  1141. if IS_WINDOWS_PLATFORM:
  1142. freezer_includes.extend(
  1143. [
  1144. "imp",
  1145. "win32api",
  1146. "win32file",
  1147. "win32con",
  1148. "win32com",
  1149. "win32net",
  1150. "win32netcon",
  1151. "win32gui",
  1152. "win32security",
  1153. "ntsecuritycon",
  1154. "pywintypes",
  1155. "pythoncom",
  1156. "_winreg",
  1157. "wmi",
  1158. "site",
  1159. "psutil",
  1160. "pytz",
  1161. ]
  1162. )
  1163. elif IS_SMARTOS_PLATFORM:
  1164. # we have them as requirements in pkg/smartos/esky/requirements.txt
  1165. # all these should be safe to force include
  1166. freezer_includes.extend(
  1167. ["cherrypy", "python-dateutil", "pyghmi", "croniter", "mako", "gnupg"]
  1168. )
  1169. elif sys.platform.startswith("linux"):
  1170. freezer_includes.append("spwd")
  1171. try:
  1172. import yum # pylint: disable=unused-variable
  1173. freezer_includes.append("yum")
  1174. except ImportError:
  1175. pass
  1176. elif sys.platform.startswith("sunos"):
  1177. # (The sledgehammer approach)
  1178. # Just try to include everything
  1179. # (This may be a better way to generate freezer_includes generally)
  1180. try:
  1181. from bbfreeze.modulegraph.modulegraph import ModuleGraph
  1182. mgraph = ModuleGraph(sys.path[:])
  1183. for arg in glob.glob("salt/modules/*.py"):
  1184. mgraph.run_script(arg)
  1185. for mod in mgraph.flatten():
  1186. if type(mod).__name__ != "Script" and mod.filename:
  1187. freezer_includes.append(str(os.path.basename(mod.identifier)))
  1188. except ImportError:
  1189. pass
  1190. return freezer_includes
  1191. # <---- Esky Setup -----------------------------------------------------------------------------------------------
  1192. # ----- Overridden Methods -------------------------------------------------------------------------------------->
  1193. def parse_command_line(self):
  1194. args = distutils.dist.Distribution.parse_command_line(self)
  1195. if not self.ssh_packaging and PACKAGED_FOR_SALT_SSH:
  1196. self.ssh_packaging = 1
  1197. if self.ssh_packaging:
  1198. self.metadata.name = "salt-ssh"
  1199. self.salt_transport = "ssh"
  1200. elif self.salt_transport is None:
  1201. self.salt_transport = "zeromq"
  1202. if self.salt_transport not in ("zeromq", "both", "ssh", "none"):
  1203. raise DistutilsArgError(
  1204. "The value of --salt-transport needs be 'zeromq', "
  1205. "'both', 'ssh', or 'none' not '{0}'".format(self.salt_transport)
  1206. )
  1207. # Setup our property functions after class initialization and
  1208. # after parsing the command line since most are set to None
  1209. # ATTENTION: This should be the last step before returning the args or
  1210. # some of the requirements won't be correctly set
  1211. for funcname in dir(self):
  1212. if not funcname.startswith("_property_"):
  1213. continue
  1214. property_name = funcname.split("_property_", 1)[-1]
  1215. setattr(self, property_name, getattr(self, funcname))
  1216. return args
  1217. # <---- Overridden Methods ---------------------------------------------------------------------------------------
  1218. # <---- Custom Distribution Class ------------------------------------------------------------------------------------
  1219. if __name__ == "__main__":
  1220. setup(distclass=SaltDistribution)