setup.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/usr/bin/env python3
  2. from __future__ import print_function
  3. import sys, os
  4. basedir = os.path.abspath(os.path.dirname(__file__))
  5. for base in (os.getcwd(), basedir):
  6. sys.path.insert(0, os.path.join(base, "misc"))
  7. # Add the basedir to PYTHONPATH before we try to import pyprofibus.version
  8. sys.path.insert(0, base)
  9. from pyprofibus.version import VERSION_STRING
  10. import setup_cython
  11. from distutils.core import setup
  12. import warnings
  13. import re
  14. isWindows = os.name.lower() in {"nt", "ce"}
  15. isPosix = os.name.lower() == "posix"
  16. def getEnvInt(name, default = 0):
  17. try:
  18. return int(os.getenv(name, "%d" % default))
  19. except ValueError:
  20. return default
  21. def getEnvBool(name, default = False):
  22. return bool(getEnvInt(name, 1 if default else 0))
  23. buildCython = getEnvInt("PYPROFIBUS_CYTHON_BUILD", 3 if isPosix else 0)
  24. buildCython = ((buildCython == 1) or (buildCython == sys.version_info[0]))
  25. setup_cython.parallelBuild = bool(getEnvInt("PYPROFIBUS_CYTHON_PARALLEL", 1) == 1 or\
  26. getEnvInt("PYPROFIBUS_CYTHON_PARALLEL", 1) == sys.version_info[0])
  27. setup_cython.profileEnabled = bool(getEnvInt("PYPROFIBUS_PROFILE") > 0)
  28. setup_cython.debugEnabled = bool(getEnvInt("PYPROFIBUS_DEBUG_BUILD") > 0)
  29. def pyCythonPatchLine(line):
  30. # Patch the import statements
  31. line = re.sub(r'^(\s*from pyprofibus[0-9a-zA-Z_]*)\.([0-9a-zA-Z_\.]+) import', r'\1_cython.\2 import', line)
  32. line = re.sub(r'^(\s*from pyprofibus[0-9a-zA-Z_]*)\.([0-9a-zA-Z_\.]+) cimport', r'\1_cython.\2 cimport', line)
  33. line = re.sub(r'^(\s*import pyprofibus[0-9a-zA-Z_]*)\.', r'\1_cython.', line)
  34. line = re.sub(r'^(\s*cimport pyprofibus[0-9a-zA-Z_]*)\.', r'\1_cython.', line)
  35. return line
  36. setup_cython.pyCythonPatchLine = pyCythonPatchLine
  37. cmdclass = {}
  38. # Try to build the Cython modules. This might fail.
  39. if buildCython:
  40. buildCython = setup_cython.cythonBuildPossible()
  41. if buildCython:
  42. cmdclass["build_ext"] = setup_cython.CythonBuildExtension
  43. setup_cython.registerCythonModules()
  44. else:
  45. print("Skipping build of CYTHON modules.")
  46. ext_modules = setup_cython.ext_modules
  47. warnings.filterwarnings("ignore", r".*'long_description_content_type'.*")
  48. with open(os.path.join(basedir, "README.rst"), "rb") as fd:
  49. readmeText = fd.read().decode("UTF-8")
  50. setup( name = "pyprofibus",
  51. version = VERSION_STRING,
  52. description = "Python PROFIBUS module",
  53. license = "GNU General Public License v2 or later",
  54. author = "Michael Buesch",
  55. author_email = "m@bues.ch",
  56. url = "https://bues.ch/a/profibus",
  57. scripts = [ "gsdparser",
  58. "profisniff",
  59. "pyprofibus-linuxcnc-hal", ],
  60. packages = [ "pyprofibus", "pyprofibus.gsd", "pyprofibus.phy_fpga_driver" ],
  61. cmdclass = cmdclass,
  62. ext_modules = ext_modules,
  63. keywords = [ "PROFIBUS", "PROFIBUS-DP", "SPS", "PLC",
  64. "Step 7", "Siemens",
  65. "GSD", "GSD parser", "General Station Description", ],
  66. classifiers = [
  67. "Development Status :: 4 - Beta",
  68. "Environment :: Console",
  69. "Intended Audience :: Developers",
  70. "Intended Audience :: Education",
  71. "Intended Audience :: Information Technology",
  72. "Intended Audience :: Manufacturing",
  73. "Intended Audience :: Science/Research",
  74. "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
  75. "Operating System :: POSIX",
  76. "Operating System :: POSIX :: Linux",
  77. "Programming Language :: Cython",
  78. "Programming Language :: Python",
  79. "Programming Language :: Python :: 3",
  80. "Programming Language :: Python :: Implementation :: CPython",
  81. "Programming Language :: Python :: Implementation :: PyPy",
  82. "Programming Language :: Python :: Implementation :: MicroPython",
  83. "Topic :: Education",
  84. "Topic :: Home Automation",
  85. "Topic :: Scientific/Engineering",
  86. "Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator",
  87. "Topic :: Scientific/Engineering :: Human Machine Interfaces",
  88. "Topic :: Software Development :: Embedded Systems",
  89. "Topic :: Software Development :: Libraries",
  90. "Topic :: System :: Hardware",
  91. "Topic :: System :: Hardware :: Hardware Drivers",
  92. "Topic :: System :: Networking",
  93. ],
  94. long_description=readmeText,
  95. long_description_content_type="text/x-rst",
  96. )