setup.py 5.65 KB
Newer Older
Michael Büsch's avatar
Michael Büsch committed
1 2
#!/usr/bin/env python3

Michael Büsch's avatar
Michael Büsch committed
3 4
from __future__ import print_function

5 6 7
import sys
import os
import re
Michael Büsch's avatar
Michael Büsch committed
8
from distutils.core import setup
Michael Büsch's avatar
Michael Büsch committed
9
from awlsim.common.version import VERSION_STRING
Michael Büsch's avatar
Michael Büsch committed
10 11 12 13
try:
	import py2exe
except ImportError as e:
	py2exe = None
14 15 16 17 18 19 20
try:
	if py2exe and "py2exe" in sys.argv:
		raise ImportError
	from cx_Freeze import setup, Executable
	cx_Freeze = True
except ImportError as e:
	cx_Freeze = False
Michael Büsch's avatar
Michael Büsch committed
21

22
sys.path.insert(0, "./maintenance")
23 24
import setup_cython

25

26
isWindows = os.name.lower() in {"nt", "ce"}
27 28 29 30 31 32 33 34 35 36 37 38 39 40


def getEnvInt(name, default = 0):
	try:
		return int(os.getenv(name, "%d" % default))
	except ValueError:
		return default

def getEnvBool(name, default = False):
	return bool(getEnvInt(name, 1 if default else 0))


fullBuild = getEnvBool("AWLSIM_FULL_BUILD")
buildCython = getEnvBool("AWLSIM_CYTHON", True)
41 42
setup_cython.parallelBuild = bool(getEnvInt("AWLSIM_CYTHON_PARALLEL", 1) == 1 or\
				  getEnvInt("AWLSIM_CYTHON_PARALLEL", 1) == sys.version_info[0])
43 44


45 46 47 48 49 50 51
def pyCythonPatchLine(line, basicOnly=False):
	# Patch the import statements
	line = re.sub(r'^(\s*from awlsim[0-9a-zA-Z_]*)\.([0-9a-zA-Z_\.]+) import', r'\1_cython.\2 import', line)
	line = re.sub(r'^(\s*from awlsim[0-9a-zA-Z_]*)\.([0-9a-zA-Z_\.]+) cimport', r'\1_cython.\2 cimport', line)
	line = re.sub(r'^(\s*import awlsim[0-9a-zA-Z_]*)\.', r'\1_cython.', line)
	line = re.sub(r'^(\s*cimport awlsim[0-9a-zA-Z_]*)\.', r'\1_cython.', line)
	return line
52

53
setup_cython.pyCythonPatchLine = pyCythonPatchLine
54

55 56 57 58
cmdclass = {}

# Try to build the Cython modules. This might fail.
if buildCython:
59
	buildCython = setup_cython.cythonBuildPossible()
60
if buildCython:
61 62 63 64
	cmdclass["build_ext"] = setup_cython.CythonBuildExtension
	setup_cython.registerCythonModules()
else:
	print("Skipping build of CYTHON modules.")
Michael Büsch's avatar
Michael Büsch committed
65

66 67
ext_modules = setup_cython.ext_modules
extraKeywords = {}
68

69 70 71 72 73 74 75 76
# Workaround for mbcs codec bug in distutils
# http://bugs.python.org/issue10945
import codecs
try:
	codecs.lookup("mbcs")
except LookupError:
	codecs.register(lambda name: codecs.lookup("ascii") if name == "mbcs" else None)

77 78 79 80 81 82 83

# Create list of scripts. Depends on OS.
scripts = [ "awlsim-gui",
	    "awlsim-client",
	    "awlsim-server",
	    "awlsim-symtab",
	    "awlsim-test", ]
84
if isWindows or fullBuild:
85
	scripts.append("awlsim-win.cmd")
86
if not isWindows or fullBuild:
87 88 89 90 91 92
	scripts.append("awlsim-linuxcnc-hal")
	scripts.append("pilc/pilc-hat-conf")


# Create freeze executable list.
guiBase = None
93
if isWindows:
94 95 96 97 98 99 100
	guiBase = "Win32GUI"
freezeExecutables = [ ("awlsim-gui", None, guiBase),
		      ("awlsim-client", None, None),
		      ("awlsim-server", None, None),
		      ("awlsim-symtab", None, None),
		      ("awlsim-test", None, None),
		      ("awlsim/coreserver/server.py", "awlsim-server-module", None), ]
Michael Büsch's avatar
Michael Büsch committed
101
if py2exe:
102
	extraKeywords["console"] = [ s for s, e, b in freezeExecutables ]
