setup.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #-*- coding: ISO-8859-1 -*-
  2. # setup.py: the distutils script
  3. #
  4. # Copyright (C) 2004-2007 Gerhard Häring <gh@ghaering.de>
  5. #
  6. # This file is part of pysqlite.
  7. #
  8. # This software is provided 'as-is', without any express or implied
  9. # warranty. In no event will the authors be held liable for any damages
  10. # arising from the use of this software.
  11. #
  12. # Permission is granted to anyone to use this software for any purpose,
  13. # including commercial applications, and to alter it and redistribute it
  14. # freely, subject to the following restrictions:
  15. #
  16. # 1. The origin of this software must not be misrepresented; you must not
  17. # claim that you wrote the original software. If you use this software
  18. # in a product, an acknowledgment in the product documentation would be
  19. # appreciated but is not required.
  20. # 2. Altered source versions must be plainly marked as such, and must not be
  21. # misrepresented as being the original software.
  22. # 3. This notice may not be removed or altered from any source distribution.
  23. import glob, os, re, sys
  24. import urllib
  25. import zipfile
  26. from distutils.core import setup, Extension, Command
  27. from distutils.command.build import build
  28. from distutils.command.build_ext import build_ext
  29. import cross_bdist_wininst
  30. # If you need to change anything, it should be enough to change setup.cfg.
  31. sqlite = "sqlite"
  32. sources = ["src/module.c", "src/connection.c", "src/cursor.c", "src/cache.c",
  33. "src/microprotocols.c", "src/prepare_protocol.c", "src/statement.c",
  34. "src/util.c", "src/row.c"]
  35. include_dirs = []
  36. library_dirs = []
  37. libraries = []
  38. runtime_library_dirs = []
  39. extra_objects = []
  40. define_macros = []
  41. long_description = \
  42. """Python interface to SQLite 3
  43. pysqlite is an interface to the SQLite 3.x embedded relational database engine.
  44. It is almost fully compliant with the Python database API version 2.0 also
  45. exposes the unique features of SQLite."""
  46. if sys.platform != "win32":
  47. define_macros.append(('MODULE_NAME', '"pysqlite2.dbapi2"'))
  48. else:
  49. define_macros.append(('MODULE_NAME', '\\"pysqlite2.dbapi2\\"'))
  50. class DocBuilder(Command):
  51. description = "Builds the documentation"
  52. user_options = []
  53. def initialize_options(self):
  54. pass
  55. def finalize_options(self):
  56. pass
  57. def run(self):
  58. import os, shutil
  59. try:
  60. shutil.rmtree("build/doc")
  61. except OSError:
  62. pass
  63. os.makedirs("build/doc")
  64. rc = os.system("sphinx-build doc/sphinx build/doc")
  65. if rc != 0:
  66. print "Is sphinx installed? If not, try 'sudo easy_install sphinx'."
  67. AMALGAMATION_ROOT = "amalgamation"
  68. def get_amalgamation():
  69. """Download the SQLite amalgamation if it isn't there, already."""
  70. if os.path.exists(AMALGAMATION_ROOT):
  71. return
  72. os.mkdir(AMALGAMATION_ROOT)
  73. print "Downloading amalgation."
  74. # find out what's current amalgamation ZIP file
  75. download_page = urllib.urlopen("http://sqlite.org/download.html").read()
  76. pattern = re.compile("(sqlite-amalgamation.*?\.zip)")
  77. download_file = pattern.findall(download_page)[0]
  78. amalgamation_url = "http://sqlite.org/" + download_file
  79. # and download it
  80. urllib.urlretrieve(amalgamation_url, "tmp.zip")
  81. zf = zipfile.ZipFile("tmp.zip")
  82. files = ["sqlite3.c", "sqlite3.h"]
  83. for fn in files:
  84. print "Extracting", fn
  85. outf = open(AMALGAMATION_ROOT + os.sep + fn, "wb")
  86. outf.write(zf.read(fn))
  87. outf.close()
  88. zf.close()
  89. os.unlink("tmp.zip")
  90. class AmalgamationBuilder(build):
  91. description = "Build a statically built pysqlite using the amalgamtion."
  92. def __init__(self, *args, **kwargs):
  93. MyBuildExt.amalgamation = True
  94. build.__init__(self, *args, **kwargs)
  95. class MyBuildExt(build_ext):
  96. amalgamation = False
  97. def build_extension(self, ext):
  98. if self.amalgamation:
  99. get_amalgamation()
  100. ext.define_macros.append(("SQLITE_ENABLE_FTS3", "1")) # build with fulltext search enabled
  101. ext.sources.append(os.path.join(AMALGAMATION_ROOT, "sqlite3.c"))
  102. ext.include_dirs.append(AMALGAMATION_ROOT)
  103. build_ext.build_extension(self, ext)
  104. def __setattr__(self, k, v):
  105. # Make sure we don't link against the SQLite library, no matter what setup.cfg says
  106. if self.amalgamation and k == "libraries":
  107. v = None
  108. self.__dict__[k] = v
  109. def get_setup_args():
  110. PYSQLITE_VERSION = None
  111. version_re = re.compile('#define PYSQLITE_VERSION "(.*)"')
  112. f = open(os.path.join("src", "module.h"))
  113. for line in f:
  114. match = version_re.match(line)
  115. if match:
  116. PYSQLITE_VERSION = match.groups()[0]
  117. PYSQLITE_MINOR_VERSION = ".".join(PYSQLITE_VERSION.split('.')[:2])
  118. break
  119. f.close()
  120. if not PYSQLITE_VERSION:
  121. print "Fatal error: PYSQLITE_VERSION could not be detected!"
  122. sys.exit(1)
  123. data_files = [("pysqlite2-doc",
  124. glob.glob("doc/*.html") \
  125. + glob.glob("doc/*.txt") \
  126. + glob.glob("doc/*.css")),
  127. ("pysqlite2-doc/code",
  128. glob.glob("doc/code/*.py"))]
  129. py_modules = ["sqlite"]
  130. setup_args = dict(
  131. name = "pysqlite",
  132. version = PYSQLITE_VERSION,
  133. description = "DB-API 2.0 interface for SQLite 3.x",
  134. long_description=long_description,
  135. author = "Gerhard Haering",
  136. author_email = "gh@ghaering.de",
  137. license = "zlib/libpng license",
  138. platforms = "ALL",
  139. url = "http://oss.itsystementwicklung.de/trac/pysqlite",
  140. download_url = "http://oss.itsystementwicklung.de/download/pysqlite/%s/%s/" % \
  141. (PYSQLITE_MINOR_VERSION, PYSQLITE_VERSION),
  142. # Description of the modules and packages in the distribution
  143. package_dir = {"pysqlite2": "pysqlite2"},
  144. packages = ["pysqlite2", "pysqlite2.test"],
  145. scripts=[],
  146. data_files = data_files,
  147. ext_modules = [Extension( name="pysqlite2._sqlite",
  148. sources=sources,
  149. include_dirs=include_dirs,
  150. library_dirs=library_dirs,
  151. runtime_library_dirs=runtime_library_dirs,
  152. libraries=libraries,
  153. extra_objects=extra_objects,
  154. define_macros=define_macros
  155. )],
  156. classifiers = [
  157. "Development Status :: 5 - Production/Stable",
  158. "Intended Audience :: Developers",
  159. "License :: OSI Approved :: zlib/libpng License",
  160. "Operating System :: MacOS :: MacOS X",
  161. "Operating System :: Microsoft :: Windows",
  162. "Operating System :: POSIX",
  163. "Programming Language :: C",
  164. "Programming Language :: Python",
  165. "Topic :: Database :: Database Engines/Servers",
  166. "Topic :: Software Development :: Libraries :: Python Modules"],
  167. cmdclass = {"build_docs": DocBuilder}
  168. )
  169. setup_args["cmdclass"].update({"build_docs": DocBuilder, "build_ext": MyBuildExt, "build_static": AmalgamationBuilder, "cross_bdist_wininst": cross_bdist_wininst.bdist_wininst})
  170. return setup_args
  171. def main():
  172. setup(**get_setup_args())
  173. if __name__ == "__main__":
  174. main()