setup.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. chunker_source = 'darc/chunker.pyx'
  20. hashindex_source = 'darc/hashindex.pyx'
  21. try:
  22. from Cython.Distutils import build_ext
  23. import Cython.Compiler.Main as cython_compiler
  24. class Sdist(sdist):
  25. def __init__(self, *args, **kwargs):
  26. for src in glob('darc/*.pyx'):
  27. cython_compiler.compile(glob('darc/*.pyx'),
  28. cython_compiler.default_options)
  29. sdist.__init__(self, *args, **kwargs)
  30. def make_distribution(self):
  31. self.filelist += ['darc/chunker.c', 'darc/chunker.h', 'darc/hashindex.c', 'darc/hashindex.h']
  32. sdist.make_distribution(self)
  33. except ImportError:
  34. chunker_source = chunker_source.replace('.pyx', '.c')
  35. hashindex_source = hashindex_source.replace('.pyx', '.c')
  36. from distutils.command.build_ext import build_ext
  37. Sdist = sdist
  38. if not os.path.exists(chunker_source) or not os.path.exists(hashindex_source):
  39. raise ImportError('The GIT version of darc needs Cython. Install Cython or use a released version')
  40. setup(name='darc',
  41. version=darc.__version__,
  42. author='Jonas Borgström',
  43. author_email='jonas@borgstrom.se',
  44. url='http://github.com/jborg/darc/',
  45. packages=['darc'],
  46. cmdclass={'build_ext': build_ext, 'sdist': Sdist},
  47. ext_modules=[
  48. Extension('darc.chunker', [chunker_source]),
  49. Extension('darc.hashindex', [hashindex_source])],
  50. scripts=['scripts/darc'],
  51. )