[gtk-doc] mkdb,rebase,scan: python 2/3 compat for dict.keys()



commit b205fe86f7202019065547fec338577d82971702
Author: Stefan Sauer <ensonic users sf net>
Date:   Fri Jun 2 08:17:08 2017 +0200

    mkdb,rebase,scan: python 2/3 compat for dict.keys()
    
    Fixes #783315

 gtkdoc/mkdb.py    |   32 ++++++++++++++++----------------
 gtkdoc/rebase.py  |    3 ++-
 gtkdoc/scan.py    |    7 +++++--
 tests/tools.sh.in |    2 ++
 4 files changed, 25 insertions(+), 19 deletions(-)
---
diff --git a/gtkdoc/mkdb.py b/gtkdoc/mkdb.py
index 382ee4c..9432cc7 100644
--- a/gtkdoc/mkdb.py
+++ b/gtkdoc/mkdb.py
@@ -24,7 +24,7 @@ Creates the DocBook files from the source comments.
 """
 
 from __future__ import print_function
-from six import iteritems
+from six import iteritems, iterkeys
 
 from collections import OrderedDict
 import logging
@@ -812,7 +812,7 @@ def DetermineNamespace():
     while True:
         prefix = {}
         letter = ''
-        for symbol in IndexEntriesFull.keys():
+        for symbol in iterkeys(IndexEntriesFull):
             if name_space == '' or name_space.lower() in symbol.lower():
                 if len(symbol) > pos:
                     letter = symbol[pos:pos + 1]
@@ -834,7 +834,7 @@ def DetermineNamespace():
         if letter != '' and letter != "_":
             maxletter = ''
             maxsymbols = 0
-            for letter in prefix.keys():
+            for letter in iterkeys(prefix):
                 logging.debug("ns prefix: %s: %s", letter, prefix[letter])
                 if prefix[letter] > maxsymbols:
                     maxletter = letter
@@ -881,7 +881,7 @@ def OutputIndex(basename, apiindex):
         {
             'original': x,
             'short': re.sub(r'^' + NAME_SPACE + r'\_?(.*)', r'\1', x.upper(), flags=re.I),
-        } for x in apiindex.keys()]
+        } for x in iterkeys(apiindex)]
     sorted_keys = sorted(mapped_keys, key=lambda d: (d['short'], d['original']))
 
     for key in sorted_keys:
@@ -970,7 +970,7 @@ def OutputSinceIndexes():
     """Generate the 'since' api index files."""
     for version in set(Since.values()):
         logging.info("Since : [%s]", version)
-        index = {x: IndexEntriesSince[x] for x in IndexEntriesSince.keys() if Since[x] == version}
+        index = {x: IndexEntriesSince[x] for x in iterkeys(IndexEntriesSince) if Since[x] == version}
         OutputIndex("api-index-" + version, index)
 
 
@@ -1008,7 +1008,7 @@ def OutputAnnotationGlossary():
   <title>Annotation Glossary</title>
 ''' % MakeDocHeader("glossary"))
 
-    for annotation in sorted(AnnotationsUsed.keys(), key=str.lower):
+    for annotation in sorted(iterkeys(AnnotationsUsed), key=str.lower):
         if annotation in AnnotationDefinition:
             definition = AnnotationDefinition[annotation]
             curletter = annotation[0].upper()
@@ -1900,7 +1900,7 @@ def OutputFunction(symbol, declaration, symbol_type):
         if param_annotations != '':
             desc += "\n<para>%s</para>" % param_annotations
 
-    desc += OutputParamDescriptions("FUNCTION", symbol, fields.keys())
+    desc += OutputParamDescriptions("FUNCTION", symbol, iterkeys(fields))
     desc += OutputSymbolTraits(symbol)
     desc += "</refsect2>\n"
     return (synop, desc)
@@ -3325,7 +3325,7 @@ def GetSignals(gobject):
                         gtype = m.group(1)
                         pointer = m.group(2)
                         if sourceparams:
-                            param_name = sourceparams.keys()[j]
+                            param_name = list(sourceparams)[j]   # keys as list
                             logging.info('from sourceparams: "%s" (%d: %s)', param_name, j, params[j])
                         else:
                             param_name = m.group(3)
@@ -3961,7 +3961,7 @@ def OutputMissingDocumentation():
 
     UNDOCUMENTED = open(new_undocumented_file, 'w')
 
-    for symbol in sorted(AllSymbols.keys()):
+    for symbol in sorted(iterkeys(AllSymbols)):
         # FIXME: should we print common.LogWarnings for undocumented stuff?
         # DEBUG
         # location = "defined at " + GetSymbolSourceFile(symbol) + ":" + GetSymbolSourceLine(symbol) + "\n"
@@ -4043,7 +4043,7 @@ def OutputUndeclaredSymbols():
     UNDECLARED = open(new_undeclared_file, 'w')
 
     if UndeclaredSymbols:
-        UNDECLARED.write("\n".join(sorted(UndeclaredSymbols.keys())))
+        UNDECLARED.write("\n".join(sorted(iterkeys(UndeclaredSymbols))))
         UNDECLARED.write("\n")
         print("See %s-undeclared.txt for the list of undeclared symbols." % MODULE)
 
@@ -4067,12 +4067,12 @@ def OutputUnusedSymbols():
 
     UNUSED = open(new_unused_file, 'w')
 
-    for symbol in sorted(Declarations.keys()):
+    for symbol in sorted(iterkeys(Declarations)):
         if not symbol in DeclarationOutput:
             UNUSED.write("%s\n" % symbol)
             num_unused += 1
 
-    for symbol in sorted(AllUnusedSymbols.keys()):
+    for symbol in sorted(iterkeys(AllUnusedSymbols)):
         UNUSED.write(symbol + "(" + AllUnusedSymbols[symbol] + ")\n")
         num_unused += 1
 
@@ -4088,7 +4088,7 @@ def OutputAllSymbols():
     """Outputs list of all symbols to a file."""
     SYMBOLS = open(os.path.join(ROOT_DIR, MODULE + "-symbols.txt"), 'w')
 
-    for symbol in sorted(AllSymbols.keys()):
+    for symbol in sorted(iterkeys(AllSymbols)):
         SYMBOLS.write(symbol + "\n")
     SYMBOLS.close()
 
@@ -4097,7 +4097,7 @@ def OutputSymbolsWithoutSince():
     """Outputs list of all symbols without a since tag to a file."""
     SYMBOLS = open(os.path.join(ROOT_DIR, MODULE + "-nosince.txt"), 'w')
 
-    for symbol in sorted(SourceSymbolDocs.keys()):
+    for symbol in sorted(iterkeys(SourceSymbolDocs)):
         if symbol in Since:
             SYMBOLS.write(symbol + "\n")
     SYMBOLS.close()
@@ -4146,10 +4146,10 @@ def MergeSourceDocumentation():
     """
 
     # add whats found in the source
