setup.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- encoding: utf-8 *-*
  2. #!/usr/bin/env python
  3. import os
  4. import sys
  5. from glob import glob
  6. import darc
  7. min_python = (3, 2)
  8. if sys.version_info < min_python:
  9. print("Darc requires Python %d.%d or later" % min_python)
  10. sys.exit(1)
  11. try:
  12. import Cython
  13. sys.path.insert(0, os.path.join(os.path.dirname(__file__), "fake_pyrex"))
  14. except ImportError:
  15. pass
  16. from distutils.core import setup
  17. from distutils.extension import Extension
  18. from distutils.command.sdist import sdist
  19. try:
  20. from Cython.Distutils import build_ext
  21. import Cython.Compiler.Main as cython_compiler
  22. class Sdist(sdist):
  23. def __init__(self, *args, **kwargs):
  24. for src in glob('darc/*.pyx'):
  25. cython_compiler.compile(glob('darc/*.pyx'),
  26. cython_compiler.default_options)
  27. sdist.__init__(self, *args, **kwargs)
  28. def make_distribution(self):
  29. self.filelist.append('darc/hashindex.c')
  30. self.filelist.append('darc/hashindex.h')
  31. sdist.make_distribution(self)
  32. except ImportError:
  33. hashindex_sources[0] = hashindex_sources[0].replace('.pyx', '.c')
  34. from distutils.command.build_ext import build_ext
  35. Sdist = sdist
  36. if not os.path.exists('darc/hashindex.c'):
  37. raise ImportError('The GIT version of darc needs Cython. Install Cython or use a released version')
  38. setup(name='darc',
  39. version=darc.__version__,
  40. author='Jonas Borgström',
  41. author_email='jonas@borgstrom.se',
  42. url='http://github.com/jborg/darc/',
  43. packages=['darc'],
  44. cmdclass={'build_ext': build_ext, 'sdist': Sdist},
  45. ext_modules=[
  46. Extension('darc.chunker', ['darc/chunker.pyx']),
  47. Extension('darc.hashindex', ['darc/hashindex.pyx'])],
  48. scripts=['scripts/darc'],
  49. )