setup.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. """Distutils script for cx_Oracle.
  2. Windows platforms:
  3. python setup.py build --compiler=mingw32 install
  4. Unix platforms
  5. python setup.py build install
  6. """
  7. import distutils.core
  8. import os
  9. import sys
  10. # if setuptools is detected, use it to add support for eggs
  11. try:
  12. from setuptools import setup, Extension
  13. except:
  14. from distutils.core import setup
  15. from distutils.extension import Extension
  16. # define build constants
  17. BUILD_VERSION = "6.4.1"
  18. # setup extra link and compile args
  19. extraLinkArgs = []
  20. extraCompileArgs = []
  21. if sys.platform == "aix4":
  22. extraCompileArgs.append("-qcpluscmt")
  23. elif sys.platform == "aix5":
  24. extraCompileArgs.append("-DAIX5")
  25. elif sys.platform == "cygwin":
  26. extraLinkArgs.append("-Wl,--enable-runtime-pseudo-reloc")
  27. elif sys.platform == "darwin":
  28. extraLinkArgs.append("-shared-libgcc")
  29. class test(distutils.core.Command):
  30. description = "run the test suite for the extension"
  31. user_options = []
  32. def finalize_options(self):
  33. pass
  34. def initialize_options(self):
  35. pass
  36. def run(self):
  37. self.run_command("build")
  38. buildCommand = self.distribution.get_command_obj("build")
  39. sys.path.insert(0, os.path.abspath("test"))
  40. sys.path.insert(0, os.path.abspath(buildCommand.build_lib))
  41. fileName = os.path.join("test", "test.py")
  42. exec(open(fileName).read())
  43. # define classifiers for the package index
  44. classifiers = [
  45. "Development Status :: 6 - Mature",
  46. "Intended Audience :: Developers",
  47. "License :: OSI Approved :: BSD License",
  48. "Natural Language :: English",
  49. "Operating System :: OS Independent",
  50. "Programming Language :: C",
  51. "Programming Language :: Python",
  52. "Programming Language :: Python :: 2",
  53. "Programming Language :: Python :: 3",
  54. "Topic :: Database"
  55. ]
  56. # define cx_Oracle sources
  57. sourceDir = "src"
  58. sources = [os.path.join(sourceDir, n) \
  59. for n in sorted(os.listdir(sourceDir)) if n.endswith(".c")]
  60. depends = ["src/cxoModule.h"]
  61. # define ODPI-C sources, libraries and include directories; if the environment
  62. # variables ODPIC_INC_DIR and ODPIC_LIB_DIR are both set, assume these
  63. # locations contain a compiled installation of ODPI-C; otherwise, use the
  64. # source of ODPI-C found in the odpi subdirectory
  65. dpiIncludeDir = os.environ.get("ODPIC_INC_DIR")
  66. dpiLibDir = os.environ.get("ODPIC_LIB_DIR")
  67. if dpiIncludeDir and dpiLibDir:
  68. dpiSources = []
  69. includeDirs = [dpiIncludeDir]
  70. libraries = ["odpic"]
  71. libraryDirs = [dpiLibDir]
  72. else:
  73. includeDirs = ["odpi/include", "odpi/src"]
  74. dpiSourceDir = os.path.join("odpi", "src")
  75. dpiSources = [os.path.join(dpiSourceDir, n) \
  76. for n in sorted(os.listdir(dpiSourceDir)) if n.endswith(".c")]
  77. depends.extend(["odpi/include/dpi.h", "odpi/src/dpiImpl.h",
  78. "odpi/src/dpiErrorMessages.h"])
  79. libraries = []
  80. libraryDirs = []
  81. # setup the extension
  82. extension = Extension(
  83. name = "cx_Oracle",
  84. include_dirs = includeDirs,
  85. extra_compile_args = extraCompileArgs,
  86. define_macros = [("CXO_BUILD_VERSION", BUILD_VERSION)],
  87. extra_link_args = extraLinkArgs,
  88. sources = sources + dpiSources,
  89. depends = depends,
  90. libraries = libraries,
  91. library_dirs = libraryDirs)
  92. # perform the setup
  93. setup(
  94. name = "cx_Oracle",
  95. version = BUILD_VERSION,
  96. description = "Python interface to Oracle",
  97. cmdclass = dict(test = test),
  98. data_files = [ ("cx_Oracle-doc", ["LICENSE.txt", "README.txt"]) ],
  99. long_description = \
  100. "Python interface to Oracle Database conforming to the Python DB "
  101. "API 2.0 specification.\n"
  102. "See http://www.python.org/topics/database/DatabaseAPI-2.0.html.",
  103. author = "Anthony Tuininga",
  104. author_email = "anthony.tuininga@gmail.com",
  105. url = "https://oracle.github.io/python-cx_Oracle",
  106. ext_modules = [extension],
  107. keywords = "Oracle",
  108. license = "BSD License",
  109. classifiers = classifiers)