-    symbols = set(SourceSymbolDocs.keys())
+    symbols = set(iterkeys(SourceSymbolDocs))
 
     # and add known symbols from -sections.txt
-    for symbol in KnownSymbols.keys():
+    for symbol in iterkeys(KnownSymbols):
         if KnownSymbols[symbol] == 1:
             symbols.add(symbol)
 
diff --git a/gtkdoc/rebase.py b/gtkdoc/rebase.py
index 81ae6dd..acf3c28 100755
--- a/gtkdoc/rebase.py
+++ b/gtkdoc/rebase.py
@@ -25,6 +25,7 @@ The rebase tool rewrites URI references in installed HTML documentation.
 """
 
 from __future__ import print_function
+from six import iteritems, iterkeys
 
 import logging
 import os
@@ -248,6 +249,6 @@ def RebaseLink(href, options):
 
 
 def PrintWhatWeHaveDone():
-    for origdir in sorted(Mapped.keys()):
+    for origdir in sorted(iterkeys(Mapped)):
         info = Mapped[origdir]
         print(origdir, "->", info[0], "(%s)" % info[1])
diff --git a/gtkdoc/scan.py b/gtkdoc/scan.py
index bd81d48..1ba3f40 100644
--- a/gtkdoc/scan.py
+++ b/gtkdoc/scan.py
@@ -33,6 +33,9 @@ This second list file is typically copied to '$MODULE-sections.txt' and
 organized into sections ready to output the XML pages.
 """
 
+from __future__ import print_function
+from six import iteritems, iterkeys
+
 import logging
 import os
 import re
@@ -74,7 +77,7 @@ def Run(options):
         ScanHeaders(dir, section_list, decl_list, get_types, options)
 
     with open(new_decl_list, 'w') as f:
-        for section in sorted(section_list.keys()):
+        for section in sorted(iterkeys(section_list)):
             f.write(section_list[section])
 
     with open(new_decl, 'w') as f:
@@ -766,7 +769,7 @@ def ScanHeader(input_file, section_list, decl_list, get_types, options):
         previous_line = line
 
     # print remaining forward declarations
-    for symbol in sorted(forward_decls.keys()):
+    for symbol in sorted(iterkeys(forward_decls)):
         if forward_decls[symbol]:
             AddSymbolToList(slist, symbol)
             decl_list.append(forward_decls[symbol])
diff --git a/tests/tools.sh.in b/tests/tools.sh.in
index 1bf19e0..4d301d0 100644
--- a/tests/tools.sh.in
+++ b/tests/tools.sh.in
@@ -27,6 +27,8 @@ done
 
 
 # test python scripts
+# TODO: also test the module files
+# TODO: test python 2 and 3 (python3 -mcompileall gtkdoc/*.py)
 for file in gtkdoc-check gtkdoc-depscan gtkdoc-fixxref gtkdoc-mkdb gtkdoc-mkhtml gtkdoc-mkman gtkdoc-mkpdf 
gtkdoc-rebase gtkdoc-scangobj; do
     fullfile=`which $file`
     @PYTHON@ -m py_compile $fullfile


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