setup.py 7.5 KB

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