setup.py 7.0 KB

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