Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Sun, 28 Feb 2016 03:49:51 UTC Commit: 00f0ce5991098ed0533e7577c18eb5b402c6be63 https://github.com/geany/geany/commit/00f0ce5991098ed0533e7577c18eb5b402c6be...
Log Message: ----------- PEP8 the GtkDoc header generator script a little
But use 110 as line length and leave visual operators alignment alone.
Modified Paths: -------------- scripts/gen-api-gtkdoc.py
Modified: scripts/gen-api-gtkdoc.py 48 lines changed, 27 insertions(+), 21 deletions(-) =================================================================== @@ -6,6 +6,7 @@ from lxml import etree from optparse import OptionParser
+ def normalize_text(s): r""" Normalizes whitespace in text. @@ -17,6 +18,7 @@ def normalize_text(s): """ return s.replace("\n", " ").strip()
+ CXX_NAMESPACE_RE = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*::') def fix_definition(s): """ @@ -32,10 +34,10 @@ def fix_definition(s): 'void(* project_open) (GKeyFile *keyfile)'
""" - return CXX_NAMESPACE_RE.sub(r"", s); + return CXX_NAMESPACE_RE.sub(r"", s)
-class AtAt(object):
+class AtAt(object): def __init__(self): self.retval = None self.since = "" @@ -44,6 +46,7 @@ def __init__(self): def cb(type, str): return "@%s %s" % (type, str)
+ class AtDoc(object): def __init__(self): self.retval = None @@ -52,7 +55,7 @@ def __init__(self):
def cb(self, type, str): if (type == "param"): - words = str.split(" ", 2); + words = str.split(" ", 2) self.annot = [] elif (type == "return"): self.annot = [] @@ -70,22 +73,24 @@ def cb(self, type, str): "geany:scope"): type = type.split(":")[1] self.annot.append("%s %s" % (type, str)) - elif (type == "see"): + elif (type == "see"): return "See " + str elif type in ("a", "c") and str in ("NULL", "TRUE", "FALSE"): # FIXME: some of Geany does @a NULL instead of @c NULL return "%" + str - elif (type == "a"): + elif (type == "a"): return "@" + str else: return str
return ""
+ class At(object): def __init__(self, cb): self.cb = cb
+ class DoxygenProcess(object): def __init__(self): self.at = None @@ -96,8 +101,8 @@ def stringify_children(node): from lxml.etree import tostring from itertools import chain parts = ([node.text] + - list(chain(*([c.text, tostring(c).decode("utf-8"), c.tail] for c in node.getchildren()))) + - [node.tail]) + list(chain(*([c.text, tostring(c).decode("utf-8"), c.tail] for c in node.getchildren()))) + + [node.tail]) # filter removes possible Nones in texts and tails return "".join(filter(None, parts))
@@ -176,11 +181,12 @@ def __process_element(self, xml): if n.tail: s += n.tail if n.tag.startswith("param"): - pass # parameters are handled separately in DoxyFunction::from_memberdef() + pass # parameters are handled separately in DoxyFunction::from_memberdef() return s
+ class DoxyMember(object): - def __init__(self, name, brief, extra = ""): + def __init__(self, name, brief, extra=""): self.name = name self.brief = brief self.extra = extra @@ -234,7 +240,7 @@ def add_return(self, xml): self.retval = DoxyMember("ret", normalize_text(brief), proc.get_extra())
def to_gtkdoc(self): - s = [] + s = [] s.append("/**") s.append(" * %s: %s" % (self.name, self.extra)) for p in self.members: @@ -253,8 +259,8 @@ def to_gtkdoc(self): s.append("") return "\n".join(s)
-class DoxyTypedef(DoxyElement):
+class DoxyTypedef(DoxyElement): @staticmethod def from_memberdef(xml): name = xml.find("name").text @@ -262,15 +268,15 @@ def from_memberdef(xml): d += ";" return DoxyTypedef(name, d)
-class DoxyEnum(DoxyElement):
+class DoxyEnum(DoxyElement): @staticmethod def from_memberdef(xml): name = xml.find("name").text d = "typedef enum {\n" for member in xml.findall("enumvalue"): v = member.find("initializer") - d += "\t%s%s,\n" % ( member.find("name").text, " "+v.text if v is not None else "") + d += "\t%s%s,\n" % (member.find("name").text, " "+v.text if v is not None else "") d += "} %s;\n" % name
e = DoxyEnum(name, d) @@ -279,13 +285,13 @@ def from_memberdef(xml): e.add_member(p) return e
-class DoxyStruct(DoxyElement):
+class DoxyStruct(DoxyElement): @staticmethod - def from_compounddef(xml, typedefs = []): + def from_compounddef(xml, typedefs=[]): name = xml.find("compoundname").text section = xml.find("sectiondef") - d = "struct %s {\n" % name; + d = "struct %s {\n" % name for p in section.findall("memberdef"): # workaround for struct members. g-ir-scanner can't properly map struct members # (beginning with struct GeanyFoo) to the typedef and assigns a generic type for them @@ -310,8 +316,8 @@ def from_compounddef(xml, typedefs = []): e.add_member(p) return e
-class DoxyFunction(DoxyElement):
+class DoxyFunction(DoxyElement): @staticmethod def from_memberdef(xml): name = xml.find("name").text @@ -329,18 +335,18 @@ def from_memberdef(xml): e.add_return(x[0]) return e
-def main(args):
+def main(args): xml_dir = None outfile = None
parser = OptionParser(usage="usage: %prog [options] XML_DIR") parser.add_option("--xmldir", metavar="DIRECTORY", help="Path to Doxygen-generated XML files", - action="store", dest="xml_dir") + action="store", dest="xml_dir") parser.add_option("-d", "--outdir", metavar="DIRECTORY", help="Path to Doxygen-generated XML files", - action="store", dest="outdir", default=".") + action="store", dest="outdir", default=".") parser.add_option("-o", "--output", metavar="FILE", help="Write output to FILE", - action="store", dest="outfile") + action="store", dest="outfile") opts, args = parser.parse_args(args[1:])
xml_dir = args[0]
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).