setup.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/python3
  2. # Setup file for dulwich
  3. # Copyright (C) 2008-2022 Jelmer Vernooij <jelmer@jelmer.uk>
  4. import os
  5. import sys
  6. from setuptools import Extension, setup
  7. from setuptools_rust import Binding, RustExtension
  8. if sys.platform == "darwin" and os.path.exists("/usr/bin/xcodebuild"):
  9. # XCode 4.0 dropped support for ppc architecture, which is hardcoded in
  10. # distutils.sysconfig
  11. import subprocess
  12. p = subprocess.Popen(
  13. ["/usr/bin/xcodebuild", "-version"],
  14. stdout=subprocess.PIPE,
  15. stderr=subprocess.PIPE,
  16. env={},
  17. )
  18. out, err = p.communicate()
  19. for line in out.splitlines():
  20. line = line.decode("utf8")
  21. # Also parse only first digit, because 3.2.1 can't be parsed nicely
  22. if line.startswith("Xcode") and int(line.split()[1].split(".")[0]) >= 4:
  23. os.environ["ARCHFLAGS"] = ""
  24. tests_require = ["fastimport"]
  25. if "__pypy__" not in sys.modules and sys.platform != "win32":
  26. tests_require.extend(["gevent", "geventhttpclient", "setuptools>=17.1"])
  27. optional = os.environ.get("CIBUILDWHEEL", "0") != "1"
  28. ext_modules = [
  29. Extension("dulwich._pack", ["dulwich/_pack.c"], optional=optional),
  30. Extension("dulwich._diff_tree", ["dulwich/_diff_tree.c"], optional=optional),
  31. ]
  32. rust_extensions = [
  33. RustExtension("dulwich._objects", "crates/objects/Cargo.toml", binding=Binding.PyO3, optional=True),
  34. ]
  35. # Ideally, setuptools would just provide a way to do this
  36. if "--pure" in sys.argv:
  37. sys.argv.remove("--pure")
  38. ext_modules = []
  39. rust_extensions = []
  40. setup(package_data={'': ['../docs/tutorial/*.txt', 'py.typed']},
  41. ext_modules=ext_modules,
  42. rust_extensions=rust_extensions,
  43. tests_require=tests_require)