Bug 582006 - RFE: add libselinux-python3 subpackage to build
Summary: RFE: add libselinux-python3 subpackage to build
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: libselinux
Version: rawhide
Hardware: All
OS: Linux
low
medium
Target Milestone: ---
Assignee: Thomas Liu
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 582007
TreeView+ depends on / blocked
 
Reported: 2010-04-13 20:03 UTC by Dave Malcolm
Modified: 2010-07-02 17:42 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2010-07-02 17:42:00 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
Patch to devel's libselinux.spec to add a python3 subpackage (5.59 KB, patch)
2010-04-26 17:46 UTC, Dave Malcolm
no flags Details | Diff
Patch to src/Makefile (2.30 KB, patch)
2010-04-26 17:50 UTC, Dave Malcolm
no flags Details | Diff
Patch to generalize audit2why.c so that it can be built against both python 2.* and 3.* (1.79 KB, patch)
2010-04-26 17:52 UTC, Dave Malcolm
no flags Details | Diff
Fix handling of bad args to audit2why.init (733 bytes, patch)
2010-04-26 17:57 UTC, Dave Malcolm
no flags Details | Diff
Change various parts of the python swig code to use "bytes" not "string" (1.97 KB, patch)
2010-04-26 17:59 UTC, Dave Malcolm
no flags Details | Diff
Patch to src/Makefile, supplying defaults for PYTHON and PYPREFIX (2.54 KB, patch)
2010-04-27 20:16 UTC, Dave Malcolm
no flags Details | Diff
Patch to devel's libselinux.spec to add a python3 subpackage (renaming one of the patches) (5.18 KB, patch)
2010-04-27 20:18 UTC, Dave Malcolm
no flags Details | Diff
Patch to generalize audit2why.c so that it can be built against both python 2.* and 3.* (using PyUnicode for py3k) (1.79 KB, patch)
2010-04-27 20:20 UTC, Dave Malcolm
no flags Details | Diff
Change various parts of the python swig code to use "PyUnicode"for python3 and "PyString" for python2 (2.41 KB, patch)
2010-04-27 20:22 UTC, Dave Malcolm
no flags Details | Diff
Revised version of patch for python swig code to use "PyUnicode"for python3 and "PyString" for python2 (2.96 KB, patch)
2010-05-07 21:10 UTC, Dave Malcolm
no flags Details | Diff
Revised version of specfile patch (5.18 KB, patch)
2010-05-07 21:13 UTC, Dave Malcolm
no flags Details | Diff

Description Dave Malcolm 2010-04-13 20:03:53 UTC
Please can you add a libselinux-python3 subpackage to the build.

As I understand it SWIG from F11 onwards can generate both Python 2 and Python 3 code, you just have to point it at the correct /usr/bin/python or python3 binary

An example of generalizing a specfile to build two different subpackages can be seen at bug 536948

with this diff:
http://cvs.fedoraproject.org/viewvc/rpms/python-coverage/devel/python-coverage.spec?r1=1.7&r2=1.8

Notes on packaging can be seen here http://fedoraproject.org/wiki/Packaging/Python

Comment 1 Dave Malcolm 2010-04-26 17:46:43 UTC
Created attachment 409243 [details]
Patch to devel's libselinux.spec to add a python3 subpackage

Comment 2 Dave Malcolm 2010-04-26 17:50:12 UTC
Created attachment 409244 [details]
Patch to src/Makefile

Patch generalizes build to _require_ a PYTHON envvar to be set, pointing at a python runtime, and a PYPREFIX envvar, so that we can build the Python bindings multiple times, once for each Python runtime (in our case, python2.6 and python3.1).  

This is used by the libselinux.spec file.  As it stands, this will break the build for people building outside of RPM, as it requires the two env vars to exist.

I guess we could supply defaults:
PYTHON=python
PYPREFIX=   
(empty)

Comment 3 Dave Malcolm 2010-04-26 17:52:58 UTC
Created attachment 409245 [details]
Patch to generalize audit2why.c so that it can be built against both python 2.* and 3.*

Mostly just changes to module-initialization logic.  See:
http://wiki.python.org/moin/PortingExtensionModulesToPy3k#module-initialization-and-state

Comment 4 Dave Malcolm 2010-04-26 17:57:21 UTC
Created attachment 409246 [details]
Fix handling of bad args to audit2why.init

This isn't part of python3 porting, but fixes a compiler warning:
PyArg_ParseTuple can fail, if the input doesn't match what was expected (e.g. if the user passes an argument that isn't a string e.g. a list), and returns NULL when this happens, setting the global exception state for the current thread, and leaving "result" uninitialized.

Comment 5 Dave Malcolm 2010-04-26 17:59:41 UTC
Created attachment 409247 [details]
Change various parts of the python swig code to use "bytes" not "string"

This will work with Python 2.6 onwards, and Python 3.*

In 2.6 and 2.7, PyBytes_* is a set of #defines for PyString_*

In 3.*, PyBytes_* is the new name for the PyString_ API, but they are a "bytes" type, with no encoding.  Literals have a 'b' prefix.

