summaryrefslogtreecommitdiffstats
path: root/setup.py
blob: 40f45dfd625a82b923f675ea6a2a02bdcbc06254 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python3

from __future__ import print_function

import sys, os
basedir = os.path.abspath(os.path.dirname(__file__))

for base in (os.getcwd(), basedir):
	sys.path.insert(0, os.path.join(base, "misc"))
	# Add the basedir to PYTHONPATH before we try to import pyprofibus.version
	sys.path.insert(0, base)

from pyprofibus.version import VERSION_STRING
import setup_cython
from distutils.core import setup
import warnings
import re


isWindows = os.name.lower() in {"nt", "ce"}
isPosix = os.name.lower() == "posix"


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))

buildCython = getEnvInt("PYPROFIBUS_CYTHON_BUILD", 3 if isPosix else 0)
buildCython = ((buildCython == 1) or (buildCython == sys.version_info[0]))
setup_cython.parallelBuild = bool(getEnvInt("PYPROFIBUS_CYTHON_PARALLEL", 1) == 1 or\
				  getEnvInt("PYPROFIBUS_CYTHON_PARALLEL", 1) == sys.version_info[0])
setup_cython.profileEnabled = bool(getEnvInt("PYPROFIBUS_PROFILE") > 0)
setup_cython.debugEnabled = bool(getEnvInt("PYPROFIBUS_DEBUG_BUILD") > 0)

def pyCythonPatchLine(line):
	# Patch the import statements
	line = re.sub(r'^(\s*from pyprofibus[0-9a-zA-Z_]*)\.([0-9a-zA-Z_\.]+) import', r'\1_cython.\2 import', line)
	line = re.sub(r'^(\s*from pyprofibus[0-9a-zA-Z_]*)\.([0-9a-zA-Z_\.]+) cimport', r'\1_cython.\2 cimport', line)
	line = re.sub(r'^(\s*import pyprofibus[0-9a-zA-Z_]*)\.', r'\1_cython.', line)
	line = re.sub(r'^(\s*cimport pyprofibus[0-9a-zA-Z_]*)\.', r'\1_cython.', line)
	return line

setup_cython.pyCythonPatchLine = pyCythonPatchLine

cmdclass = {}

# Try to build the Cython modules. This might fail.
if buildCython:
	buildCython = setup_cython.cythonBuildPossible()
if buildCython:
	cmdclass["build_ext"] = setup_cython.CythonBuildExtension
	setup_cython.registerCythonModules()
else:
	print("Skipping build of CYTHON modules.")

ext_modules = setup_cython.ext_modules


warnings.filterwarnings("ignore", r".*'long_description_content_type'.*")

with open(os.path.join(basedir, "README.md"), "rb") as fd:
	readmeText = fd.read().decode("UTF-8")

setup(	name		= "pyprofibus",
	version		= VERSION_STRING,
	description	= "Python PROFIBUS module",
	license		= "GNU General Public License v2 or later",
	author		= "Michael Buesch",
	author_email	= "m@bues.ch",
	url		= "https://bues.ch/a/profibus",
	scripts		= [ "gsdparser",
			    "profisniff",
			    "pyprofibus-linuxcnc-hal", ],
	packages	= [ "pyprofibus", "pyprofibus.gsd", "pyprofibus.phy_fpga_driver" ],
	cmdclass	= cmdclass,
	ext_modules	= ext_modules,
	keywords	= [ "PROFIBUS", "PROFIBUS-DP", "SPS", "PLC",
			    "Step 7", "Siemens",
			    "GSD", "GSD parser", "General Station Description", ],
	classifiers	= [
		"Development Status :: 4 - Beta",
		"Environment :: Console",
		"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 :: POSIX",
		"Operating System :: POSIX :: Linux",
		"Programming Language :: Cython",
		"Programming Language :: Python",
		"Programming Language :: Python :: 2.7",
		"Programming Language :: Python :: 3",
		"Programming Language :: Python :: Implementation :: CPython",
		"Programming Language :: Python :: Implementation :: PyPy",
		"Topic :: Education",
		"Topic :: Home Automation",
		"Topic :: Scientific/Engineering",
		"Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator",
		"Topic :: Software Development :: Embedded Systems",
		"Topic :: System :: Hardware",
		"Topic :: System :: Hardware :: Hardware Drivers",
		"Topic :: System :: Networking",
	],
	long_description=readmeText,
	long_description_content_type="text/markdown",
)
bues.ch cgit interface