setup.py 4.0 KB

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