[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[augeas-devel] Python 3 support for Augeas?



To what extent has anyone tried python-augeas with Python 3?

I've experimented with Python 3 with the python-augeas-0.3.0 tarball.

I had to apply a patch (attached) to remove the (apparently unused)
PyFile_AsFile hook, which doesn't exist anymore in Python 3.

With that patch, I fooled myself into thinking that 0.3.0 was working
with python3 (having run 2to3 on the sources after patching; this is why
I copied them to the directory named
"python3-python-augeas-0.3.0-5.fc13" below):

[david f13 F-13]$ python3
python3-python-augeas-0.3.0-5.fc13/test/test_augeas.py 
test01Get (__main__.TestAugeas)
test aug_get ... ok
test02Match (__main__.TestAugeas)
test aug_match ... ok
test03PrintAll (__main__.TestAugeas)
print all tree elements ... ok
test04Grub (__main__.TestAugeas)
test default setting of grub entry ... ERROR

======================================================================
ERROR: test04Grub (__main__.TestAugeas)
test default setting of grub entry
----------------------------------------------------------------------
Traceback (most recent call last):
  File "python3-python-augeas-0.3.0-5.fc13/test/test_augeas.py", line
66, in test04Grub
    default = int(a.get("/files/etc/grub.conf/default"))
TypeError: int() argument must be a string or a number, not 'NoneType'

----------------------------------------------------------------------
Ran 4 tests in 0.927s

FAILED (errors=1)

The failure above seems to be a permissions error trying to open
"/etc/grub.conf" as non-root; I didn't dare running it as root.

However, on closer examination I realized that there are some deeper
issues:  the code uses ctypes to convert from "str" and "int" to "char*"
and "int", but the former two types change internally from
PyStringObject and PyIntObject to PyUnicodeObject and PyLongObject.

This is probably fixable, but a deeper issue is:  what is the
expectation around the encoding of a string value in augeas?  Is it a
collection of bytes, or is it a unicode string with some encoding?

(it also suggests that the selftests may need to be stricter, given how
far they seemed to get, whilst the code I'd generated was apparently
totally broken :( )

Hope this is helpful
Dave
diff -up python-augeas-0.3.0/augeas.py.fix_py3k python-augeas-0.3.0/augeas.py
--- python-augeas-0.3.0/augeas.py.fix_py3k	2010-04-05 13:59:33.128856797 -0400
+++ python-augeas-0.3.0/augeas.py	2010-04-05 13:59:48.527811265 -0400
@@ -53,12 +53,10 @@ def _dlopen(*args):
 class Augeas(object):
     "Class wrapper for the augeas library"
 
-    # Load libpython (for 'PyFile_AsFile()' and 'PyMem_Free()')
+    # Load libpython (for 'PyMem_Free()')
     # pylint: disable-msg=W0142
     _libpython = _dlopen(*["python" + v % _pyver[:2] 
                            for v in ("%d.%d", "%d%d")])
-    _libpython.PyFile_AsFile.restype = ctypes.c_void_p
-
     # Load libaugeas
     _libaugeas = _dlopen("augeas")
     _libaugeas.aug_init.restype = ctypes.c_void_p

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]