From f877a6f34c16bc73bccc18073b3512318d49e92c Mon Sep 17 00:00:00 2001 From: David Coles Date: Fri, 8 Apr 2011 16:49:30 -0700 Subject: [PATCH] Use absolute imports in xcbgen for Python 3 compatibility Python 3 has stricter syntax for relative imports. Use absolute imports to ensure compatibility with all versions of Python. Also break cyclical module import between state.py and matcher.py by deferring import. Signed-off-by: David Coles Signed-off-by: Julien Danjou --- xcbgen/matcher.py | 5 +++-- xcbgen/state.py | 6 +++--- xcbgen/xtypes.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/xcbgen/matcher.py b/xcbgen/matcher.py index e7958fa..6e45b23 100644 --- a/xcbgen/matcher.py +++ b/xcbgen/matcher.py @@ -9,14 +9,15 @@ we do not create a new type object, we just record the existing one under a new from os.path import join from xml.etree.cElementTree import parse -import state -from xtypes import * +from xcbgen.xtypes import * def import_(node, module, namespace): ''' For imports, we load the file, create a new namespace object, execute recursively, then record the import (for header files, etc.) ''' + # To avoid circular import error + from xcbgen import state new_file = join(namespace.dir, '%s.xml' % node.text) new_root = parse(new_file).getroot() new_namespace = state.Namespace(new_file) diff --git a/xcbgen/state.py b/xcbgen/state.py index 51efc94..ae3d2d4 100644 --- a/xcbgen/state.py +++ b/xcbgen/state.py @@ -4,9 +4,9 @@ This module contains the namespace class and the singleton module class. from os.path import dirname, basename from xml.etree.cElementTree import parse -import matcher -from error import * -from xtypes import * +from xcbgen import matcher +from xcbgen.error import * +from xcbgen.xtypes import * import __main__ diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py index 1a6c7ce..14c318a 100644 --- a/xcbgen/xtypes.py +++ b/xcbgen/xtypes.py @@ -1,7 +1,7 @@ ''' This module contains the classes which represent XCB data types. ''' -from expr import Field, Expression +from xcbgen.expr import Field, Expression import __main__ class Type(object): -- 2.7.4