[augeas-devel] Python 3 support for Augeas?

David Malcolm dmalcolm at redhat.com
Mon Apr 5 18:43:43 UTC 2010


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 at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: python-augeas-0.3.0-fix-py3k.patch
Type: text/x-patch
Size: 756 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20100405/5aeaa926/attachment.bin>


More information about the augeas-devel mailing list