Comment 6 Dave Malcolm 2010-04-26 18:01:15 UTC
I've got this to compile against Python 3, but it took a lot more effort than I was hoping.

It wasn't clear to me whether the names of booleans and of constants can contain non-ASCII characters, so I took the conservative approach of representing them as "bytes" instances, rather than (unicode) "str" instances.  I can redo things using "str" if we can rely on them being ASCII.

The result works, under light testing, but I haven't tried "serious" testing:
[david@surprise devel]$ rpm -q libselinux-python3
libselinux-python3-2.0.92-2.fc14.x86_64
[david@surprise devel]$ python3
Python 3.1.2 (r312:79147, Mar 21 2010, 16:44:26) 
[GCC 4.4.3 20100127 (Red Hat 4.4.3-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import selinux
>>> selinux.is_selinux_enabled()
1
>>> selinux.is_selinux_mls_enabled()
1
>>> selinux.avc_av_stats()
uavc:  0 AV entries and 0/512 buckets used, longest chain length 0
>>> selinux.get_default_context('foo', 'bar')
[-1, None]
>>> selinux.security_get_boolean_names()
[0, [b'allow_console_login', b'allow_cvs_read_shadow', b'allow_daemons_dump_core', b'allow_daemons_use_tty', b'allow_domain_fd_use', b'allow_execheap', b'allow_execmem', b'allow_execmod', b'allow_execstack', b'allow_ftpd_anon_write', b'allow_ftpd_full_access', 
(etc; note that these are bytes, not strings)

Comment 7 Dave Malcolm 2010-04-27 20:16:56 UTC
Created attachment 409578 [details]
Patch to src/Makefile, supplying defaults for PYTHON and PYPREFIX

Comment 8 Dave Malcolm 2010-04-27 20:18:40 UTC
Created attachment 409579 [details]
Patch to devel's libselinux.spec to add a python3 subpackage (renaming one of the patches)

Comment 9 Dave Malcolm 2010-04-27 20:20:39 UTC
Created attachment 409580 [details]
Patch to generalize audit2why.c so that it can be built against both python 2.* and 3.*  (using PyUnicode for py3k)

Comment 10 Dave Malcolm 2010-04-27 20:22:14 UTC
Created attachment 409581 [details]
Change various parts of the python swig code to use "PyUnicode"for python3 and "PyString" for python2

Comment 11 Dave Malcolm 2010-04-27 20:25:29 UTC
I've updated things to use PyUnicode for throughout within Python 3 for contexts and boolean names.  Swig appears to have already been doing this, using UTF8 internally.

I've rebuilt local test packages of "devel" on this F-12 x86_64 system (with a local build of python3) and tested lightly; the python3 bindings appear to work:

[david@surprise devel]$ rpm -q libselinux-python3
libselinux-python3-2.0.92-2.fc14.x86_64
[david@surprise devel]$ python3
Python 3.1.2 (r312:79147, Mar 21 2010, 16:44:26) 
[GCC 4.4.3 20100127 (Red Hat 4.4.3-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import selinux
>>> selinux.is_selinux_enabled()
1
>>> selinux.is_selinux_mls_enabled()
1
>>> selinux.avc_av_stats()
uavc:  0 AV entries and 0/512 buckets used, longest chain length 0
>>> selinux.get_default_context('foo', 'bar')
[-1, None]
>>> selinux.security_get_boolean_names()
[0, ['allow_console_login', 'allow_cvs_read_shadow', 'allow_daemons_dump_core', 'allow_daemons_use_tty', 'allow_domain_fd_use', 'allow_execheap', 'allow_execmem', 'allow_execmod', 'allow_execstack', 'allow_ftpd_anon_write', 'allow_ftpd_full_access', 'allow_ftpd_use_cifs', 'allow_ftpd_use_nfs', 'allow_gssd_read_tmp', 
(snip; note the use of strings, not bytes)
>>> selinux.getfilecon('/')
[28, 'system_u:object_r:root_t:s0']


I haven't thoroughly tested it though.

Comment 12 Dave Malcolm 2010-05-07 21:10:25 UTC
Created attachment 412449 [details]
Revised version of patch for python swig code to use "PyUnicode"for python3 and "PyString" for python2

I've revised this typemap code to use SWIG's internal python API for converting between Python and C string values

Comment 13 Dave Malcolm 2010-05-07 21:13:13 UTC
Created attachment 412450 [details]
Revised version of specfile patch

I slightly revised the specfile patch, removing a stray ".patch" suffix from the -b parameter to %patch5

Comment 14 Dave Malcolm 2010-05-07 21:14:37 UTC
Dan:  I've lightly tested a build of this with both Python 2.6 and Python 3.1 on Fedora 13.  I believe it's ready for your review.

Comment 15 Dave Malcolm 2010-07-02 17:42:00 UTC
Appears to be fixed in rawhide as of libselinux-2.0.96-1


Note You need to log in before you can comment on or make changes to this bug.