Re: [apparmor] [patch v2] fix python LibAppArmor import failures with swig > 3.0.8

2016-09-30 Thread Christian Boltz
Hello,

Am Dienstag, 20. September 2016, 11:45:23 CEST schrieb Steve Beattie:
> On Wed, Sep 14, 2016 at 11:32:06PM +0200, Christian Boltz wrote:
...
> > 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.

Oops. I have to admit that I only tested with py3, because that's what I 
actually use (both for myself and in the openSUSE packages).

> 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. 

Given the, well, limited amount of answers on the swig mailinglist, this 
doesn't really surprise me.

> So as far as I can see, a
> variant of the import * solution will have to suffice, as follows:
...
> --- /dev/null
> +++ b/libraries/libapparmor/swig/python/__init__.py
> @@ -0,0 +1,6 @@
> +import sys
> +
> +if sys.version_info[0] > 3:

As already mentioned on IRC some days ago, this is very future-proof ;-)
Your condition will match for python 4 and newer, but not for python 3.

> +from LibAppArmor.LibAppArmor import *
> +else:
> +from .LibAppArmor import *

It seems the line in the else branch works for py2 and py3, so why not 
simplify the file to "from .LibAppArmor import *"?

> > > 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.

I'd still expect to have a make target that *really* cleans everything 
instead of "just" most files - but that's a different topic ;-) and not 
related to this patch.


Regards,

Christian Boltz
-- 
Sagt mal ehrlich: Ist mein Rechner geisteskrank
[Harald Katzer in suse-linux]


signature.asc
Description: This is a digitally signed message part.
-- 
AppArmor mailing list
AppArmor@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/apparmor


Re: [apparmor] [patch v2] fix python LibAppArmor import failures with swig > 3.0.8

2016-09-20 Thread Steve Beattie
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

http://NxNW.org/~steve/


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