setup.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #!/usr/bin/env python3
  2. #
  3. # Awlsim setup.py Python build script.
  4. #
  5. # These environment variables affect the setup.py build:
  6. #
  7. # AWLSIM_FULL_BUILD:
  8. # 0 (default): Do not include scripts that are not necessary on this platform.
  9. # 1: Include all scripts; also those that aren't required on the platform.
  10. #
  11. # AWLSIM_CYTHON_BUILD:
  12. # 0: Do not build any Cython modules.
  13. # 1: Build Cython modules.
  14. # 2: Build Cython modules only, if setup.py is being executed by Python 2.
  15. # 3 (default): Build Cython modules only, if setup.py is being executed by Python 3.
  16. #
  17. # AWLSIM_CYTHON_PARALLEL:
  18. # 0: Do not use parallel compilation for Cython modules.
  19. # 1 (default): Invoke multiple compilers in parallel (faster on multicore).
  20. # 2: Invole multiple compilers only, if setup.py is being executed by Python 2.
  21. # 3: Invole multiple compilers only, if setup.py is being executed by Python 3.
  22. #
  23. # AWLSIM_PROFILE:
  24. # 0 (default): Do not enable profiling support in compiled Cython modules.
  25. # 1: Enable profiling support in compiled Cython modules.
  26. #
  27. from __future__ import print_function
  28. import sys
  29. import os
  30. import re
  31. import warnings
  32. from distutils.core import setup
  33. from awlsim.common.version import VERSION_STRING
  34. try:
  35. import py2exe
  36. except ImportError as e:
  37. py2exe = None
  38. try:
  39. if py2exe and "py2exe" in sys.argv:
  40. raise ImportError
  41. from cx_Freeze import setup, Executable
  42. cx_Freeze = True
  43. except ImportError as e:
  44. cx_Freeze = False
  45. sys.path.insert(0, "./misc")
  46. import setup_cython
  47. basedir = os.path.abspath(os.path.dirname(__file__))
  48. isWindows = os.name.lower() in {"nt", "ce"}
  49. def getEnvInt(name, default = 0):
  50. try:
  51. return int(os.getenv(name, "%d" % default))
  52. except ValueError:
  53. return default
  54. def getEnvBool(name, default = False):
  55. return bool(getEnvInt(name, 1 if default else 0))
  56. fullBuild = getEnvBool("AWLSIM_FULL_BUILD")
  57. buildCython = getEnvInt("AWLSIM_CYTHON_BUILD", 3)
  58. buildCython = ((buildCython == 1) or (buildCython == sys.version_info[0]))
  59. setup_cython.parallelBuild = bool(getEnvInt("AWLSIM_CYTHON_PARALLEL", 1) == 1 or\
  60. getEnvInt("AWLSIM_CYTHON_PARALLEL", 1) == sys.version_info[0])
  61. setup_cython.profileEnabled = bool(getEnvInt("AWLSIM_PROFILE") > 0)
  62. def pyCythonPatchLine(line):
  63. # Patch the import statements
  64. line = re.sub(r'^(\s*from awlsim[0-9a-zA-Z_]*)\.([0-9a-zA-Z_\.]+) import', r'\1_cython.\2 import', line)
  65. line = re.sub(r'^(\s*from awlsim[0-9a-zA-Z_]*)\.([0-9a-zA-Z_\.]+) cimport', r'\1_cython.\2 cimport', line)
  66. line = re.sub(r'^(\s*import awlsim[0-9a-zA-Z_]*)\.', r'\1_cython.', line)
  67. line = re.sub(r'^(\s*cimport awlsim[0-9a-zA-Z_]*)\.', r'\1_cython.', line)
  68. return line
  69. setup_cython.pyCythonPatchLine = pyCythonPatchLine
  70. cmdclass = {}
  71. # Try to build the Cython modules. This might fail.
  72. if buildCython:
  73. buildCython = setup_cython.cythonBuildPossible()
  74. if buildCython:
  75. cmdclass["build_ext"] = setup_cython.CythonBuildExtension
  76. setup_cython.registerCythonModules()
  77. else:
  78. print("Skipping build of CYTHON modules.")
  79. ext_modules = setup_cython.ext_modules
  80. extraKeywords = {}
  81. # Workaround for mbcs codec bug in distutils
  82. # http://bugs.python.org/issue10945
  83. import codecs
  84. try:
  85. codecs.lookup("mbcs")
  86. except LookupError:
  87. codecs.register(lambda name: codecs.lookup("ascii") if name == "mbcs" else None)
  88. # Create list of scripts. Depends on OS.
  89. scripts = [ "awlsim-gui",
  90. "awlsim-client",
  91. "awlsim-server",
  92. "awlsim-symtab",
  93. "awlsim-proupgrade",
  94. "awlsim-test", ]
  95. if isWindows or fullBuild:
  96. scripts.append("awlsim-win.cmd")
  97. if not isWindows or fullBuild:
  98. scripts.append("awlsim-linuxcnc-hal")
  99. # List of all hardware modules.
  100. hwmodules = [
  101. "awlsimhw_debug",
  102. "awlsimhw_dummy",
  103. "awlsimhw_linuxcnc",
  104. "awlsimhw_pyprofibus",
  105. "awlsimhw_rpigpio",
  106. "awlsimhw_pixtend",
  107. ]
  108. # Create freeze executable list.
  109. guiBase = None
  110. if isWindows:
  111. guiBase = "Win32GUI"
  112. freezeExecutables = [ ("awlsim-gui", None, guiBase),
  113. ("awlsim-client", None, None),
  114. ("awlsim-server", None, None),
  115. ("awlsim-symtab", None, None),
  116. ("awlsim-proupgrade", None, None),
  117. ("awlsim-test", None, None),
  118. ("awlsim/coreserver/server.py", "awlsim-server-module", None), ]
  119. if py2exe:
  120. extraKeywords["console"] = [ s for s, e, b in freezeExecutables ]
  121. if cx_Freeze:
  122. executables = []
  123. for script, exe, base in freezeExecutables:
  124. if exe:
  125. if isWindows:
  126. exe += ".exe"
  127. executables.append(Executable(script = script,
  128. targetName = exe,
  129. base = base))
  130. else:
  131. executables.append(Executable(script = script,
  132. base = base))
  133. extraKeywords["executables"] = executables
  134. extraKeywords["options"] = {
  135. "build_exe" : {
  136. "packages" : hwmodules + [ "awlsim.library.iec", ],
  137. }
  138. }
  139. warnings.filterwarnings("ignore", r".*'python_requires'.*")
  140. warnings.filterwarnings("ignore", r".*'long_description_content_type'.*")
  141. with open(os.path.join(basedir, "README.md"), "rb") as fd:
  142. readmeText = fd.read().decode("UTF-8")
  143. setup( name = "awlsim",
  144. version = VERSION_STRING,
  145. description = "S7 compatible Programmable Logic Controller PLC/SPS (AWL, STL, FUP, FBD)",
  146. license = "GNU General Public License v2 or later",
  147. author = "Michael Buesch",
  148. author_email = "m@bues.ch",
  149. url = "https://awlsim.de",
  150. python_requires = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*",
  151. packages = [ "awlsim",
  152. "awlsim_loader",
  153. "awlsim/common",
  154. "awlsim/core",
  155. "awlsim/core/instructions",
  156. "awlsim/core/systemblocks",
  157. "awlsim/coreclient",
  158. "awlsim/coreserver",
  159. "awlsim/awlcompiler",
  160. "awlsim/awloptimizer",
  161. "awlsim/fupcompiler",
  162. "awlsim/gui",
  163. "awlsim/gui/fup",
  164. "awlsim/gui/icons",
  165. "awlsim/gui/interfedit",
  166. "awlsim/library",
  167. "awlsim/library/iec",
  168. ] + hwmodules,
  169. scripts = scripts,
  170. cmdclass = cmdclass,
  171. ext_modules = ext_modules,
  172. keywords = "AWL STL FUP FBD SPS PLC emulator simulator "
  173. "Step-7 Siemens PROFIBUS "
  174. "LinuxCNC PiXtend RaspberryPi",
  175. classifiers = [
  176. "Development Status :: 4 - Beta",
  177. "Environment :: Console",
  178. "Environment :: Win32 (MS Windows)",
  179. "Environment :: X11 Applications",
  180. "Intended Audience :: Developers",
  181. "Intended Audience :: Education",
  182. "Intended Audience :: Information Technology",
  183. "Intended Audience :: Manufacturing",
  184. "Intended Audience :: Science/Research",
  185. "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
  186. "Operating System :: Microsoft :: Windows",
  187. "Operating System :: POSIX",
  188. "Operating System :: POSIX :: Linux",
  189. "Programming Language :: Cython",
  190. "Programming Language :: Python",
  191. "Programming Language :: Python :: 2.7",
  192. "Programming Language :: Python :: 3",
  193. "Programming Language :: Python :: Implementation :: CPython",
  194. "Programming Language :: Python :: Implementation :: PyPy",
  195. "Topic :: Education",
  196. "Topic :: Home Automation",
  197. "Topic :: Scientific/Engineering",
  198. "Topic :: Software Development",
  199. "Topic :: Software Development :: Interpreters",
  200. "Topic :: Software Development :: Embedded Systems",
  201. "Topic :: Software Development :: Testing",
  202. "Topic :: System :: Emulators",
  203. ],
  204. long_description=readmeText,
  205. long_description_content_type="text/markdown",
  206. **extraKeywords
  207. )