0001-Use-CFFI-in-out-of-line-API-mode-49.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. From 9de73fefbe83c74840a93c039258845c49271b9b Mon Sep 17 00:00:00 2001
  2. From: Jeffery To <jeffery.to@gmail.com>
  3. Date: Sun, 8 Nov 2020 21:51:09 +0800
  4. Subject: [PATCH] Use CFFI in out-of-line API mode (#49)
  5. Currently, ffi.py is called during setup to generate augeas.py; this
  6. file would normally be used for out-of-line ABI mode. ffi.py is also
  7. imported at run-time, instead of the generated augeas.py, and used in
  8. in-line ABI mode.
  9. This changes usage of CFFI to out-of-line API mode (CFFI's "main mode of
  10. usage"): ffi.py is called during setup to generate _augeas.abi3.so (a C
  11. extension module); this generated module is imported at run-time.
  12. With this change, the headers/development files for augeas (i.e.
  13. libaugeas-dev on Debian, augeas-devel on Fedora, etc.) and the C
  14. compiler are required for build/setup. (These were not necessary
  15. previously.)
  16. Closes https://github.com/hercules-team/python-augeas/issues/48.
  17. Upstream: commit 712c2028568df7760bc98d95577e35709078bfea
  18. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  19. ---
  20. augeas/__init__.py | 2 +-
  21. augeas/ffi.py | 27 ++++++++++++++++++++++-----
  22. setup.py | 1 +
  23. 3 files changed, 24 insertions(+), 6 deletions(-)
  24. diff --git a/augeas/__init__.py b/augeas/__init__.py
  25. index 9bd97bf..1c0f580 100644
  26. --- a/augeas/__init__.py
  27. +++ b/augeas/__init__.py
  28. @@ -32,7 +32,7 @@ format and the transformation into a tree.
  29. from sys import version_info as _pyver
  30. -from augeas.ffi import ffi, lib
  31. +from _augeas import ffi, lib
  32. __author__ = "Nathaniel McCallum <nathaniel@natemccallum.com>"
  33. __credits__ = """Jeff Schroeder <jeffschroeder@computer.org>
  34. diff --git a/augeas/ffi.py b/augeas/ffi.py
  35. index a24daf5..1931764 100644
  36. --- a/augeas/ffi.py
  37. +++ b/augeas/ffi.py
  38. @@ -1,9 +1,28 @@
  39. +import os
  40. +import subprocess
  41. +
  42. from cffi import FFI
  43. +def get_include_dirs():
  44. + XML2_CONFIG = os.environ.get('XML2_CONFIG', 'xml2-config')
  45. + PKG_CONFIG = os.environ.get('PKG_CONFIG', 'pkg-config')
  46. + try:
  47. + stdout = subprocess.check_output([XML2_CONFIG, '--cflags'])
  48. + except (OSError, subprocess.CalledProcessError):
  49. + try:
  50. + stdout = subprocess.check_output([PKG_CONFIG, '--cflags', 'libxml-2.0'])
  51. + except (OSError, subprocess.CalledProcessError):
  52. + stdout = b''
  53. + cflags = stdout.decode('utf-8').split()
  54. + return [cflag[2:] for cflag in cflags if cflag.startswith('-I')]
  55. +
  56. ffi = FFI()
  57. -ffi.set_source("augeas",
  58. - None,
  59. - libraries=['augeas'])
  60. +ffi.set_source("_augeas",
  61. + """
  62. + #include <augeas.h>
  63. + """,
  64. + libraries=['augeas'],
  65. + include_dirs=get_include_dirs())
  66. ffi.cdef("""
  67. typedef struct augeas augeas;
  68. @@ -44,7 +63,5 @@ const char *aug_error_details(augeas *aug);
  69. void free(void *);
  70. """)
  71. -lib = ffi.dlopen("augeas")
  72. -
  73. if __name__ == "__main__":
  74. ffi.compile(verbose=True)
  75. diff --git a/setup.py b/setup.py
  76. index 7d55877..17f9516 100755
  77. --- a/setup.py
  78. +++ b/setup.py
  79. @@ -22,6 +22,7 @@ setup(name=name,
  80. setup_requires=["cffi>=1.0.0"],
  81. cffi_modules=["augeas/ffi.py:ffi"],
  82. install_requires=["cffi>=1.0.0"],
  83. + zip_safe=False,
  84. url="http://augeas.net/",
  85. classifiers=[
  86. "Programming Language :: Python :: 2.7",
  87. --
  88. 2.31.1