Eolian: don't use the actual eolian obj when generating

This commit is contained in:
Kai Huuhko 2014-06-22 13:27:26 +03:00
parent 9687624f47
commit 0fa41e652d
1 changed files with 31 additions and 17 deletions

View File

@ -80,6 +80,14 @@ return_type_mapping = {
}
def conv_cls_name(name):
s = name.split("_")
if len(s) > 1:
return s[0], "_".join(s[1:])
else:
return name, name
class Generator(object):
tab = " "
@ -195,7 +203,7 @@ class Method(object):
def parse(cls, func, eo_prefix):
self = cls.__new__(cls)
self.__init__(eo_prefix)
self.func = func
#self.func = func
self.py_name = func.name
if keyword.iskeyword(self.py_name):
@ -349,7 +357,9 @@ class Property(object):
def parse(cls, func, eo_prefix):
self = cls.__new__(cls)
self.__init__(eo_prefix)
self.func = func
#self.func = func
self.name = func.name
getter_desc = func.description_get("comment_get")
setter_desc = func.description_get("comment_set")
@ -431,7 +441,7 @@ class Property(object):
return self
def pyx_generate(self, gen):
gen.write("property %s:" % (self.func.name))
gen.write("property %s:" % (self.name))
gen.indent()
gen.docstring_write(self.docs)
@ -512,7 +522,9 @@ class Class(object):
def parse(klass, cls):
self = klass.__new__(klass)
self.__init__()
self.cls = cls
#self.cls = cls
self.lib_name, self.name = conv_cls_name(cls.name)
header_path = cls.filename
if not header_path:
@ -522,7 +534,7 @@ class Class(object):
self.inherits = cls.inherits_list
desc = self.cls.description
desc = cls.description
if desc:
descs = desc.split("\n\n")
for desc in descs:
@ -536,14 +548,14 @@ class Class(object):
self.docs.append("")
for k, v in (
type(self.cls).__dict__.items()
type(cls).__dict__.items()
):
if k.startswith("__") or hasattr(v, "__call__") or \
k == "description":
continue
if k == "events" or k == "implements" or k == "inherits_list":
objs = v.__get__(self.cls)
objs = v.__get__(cls)
if not objs:
continue
self.docs.append(
@ -555,7 +567,7 @@ class Class(object):
)
else:
self.docs.append(
"- %s: %s" % (k, v.__get__(self.cls))
"- %s: %s" % (k, v.__get__(cls))
)
ctors = None
@ -630,7 +642,7 @@ class Class(object):
inherits = ("object", )
inherits = ", ".join(inherits)
gen.write("cdef class _%s(%s):" % (self.cls.name, inherits))
gen.write("cdef class _%s(%s):" % (self.name, inherits))
gen.indent()
gen.docstring_write(self.docs)
@ -652,7 +664,8 @@ class Class(object):
gen.write()
def py_generate(self, gen):
inherits = ["_" + self.cls.name]
inherits = ["_" + self.name]
imports = [(self.lib_name, "_" + self.name)]
for i in self.inherits:
i_cls = eolian.class_find_by_name(i)
if i_cls:
@ -661,24 +674,25 @@ class Class(object):
continue
else:
log.warn("Class %s is unknown" % (i))
inherits.append("_" + i)
l, n = conv_cls_name(i)
inherits.append("_" + n)
imports.append((l, "_" + n))
for i in inherits:
pfix = i.split("_")[1]
m = pfix.lower()
gen.write("from %s import %s" % (m, i))
for l, n in imports:
l = l.lower()
gen.write("from %s import %s" % (l, n))
gen.write()
gen.write()
gen.write("class %s(%s):" % (self.cls.name, ", ".join(inherits)))
gen.write("class %s(%s):" % (self.name, ", ".join(inherits)))
gen.indent()
gen.write("def __init__(self, parent=None, *args, **kwargs):")
gen.indent()
gen.write(
"_%s.__init__(self, parent=None, *args, **kwargs)" % (
self.cls.name
self.name
)
)