2
0

setup.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. 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. # Ideally, setuptools would just provide a way to do this
  28. if "PURE" in os.environ or "--pure" in sys.argv:
  29. if "--pure" in sys.argv:
  30. sys.argv.remove("--pure")
  31. setup_requires = []
  32. rust_extensions = []
  33. else:
  34. setup_requires = ["setuptools_rust"]
  35. # We check for egg_info since that indicates we are running prepare_metadata_for_build_*
  36. if "egg_info" in sys.argv:
  37. rust_extensions = []
  38. else:
  39. from setuptools_rust import Binding, RustExtension
  40. rust_extensions = [
  41. RustExtension(
  42. "dulwich._objects",
  43. "crates/objects/Cargo.toml",
  44. binding=Binding.PyO3,
  45. optional=optional,
  46. ),
  47. RustExtension(
  48. "dulwich._pack",
  49. "crates/pack/Cargo.toml",
  50. binding=Binding.PyO3,
  51. optional=optional,
  52. ),
  53. RustExtension(
  54. "dulwich._diff_tree",
  55. "crates/diff-tree/Cargo.toml",
  56. binding=Binding.PyO3,
  57. optional=optional,
  58. ),
  59. ]
  60. setup(
  61. package_data={"": ["py.typed"]},
  62. rust_extensions=rust_extensions,
  63. setup_requires=setup_requires,
  64. tests_require=tests_require,
  65. )