setup.py 1.5 KB

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