2
0

setup.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/python3
  2. # Setup file for dulwich
  3. # Copyright (C) 2008-2022 Jelmer Vernooij <jelmer@jelmer.uk>
  4. # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  5. import os
  6. import sys
  7. from setuptools import setup
  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. # Ideally, setuptools would just provide a way to do this
  29. if "PURE" in os.environ or "--pure" in sys.argv:
  30. if "--pure" in sys.argv:
  31. sys.argv.remove("--pure")
  32. setup_requires = []
  33. rust_extensions = []
  34. else:
  35. setup_requires = ["setuptools_rust"]
  36. # We check for egg_info since that indicates we are running prepare_metadata_for_build_*
  37. if "egg_info" in sys.argv:
  38. rust_extensions = []
  39. else:
  40. from setuptools_rust import Binding, RustExtension
  41. rust_extensions = [
  42. RustExtension(
  43. "dulwich._objects",
  44. "crates/objects/Cargo.toml",
  45. binding=Binding.PyO3,
  46. optional=optional,
  47. ),
  48. RustExtension(
  49. "dulwich._pack",
  50. "crates/pack/Cargo.toml",
  51. binding=Binding.PyO3,
  52. optional=optional,
  53. ),
  54. RustExtension(
  55. "dulwich._diff_tree",
  56. "crates/diff-tree/Cargo.toml",
  57. binding=Binding.PyO3,
  58. optional=optional,
  59. ),
  60. ]
  61. setup(
  62. package_data={"": ["py.typed"]},
  63. rust_extensions=rust_extensions,
  64. setup_requires=setup_requires,
  65. tests_require=tests_require,
  66. )