On Wed, Sep 14, 2016 at 11:32:06PM +0200, Christian Boltz wrote:
> Am Mittwoch, 14. September 2016, 12:41:33 CEST schrieb Steve Beattie:
> > Ugh, I *really* don't like the 'from LibAppArmor.LibAppArmor import *'
> > bit.
> 
> Do you have a better solution? ;-)
> 
> I asked about this on the swig-user mailinglist some weeks ago, and this 
> was the best solution I received. Actually it's the only solution I 
> received (besides some more general answers, documentation pointers 
> etc.). An interesting detail is that I received this solution off-list 
> for whatever reason.
> 
> My patch has a big advantage: it works ;-) (and it's already in 
> Tumbleweed and Leap 42.2 beta to un-break the aa-* tools)

Except for where it doesn't, which is python2.7, where the __init__.py
import fails.

I spent some time poking at swig 3.10 trying to get it to work some
other way, but the documentation seems to lie, as I couldn't make swig
generate python code that did a relative import; no amount of futzing
with -relativeimport or -py3 or -modern or setting the package name
in the libapparmor.i seemed to make any difference in the _LibAppArmor
import code generated by swig. So as far as I can see, a variant of the
import * solution will have to suffice, as follows:

---
 .bzrignore                                    |    2 +-
 libraries/libapparmor/swig/python/Makefile.am |    3 +--
 libraries/libapparmor/swig/python/__init__.py |    6 ++++++
 3 files changed, 8 insertions(+), 3 deletions(-)

Index: b/.bzrignore
===================================================================
--- a/.bzrignore
+++ b/.bzrignore
@@ -88,7 +88,7 @@ libraries/libapparmor/swig/perl/MYMETA.y
 libraries/libapparmor/swig/perl/blib
 libraries/libapparmor/swig/perl/libapparmor_wrap.c
 libraries/libapparmor/swig/perl/pm_to_blib
-libraries/libapparmor/swig/python/__init__.py
+libraries/libapparmor/swig/python/LibAppArmor.py
 libraries/libapparmor/swig/python/build/
 libraries/libapparmor/swig/python/libapparmor_wrap.c
 libraries/libapparmor/swig/python/Makefile
Index: b/libraries/libapparmor/swig/python/Makefile.am
===================================================================
--- a/libraries/libapparmor/swig/python/Makefile.am
+++ b/libraries/libapparmor/swig/python/Makefile.am
@@ -6,9 +6,8 @@ SUBDIRS = test
 
 libapparmor_wrap.c: $(srcdir)/../SWIG/libapparmor.i
        $(SWIG) -python -I$(srcdir)/../../include -module LibAppArmor -o $@ 
$(srcdir)/../SWIG/libapparmor.i
-       mv LibAppArmor.py __init__.py
 
-MOSTLYCLEANFILES=libapparmor_wrap.c __init__.py
+MOSTLYCLEANFILES=libapparmor_wrap.c LibAppArmor.py
 
 all-local: libapparmor_wrap.c setup.py
        if test ! -f libapparmor_wrap.c; then cp $(srcdir)/libapparmor_wrap.c . 
; fi
Index: b/libraries/libapparmor/swig/python/__init__.py
===================================================================
--- /dev/null
+++ b/libraries/libapparmor/swig/python/__init__.py
@@ -0,0 +1,6 @@
+import sys
+
+if sys.version_info[0] > 3:
+    from LibAppArmor.LibAppArmor import *
+else:
+    from .LibAppArmor import *

Once we kill python2.7 support, then we can go with the "simple" form of
the __init__.py file.

> > make maintainer-clean, I believe (but it's only supported by the
> > libapparmor subdirectory).
> 
> # make maintainer-clean
> ...
> # bzr ignored | awkcol 1
> libraries/libapparmor/swig/python/Makefile.in          <----------
> 
> So it cleans up a lot, but not everything.
> 
> Needless to say that .../swig/python/Makefile.in contains code from 
> Makefile.am and needs to be updated ;-)

Changes made to Makefile.am will cause autotools to regenerate
Makefile.in.

-- 
Steve Beattie
<sbeat...@ubuntu.com>
http://NxNW.org/~steve/

Attachment: signature.asc
Description: PGP signature

-- 
AppArmor mailing list
AppArmor@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/apparmor

Reply via email to