PageRenderTime 34ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/setup.py

http://github.com/axiak/pyre2
Python | 113 lines | 103 code | 9 blank | 1 comment | 1 complexity | ca71418671ed2f46e1ef61ef6ba7370a MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #!/usr/bin/env python
  2. import sys
  3. import os
  4. import re
  5. from distutils.core import setup, Extension, Command
  6. MINIMUM_CYTHON_VERSION = '0.13'
  7. def cmp(a, b):
  8. return (a > b) - (a < b)
  9. class TestCommand(Command):
  10. description = 'Run packaged tests'
  11. user_options = []
  12. def initialize_options(self):
  13. pass
  14. def finalize_options(self):
  15. pass
  16. def run(self):
  17. from tests import re2_test
  18. re2_test.testall()
  19. def version_compare(version1, version2):
  20. def normalize(v):
  21. return [int(x) for x in re.sub(r'(\.0+)*$','', v).split(".")]
  22. return cmp(normalize(version1), normalize(version2))
  23. cmdclass = {'test': TestCommand}
  24. ext_files = []
  25. if '--cython' in sys.argv[1:]:
  26. # Using Cython
  27. sys.argv.remove('--cython')
  28. from Cython.Compiler.Main import Version
  29. if version_compare(MINIMUM_CYTHON_VERSION, Version.version) > 0:
  30. raise ValueError("Cython is version %s, but needs to be at least %s." %
  31. (Version.version, MINIMUM_CYTHON_VERSION))
  32. from Cython.Distutils import build_ext
  33. cmdclass['build_ext'] = build_ext
  34. ext_files.append("src/re2.pyx")
  35. else:
  36. # Building from C
  37. ext_files.append("src/re2.cpp")
  38. # Locate the re2 module
  39. _re2_prefixes = [
  40. '/usr',
  41. '/usr/local',
  42. '/opt/',
  43. ]
  44. for re2_prefix in _re2_prefixes:
  45. if os.path.exists(os.path.join(re2_prefix, "include", "re2")):
  46. break
  47. else:
  48. re2_prefix = ""
  49. BASE_DIR = os.path.dirname(__file__)
  50. def get_long_description():
  51. readme_f = open(os.path.join(BASE_DIR, "README.rst"))
  52. readme = readme_f.read()
  53. readme_f.close()
  54. return readme
  55. def get_authors():
  56. author_re = re.compile(r'^\s*(.*?)\s+<.*?\@.*?>', re.M)
  57. authors_f = open(os.path.join(BASE_DIR, "AUTHORS"))
  58. authors = [match.group(1) for match in author_re.finditer(authors_f.read())]
  59. authors_f.close()
  60. return ', '.join(authors)
  61. def main():
  62. setup(
  63. name="re2",
  64. version="0.2.23",
  65. description="Python wrapper for Google's RE2 using Cython",
  66. long_description=get_long_description(),
  67. author=get_authors(),
  68. license="New BSD License",
  69. author_email = "mike@axiak.net",
  70. url = "http://github.com/axiak/pyre2/",
  71. ext_modules = [
  72. Extension(
  73. "re2",
  74. ext_files,
  75. language="c++",
  76. include_dirs=[os.path.join(re2_prefix, "include")] if re2_prefix else [],
  77. libraries=["re2"],
  78. extra_compile_args=['-std=c++11'],
  79. library_dirs=[os.path.join(re2_prefix, "lib")] if re2_prefix else [],
  80. runtime_library_dirs=[os.path.join(re2_prefix, "lib")] if re2_prefix else [],
  81. )
  82. ],
  83. cmdclass=cmdclass,
  84. classifiers = [
  85. 'License :: OSI Approved :: BSD License',
  86. 'Programming Language :: Cython',
  87. 'Programming Language :: Python :: 2.5',
  88. 'Programming Language :: Python :: 2.6',
  89. 'Intended Audience :: Developers',
  90. 'Topic :: Software Development :: Libraries :: Python Modules',
  91. ],
  92. )
  93. if __name__ == '__main__':
  94. main()