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