Merge lp:~xnox/apparmor/py3 into lp:apparmor/2.12
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 2052 | ||||
Proposed branch: | lp:~xnox/apparmor/py3 | ||||
Merge into: | lp:apparmor/2.12 | ||||
Diff against target: |
420 lines (+79/-60) 8 files modified
common/Make.rules (+15/-0) libraries/libapparmor/m4/ac_python_devel.m4 (+22/-24) utils/Makefile (+2/-4) utils/aa-easyprof (+2/-2) utils/apparmor/easyprof.py (+15/-10) utils/test/test-aa-easyprof.py (+4/-3) utils/vim/Makefile (+4/-1) utils/vim/create-apparmor.vim.py (+15/-16) |
||||
To merge this branch: | bzr merge lp:~xnox/apparmor/py3 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jamie Strandboge | Approve | ||
Adam Conrad (community) | Approve | ||
Canonical Foundations Team | Pending | ||
AppArmor Developers | Pending | ||
Review via email: mp+109682@code.launchpad.net |
Description of the change
This is a complete port to make apparmor Python2/Python3 bilingual.
There are 3 variables in use:
PYTHON, used by common/Make.rule and libapparmor configure script pointing to a python interpreter
PYTHON_VERSION, used by libapparmor configure script with just version number e.g. '3.2' or '2.7'
PYTHON_VERSIONS, list of all pythons to run checks/tests with for python utilities e.g. 'python2 python3'
If none are specified, defaults will be autodetected to:
PYTHON=
PYTHON=
PYTHON_VERSION=2.7
PYTHON_
To build libapparmor (including the python swig bindings) with python3 it seems like you must set these two variables:
PYTHON=
PYTHON_VERSIONS=3.2
All test and check targets pass and build succeeds.
Scripts are functional.
Swig python module can import and doesn't segfault in smoke testing.
TODO:
/usr/bin/
ac_python_devel patch should probably be submitted to autoconf-archive (updating it's ax_python_devel), not sure about the install location as historically a*_python_devel installs into site-packages, instead of dist-packages.
On Jun 11, 2012, at 05:04 PM, Dmitrijs Ledkovs wrote:
>Dmitrijs Ledkovs has proposed merging lp:~dmitrij.ledkov/apparmor/py3 into lp:apparmor. foundations) /code.launchpad .net/~dmitrij. ledkov/ apparmor/ py3/+merge/ 109682 VERSIONS= python2 before running check/test targets.
>
>Requested reviews:
> Canonical Foundations Team (canonical-
> AppArmor Developers (apparmor-dev)
>
>For more details, see:
>https:/
>
>Initial port to python3 for utilities.
>
>Python2 compatibility is not broken, all code should be 'bilingual'.
>
>Adds helpers in the Make.rules to detect python2 and/or python3.
>
>Runs test and check targets with both pythons, if available.
>
>Python3 is entirely optional with these changes, but the test/check targets will fail if python3 incompatible code is introduced and python3 is available during build. If you do not want the build to fail export PYTHON_
>
>Currently the install defaults to python2, with fallback to python3
>
>This does not have anything to do with swig python binding.
=== modified file 'utils/ apparmor/ easyprof. py' easyprof. py 2012-05-08 05:37:48 +0000 easyprof. py 2012-06-11 17:03:23 +0000 Popen(command, stdout= subprocess. PIPE, subprocess. STDOUT)
--- utils/apparmor/
+++ utils/apparmor/
> @@ -70,7 +70,8 @@
> try:
> sp = subprocess.
> stderr=
> - except OSError, ex:
> + except OSError:
> + ex = sys.exc_info()[1]
> return [127, str(ex)]
I think in general, a better way of doing this would be to change the except
line to
except OSError as ex:
> @@ -181,7 +183,8 @@ mkstemp( prefix= 'aa-easyprof' )
> fn = policy
> else:
> f, fn = tempfile.
> - os.write(f, policy)
> + policy_bytes = bytes(policy, 'utf-8') if sys.version > '3' else policy
> + os.write(f, policy_bytes)
I generally don't like version checks unless there's no other way. In this
case, you could do something like this instead:
if not isinstance(policy, bytes): encode( 'utf-8' )
policy = policy.
=== modified file 'utils/ test/test- aa-easyprof. py' test-aa- easyprof. py 2012-05-09 18:05:07 +0000 test-aa- easyprof. py 2012-06-11 17:03:23 +0000 exists( self.tmpdir) : write(" %s\n" % self.tmpdir) rm(self. tmpdir)
--- utils/test/
+++ utils/test/
> @@ -101,6 +101,7 @@
> def tearDown(self):
> '''Teardown for tests'''
> if os.path.
> + sys.stdout.
> recursive_
>
> #
Why did you decide against using print(). I'm sure there's a good reason, but
it might be useful in at least some of these cases to explain in comments why
sys.stdout.write() is being used instead of print(). Otherwise, when the next
person comes along they probably won't understand why this idiom was chosen.