setup.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #!/usr/bin/env python3
  2. from __future__ import print_function
  3. import sys
  4. import os
  5. import re
  6. from distutils.core import setup
  7. from awlsim.common.version import VERSION_STRING
  8. try:
  9. import py2exe
  10. except ImportError as e:
  11. py2exe = None
  12. try:
  13. if py2exe and "py2exe" in sys.argv:
  14. raise ImportError
  15. from cx_Freeze import setup, Executable
  16. cx_Freeze = True
  17. except ImportError as e:
  18. cx_Freeze = False
  19. import setup_cython
  20. isWindows = os.name.lower() in {"nt", "ce"}
  21. def getEnvInt(name, default = 0):
  22. try:
  23. return int(os.getenv(name, "%d" % default))
  24. except ValueError:
  25. return default
  26. def getEnvBool(name, default = False):
  27. return bool(getEnvInt(name, 1 if default else 0))
  28. fullBuild = getEnvBool("AWLSIM_FULL_BUILD")
  29. buildCython = getEnvBool("AWLSIM_CYTHON", True)
  30. setup_cython.parallelBuild = bool(getEnvInt("AWLSIM_CYTHON_PARALLEL", 1) == 1 or\
  31. getEnvInt("AWLSIM_CYTHON_PARALLEL", 1) == sys.version_info[0])
  32. def pyCythonPatchLine(line, basicOnly=False):
  33. # Patch the import statements
  34. line = re.sub(r'^(\s*from awlsim[0-9a-zA-Z_]*)\.([0-9a-zA-Z_\.]+) import', r'\1_cython.\2 import', line)
  35. line = re.sub(r'^(\s*from awlsim[0-9a-zA-Z_]*)\.([0-9a-zA-Z_\.]+) cimport', r'\1_cython.\2 cimport', line)
  36. line = re.sub(r'^(\s*import awlsim[0-9a-zA-Z_]*)\.', r'\1_cython.', line)
  37. line = re.sub(r'^(\s*cimport awlsim[0-9a-zA-Z_]*)\.', r'\1_cython.', line)
  38. return line
  39. setup_cython.pyCythonPatchLine = pyCythonPatchLine
  40. cmdclass = {}
  41. # Try to build the Cython modules. This might fail.
  42. if buildCython:
  43. buildCython = setup_cython.cythonBuildPossible()
  44. if buildCython:
  45. cmdclass["build_ext"] = setup_cython.CythonBuildExtension
  46. setup_cython.registerCythonModules()
  47. else:
  48. print("Skipping build of CYTHON modules.")
  49. ext_modules = setup_cython.ext_modules
  50. extraKeywords = {}
  51. # Workaround for mbcs codec bug in distutils
  52. # http://bugs.python.org/issue10945
  53. import codecs
  54. try:
  55. codecs.lookup("mbcs")
  56. except LookupError:
  57. codecs.register(lambda name: codecs.lookup("ascii") if name == "mbcs" else None)
  58. # Create list of scripts. Depends on OS.
  59. scripts = [ "awlsim-gui",
  60. "awlsim-client",
  61. "awlsim-server",
  62. "awlsim-symtab",
  63. "awlsim-test", ]
  64. if isWindows or fullBuild:
  65. scripts.append("awlsim-win.cmd")
  66. if not isWindows or fullBuild:
  67. scripts.append("awlsim-linuxcnc-hal")
  68. scripts.append("pilc/pilc-hat-conf")
  69. # Create freeze executable list.
  70. guiBase = None
  71. if isWindows:
  72. guiBase = "Win32GUI"
  73. freezeExecutables = [ ("awlsim-gui", None, guiBase),
  74. ("awlsim-client", None, None),
  75. ("awlsim-server", None, None),
  76. ("awlsim-symtab", None, None),
  77. ("awlsim-test", None, None),
  78. ("awlsim/coreserver/server.py", "awlsim-server-module", None), ]
  79. if py2exe:
  80. extraKeywords["console"] = [ s for s, e, b in freezeExecutables ]
  81. if cx_Freeze:
  82. executables = []
  83. for script, exe, base in freezeExecutables:
  84. if exe:
  85. if isWindows:
  86. exe += ".exe"
  87. executables.append(Executable(script = script,
  88. targetName = exe,
  89. base = base))
  90. else:
  91. executables.append(Executable(script = script,
  92. base = base))
  93. extraKeywords["executables"] = executables
  94. extraKeywords["options"] = {
  95. "build_exe" : {
  96. "packages" : [ "awlsimhw_debug",
  97. "awlsimhw_dummy",
  98. "awlsim.library.iec", ],
  99. }
  100. }
  101. setup( name = "awlsim",
  102. version = VERSION_STRING,
  103. description = "S7 AWL/STL Soft-PLC",
  104. license = "GNU General Public License v2 or later",
  105. author = "Michael Buesch",
  106. author_email = "m@bues.ch",
  107. url = "https://bues.ch/a/awlsim",
  108. packages = [ "awlsim",
  109. "awlsim_loader",
  110. "awlsim/common",
  111. "awlsim/core",
  112. "awlsim/core/instructions",
  113. "awlsim/core/systemblocks",
  114. "awlsim/coreclient",
  115. "awlsim/coreserver",
  116. "awlsim/gui",
  117. "awlsim/gui/icons",
  118. "awlsim/library",
  119. "awlsim/library/iec",
  120. "awlsimhw_debug",
  121. "awlsimhw_dummy",
  122. "awlsimhw_linuxcnc",
  123. "awlsimhw_pyprofibus",
  124. "awlsimhw_rpigpio",
  125. "libpilc", ],
  126. package_dir = { "libpilc" : "pilc/libpilc", },
  127. scripts = scripts,
  128. cmdclass = cmdclass,
  129. ext_modules = ext_modules,
  130. keywords = [ "AWL", "STL", "SPS", "PLC", "Step 7",
  131. "Siemens", "emulator", "simulator",
  132. "PROFIBUS", "LinuxCNC", ],
  133. classifiers = [
  134. "Development Status :: 4 - Beta",
  135. "Environment :: Console",
  136. "Environment :: Win32 (MS Windows)",
  137. "Environment :: X11 Applications",
  138. "Intended Audience :: Developers",
  139. "Intended Audience :: Education",
  140. "Intended Audience :: Information Technology",
  141. "Intended Audience :: Manufacturing",
  142. "Intended Audience :: Science/Research",
  143. "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
  144. "Operating System :: Microsoft :: Windows",
  145. "Operating System :: POSIX",
  146. "Operating System :: POSIX :: Linux",
  147. "Programming Language :: Cython",
  148. "Programming Language :: Python",
  149. "Programming Language :: Python :: 2.7",
  150. "Programming Language :: Python :: 3",
  151. "Programming Language :: Python :: Implementation :: CPython",
  152. "Programming Language :: Python :: Implementation :: PyPy",
  153. "Programming Language :: Python :: Implementation :: Jython",
  154. "Programming Language :: Python :: Implementation :: IronPython",
  155. "Topic :: Education",
  156. "Topic :: Home Automation",
  157. "Topic :: Scientific/Engineering",
  158. "Topic :: Software Development",
  159. "Topic :: Software Development :: Interpreters",
  160. "Topic :: Software Development :: Embedded Systems",
  161. "Topic :: Software Development :: Testing",
  162. "Topic :: System :: Emulators",
  163. ],
  164. long_description = open("README.md").read(),
  165. **extraKeywords
  166. )