setup.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/python3
  2. # encoding: utf-8
  3. # Setup file for dulwich
  4. # Copyright (C) 2008-2022 Jelmer Vernooij <jelmer@jelmer.uk>
  5. from setuptools import setup, Extension, Distribution
  6. import os
  7. import sys
  8. if sys.version_info < (3, 6):
  9. raise Exception(
  10. 'Dulwich only supports Python 3.6 and later. '
  11. 'For 2.7 support, please install a version prior to 0.20')
  12. dulwich_version_string = '0.20.46'
  13. class DulwichDistribution(Distribution):
  14. def is_pure(self):
  15. if self.pure:
  16. return True
  17. def has_ext_modules(self):
  18. return not self.pure
  19. global_options = Distribution.global_options + [
  20. ('pure', None, "use pure Python code instead of C "
  21. "extensions (slower on CPython)")]
  22. pure = False
  23. if sys.platform == 'darwin' and os.path.exists('/usr/bin/xcodebuild'):
  24. # XCode 4.0 dropped support for ppc architecture, which is hardcoded in
  25. # distutils.sysconfig
  26. import subprocess
  27. p = subprocess.Popen(
  28. ['/usr/bin/xcodebuild', '-version'], stdout=subprocess.PIPE,
  29. stderr=subprocess.PIPE, env={})
  30. out, err = p.communicate()
  31. for line in out.splitlines():
  32. line = line.decode("utf8")
  33. # Also parse only first digit, because 3.2.1 can't be parsed nicely
  34. if (line.startswith('Xcode')
  35. and int(line.split()[1].split('.')[0]) >= 4):
  36. os.environ['ARCHFLAGS'] = ''
  37. tests_require = ['fastimport']
  38. if '__pypy__' not in sys.modules and sys.platform != 'win32':
  39. tests_require.extend([
  40. 'gevent', 'geventhttpclient', 'setuptools>=17.1'])
  41. ext_modules = [
  42. Extension('dulwich._objects', ['dulwich/_objects.c']),
  43. Extension('dulwich._pack', ['dulwich/_pack.c']),
  44. Extension('dulwich._diff_tree', ['dulwich/_diff_tree.c']),
  45. ]
  46. setup(keywords="git vcs",
  47. package_data={'': ['../docs/tutorial/*.txt', 'py.typed']},
  48. ext_modules=ext_modules,
  49. distclass=DulwichDistribution, # type: ignore
  50. tests_require=tests_require)