2
0

setup.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 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. rust_extensions = [
  29. RustExtension(
  30. "dulwich._objects",
  31. "crates/objects/Cargo.toml",
  32. binding=Binding.PyO3,
  33. optional=optional,
  34. ),
  35. RustExtension(
  36. "dulwich._pack",
  37. "crates/pack/Cargo.toml",
  38. binding=Binding.PyO3,
  39. optional=optional,
  40. ),
  41. RustExtension(
  42. "dulwich._diff_tree",
  43. "crates/diff-tree/Cargo.toml",
  44. binding=Binding.PyO3,
  45. optional=optional,
  46. ),
  47. ]
  48. # Ideally, setuptools would just provide a way to do this
  49. if "--pure" in sys.argv:
  50. sys.argv.remove("--pure")
  51. rust_extensions = []
  52. setup(
  53. package_data={"": ["py.typed"]},
  54. rust_extensions=rust_extensions,
  55. tests_require=tests_require,
  56. )