You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.9 KiB

  1. From 712c2028568df7760bc98d95577e35709078bfea 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. ---
  18. augeas/__init__.py | 2 +-
  19. augeas/ffi.py | 27 ++++++++++++++++++++++-----
  20. setup.py | 1 +
  21. 3 files changed, 24 insertions(+), 6 deletions(-)
  22. --- a/augeas/__init__.py
  23. +++ b/augeas/__init__.py
  24. @@ -32,7 +32,7 @@ format and the transformation into a tre
  25. from sys import version_info as _pyver
  26. -from augeas.ffi import ffi, lib
  27. +from _augeas import ffi, lib
  28. __author__ = "Nathaniel McCallum <nathaniel@natemccallum.com>"
  29. __credits__ = """Jeff Schroeder <jeffschroeder@computer.org>
  30. --- a/augeas/ffi.py
  31. +++ b/augeas/ffi.py
  32. @@ -1,9 +1,28 @@
  33. +import os
  34. +import subprocess
  35. +
  36. from cffi import FFI
  37. +def get_include_dirs():
  38. + XML2_CONFIG = os.environ.get('XML2_CONFIG', 'xml2-config')
  39. + PKG_CONFIG = os.environ.get('PKG_CONFIG', 'pkg-config')
  40. + try:
  41. + stdout = subprocess.check_output([XML2_CONFIG, '--cflags'])
  42. + except (OSError, subprocess.CalledProcessError):
  43. + try:
  44. + stdout = subprocess.check_output([PKG_CONFIG, '--cflags', 'libxml-2.0'])
  45. + except (OSError, subprocess.CalledProcessError):
  46. + stdout = b''
  47. + cflags = stdout.decode('utf-8').split()
  48. + return [cflag[2:] for cflag in cflags if cflag.startswith('-I')]
  49. +
  50. ffi = FFI()
  51. -ffi.set_source("augeas",
  52. - None,
  53. - libraries=['augeas'])
  54. +ffi.set_source("_augeas",
  55. + """
  56. + #include <augeas.h>
  57. + """,
  58. + libraries=['augeas'],
  59. + include_dirs=get_include_dirs())
  60. ffi.cdef("""
  61. typedef struct augeas augeas;
  62. @@ -44,7 +63,5 @@ const char *aug_error_details(augeas *au
  63. void free(void *);
  64. """)
  65. -lib = ffi.dlopen("augeas")
  66. -
  67. if __name__ == "__main__":
  68. ffi.compile(verbose=True)
  69. --- a/setup.py
  70. +++ b/setup.py
  71. @@ -22,6 +22,7 @@ setup(name=name,
  72. setup_requires=["cffi>=1.0.0"],
  73. cffi_modules=["augeas/ffi.py:ffi"],
  74. install_requires=["cffi>=1.0.0"],
  75. + zip_safe=False,
  76. url="http://augeas.net/",
  77. classifiers=[
  78. "Programming Language :: Python :: 2.7",