103
if cx_Freeze:
104
	executables = []
105
	for script, exe, base in freezeExecutables:
106
		if exe:
107
			if isWindows:
108 109
				exe += ".exe"
			executables.append(Executable(script = script,
110 111
						      targetName = exe,
						      base = base))
112
		else:
113 114
			executables.append(Executable(script = script,
						      base = base))
115
	extraKeywords["executables"] = executables
116 117 118 119 120 121 122
	extraKeywords["options"] = {
			"build_exe"     : {
				"packages"      : [ "awlsimhw_debug",
						    "awlsimhw_dummy",
						    "awlsim.library.iec", ],
			}
		}
Michael Büsch's avatar
Michael Büsch committed
123

124

Michael Büsch's avatar
Michael Büsch committed
125
setup(	name		= "awlsim",
Michael Büsch's avatar
Michael Büsch committed
126
	version		= VERSION_STRING,
127
	description	= "S7 AWL/STL Soft-PLC",
128
	license		= "GNU General Public License v2 or later",
Michael Büsch's avatar
Michael Büsch committed
129 130
	author		= "Michael Buesch",
	author_email	= "m@bues.ch",
Michael Büsch's avatar
Michael Büsch committed
131
	url		= "https://bues.ch/a/awlsim",
132
	packages	= [ "awlsim",
133
			    "awlsim_loader",
134
			    "awlsim/common",
135 136
			    "awlsim/core",
			    "awlsim/core/instructions",
137
			    "awlsim/core/systemblocks",
138
			    "awlsim/coreclient",
139
			    "awlsim/coreserver",
140
			    "awlsim/awlcompiler",
141
			    "awlsim/fupcompiler",
142
			    "awlsim/gui",
143
			    "awlsim/gui/fup",
Michael Büsch's avatar
Michael Büsch committed
144
			    "awlsim/gui/icons",
145
			    "awlsim/gui/interfedit",
Michael Büsch's avatar
Michael Büsch committed
146 147
			    "awlsim/library",
			    "awlsim/library/iec",
Michael Büsch's avatar
Michael Büsch committed
148
			    "awlsimhw_debug",
149 150
			    "awlsimhw_dummy",
			    "awlsimhw_linuxcnc",
151
			    "awlsimhw_pyprofibus",
Michael Büsch's avatar
Michael Büsch committed
152 153 154
			    "awlsimhw_rpigpio",
			    "libpilc", ],
	package_dir	= { "libpilc" : "pilc/libpilc", },
155
	scripts		= scripts,
156
	cmdclass	= cmdclass,
157
	ext_modules	= ext_modules,
158 159 160
	keywords	= [ "AWL", "STL", "SPS", "PLC", "Step 7",
			    "Siemens", "emulator", "simulator",
			    "PROFIBUS", "LinuxCNC", ],
161 162 163 164 165 166 167 168 169 170 171 172 173
	classifiers	= [
		"Development Status :: 4 - Beta",
		"Environment :: Console",
		"Environment :: Win32 (MS Windows)",
		"Environment :: X11 Applications",
		"Intended Audience :: Developers",
		"Intended Audience :: Education",
		"Intended Audience :: Information Technology",
		"Intended Audience :: Manufacturing",
		"Intended Audience :: Science/Research",
		"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
		"Operating System :: Microsoft :: Windows",
		"Operating System :: POSIX",
174
		"Operating System :: POSIX :: Linux",
175
		"Programming Language :: Cython",
176
		"Programming Language :: Python",
177 178 179 180
		"Programming Language :: Python :: 2.7",
		"Programming Language :: Python :: 3",
		"Programming Language :: Python :: Implementation :: CPython",
		"Programming Language :: Python :: Implementation :: PyPy",
Michael Büsch's avatar
Michael Büsch committed
181 182
		"Programming Language :: Python :: Implementation :: Jython",
		"Programming Language :: Python :: Implementation :: IronPython",
183
		"Topic :: Education",
Michael Büsch's avatar
Michael Büsch committed
184
		"Topic :: Home Automation",
185
		"Topic :: Scientific/Engineering",
186
		"Topic :: Software Development",
187
		"Topic :: Software Development :: Interpreters",
Michael Büsch's avatar
Michael Büsch committed
188
		"Topic :: Software Development :: Embedded Systems",
189 190
		"Topic :: Software Development :: Testing",
		"Topic :: System :: Emulators",
191
	],
192
	long_description = open("README.md").read(),
Michael Büsch's avatar
Michael Büsch committed
193
	**extraKeywords
Michael Büsch's avatar
Michael Büsch committed
194
)