src/eric7/eric7_api.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9364
83dea9e54ff4
--- a/src/eric7/eric7_api.py	Wed Jul 13 11:16:20 2022 +0200
+++ b/src/eric7/eric7_api.py	Wed Jul 13 14:55:47 2022 +0200
@@ -29,14 +29,13 @@
 def usage():
     """
     Function to print some usage information.
-    
+
     It prints a reference of all commandline parameters that may
     be used and ends the application.
     """
     print("eric7_api")
     print()
-    print("Copyright (c) 2004 - 2022 Detlev Offenbach"
-          " <detlev@die-offenbachs.de>.")
+    print("Copyright (c) 2004 - 2022 Detlev Offenbach" " <detlev@die-offenbachs.de>.")
     print()
     print("Usage:")
     print()
@@ -62,16 +61,16 @@
     print("  -l language or --language=language")
     print("        Generate an API file for the given programming language.")
     print("        Supported programming languages are:")
-    for lang in sorted(
-            DocumentationTools.supportedExtensionsDictForApis.keys()):
+    for lang in sorted(DocumentationTools.supportedExtensionsDictForApis.keys()):
         print("            * {0}".format(lang))
     print("        The default is 'Python3'.")
     print("        This option may be repeated multiple times.")
     print("  -o filename or --output=filename")
-    print("        Write the API information to the named file."
-          " A '%L' placeholder")        # __IGNORE_WARNING_M601__
-    print("        is replaced by the language of the API file"
-          " (see --language).")
+    print(
+        "        Write the API information to the named file."
+        " A '%L' placeholder"  # __IGNORE_WARNING_M601__
+    )
+    print("        is replaced by the language of the API file" " (see --language).")
     print("  -p or --private")
     print("        Include private methods and functions.")
     print("  -R, -r or --recursive")
@@ -102,10 +101,11 @@
         """ conditions.\n"""
         """There is NO warranty; not even for MERCHANTABILITY or FITNESS"""
         """ FOR A\n"""
-        """PARTICULAR PURPOSE.""".format(Version))
+        """PARTICULAR PURPOSE.""".format(Version)
+    )
     sys.exit(1)
 
-    
+
 def main():
     """
     Main entry point into the application.
@@ -116,15 +116,37 @@
 
     try:
         opts, args = getopt.getopt(
-            sys.argv[1:], "b:e:hil:o:pRrt:Vx:",
-            ["base=", "eol=", "exclude=", "exclude-file=", "extension=",
-             "help", "ignore", "language=", "output=", "private", "recursive",
-             "version", ])
+            sys.argv[1:],
+            "b:e:hil:o:pRrt:Vx:",
+            [
+                "base=",
+                "eol=",
+                "exclude=",
+                "exclude-file=",
+                "extension=",
+                "help",
+                "ignore",
+                "language=",
+                "output=",
+                "private",
+                "recursive",
+                "version",
+            ],
+        )
     except getopt.error:
         usage()
 
-    excludeDirs = [".svn", ".hg", ".git", ".ropeproject", ".eric7project",
-                   "dist", "build", "doc", "docs"]
+    excludeDirs = [
+        ".svn",
+        ".hg",
+        ".git",
+        ".ropeproject",
+        ".eric7project",
+        "dist",
+        "build",
+        "doc",
+        "docs",
+    ]
     excludePatterns = []
     outputFileName = ""
     recursive = False
@@ -161,18 +183,17 @@
         elif k in ["-l", "--language"]:
             if v not in progLanguages:
                 if v not in DocumentationTools.supportedExtensionsDictForApis:
-                    sys.stderr.write(
-                        "Wrong language given: {0}. Aborting\n".format(v))
+                    sys.stderr.write("Wrong language given: {0}. Aborting\n".format(v))
                     sys.exit(1)
                 else:
                     progLanguages.append(v)
         elif k in ["-e", "--eol"]:
             if v.lower() == "cr":
-                newline = '\r'
+                newline = "\r"
             elif v.lower() == "lf":
-                newline = '\n'
+                newline = "\n"
             elif v.lower() == "crlf":
-                newline = '\r\n'
+                newline = "\r\n"
 
     if not args:
         usage()
@@ -180,20 +201,20 @@
     if outputFileName == "":
         sys.stderr.write("No output file given. Aborting\n")
         sys.exit(1)
-    
+
     if len(progLanguages) == 0:
         progLanguages = ["Python3"]
-    
+
     for progLanguage in sorted(progLanguages):
         basename = ""
         apis = []
         basesDict = {}
 
-        supportedExtensions = (
-            DocumentationTools.supportedExtensionsDictForApis[progLanguage]
-        )
+        supportedExtensions = DocumentationTools.supportedExtensionsDictForApis[
+            progLanguage
+        ]
         supportedExtensions.extend(extensions)
-        
+
         if not outputFileName.endswith(".api"):
             # append the .api extension, if not given by the user
             outputFileName += ".api"
@@ -204,26 +225,27 @@
                 outputFile = outputFileName
             else:
                 root, ext = os.path.splitext(outputFileName)
-                outputFile = "{0}-{1}{2}".format(root, progLanguage.lower(),
-                                                 ext)
-        basesFile = os.path.splitext(outputFile)[0] + '.bas'
-        
+                outputFile = "{0}-{1}{2}".format(root, progLanguage.lower(), ext)
+        basesFile = os.path.splitext(outputFile)[0] + ".bas"
+
         for arg in args:
             if os.path.isdir(arg):
-                if os.path.exists(os.path.join(
-                        arg, Utilities.joinext("__init__", ".py"))):
+                if os.path.exists(
+                    os.path.join(arg, Utilities.joinext("__init__", ".py"))
+                ):
                     basename = os.path.dirname(arg)
-                    if arg == '.':
+                    if arg == ".":
                         sys.stderr.write("The directory '.' is a package.\n")
                         sys.stderr.write(
-                            "Please repeat the call giving its real name.\n")
+                            "Please repeat the call giving its real name.\n"
+                        )
                         sys.stderr.write("Ignoring the directory.\n")
                         continue
                 else:
                     basename = arg
                 if basename:
                     basename = "{0}{1}".format(basename, os.sep)
-                    
+
                 if recursive and not os.path.islink(arg):
                     names = [arg] + Utilities.getDirs(arg, excludeDirs)
                 else:
@@ -231,16 +253,20 @@
             else:
                 basename = ""
                 names = [arg]
-            
+
             for filename in sorted(names):
                 inpackage = False
                 if os.path.isdir(filename):
                     files = []
                     for ext in supportedExtensions:
-                        files.extend(glob.glob(os.path.join(
-                            filename, Utilities.joinext("*", ext))))
+                        files.extend(
+                            glob.glob(
+                                os.path.join(filename, Utilities.joinext("*", ext))
+                            )
+                        )
                         initFile = os.path.join(
-                            filename, Utilities.joinext("__init__", ext))
+                            filename, Utilities.joinext("__init__", ext)
+                        )
                         if initFile in files:
                             inpackage = True
                             files.remove(initFile)
@@ -249,14 +275,11 @@
                             # assume package
                             inpackage = True
                 else:
-                    if (
-                        Utilities.isWindowsPlatform() and
-                        glob.has_magic(filename)
-                    ):
+                    if Utilities.isWindowsPlatform() and glob.has_magic(filename):
                         files = glob.glob(filename)
                     else:
                         files = [filename]
-                
+
                 for file in files:
                     skipIt = False
                     for pattern in excludePatterns:
@@ -265,15 +288,16 @@
                             break
                     if skipIt:
                         continue
-                    
+
                     try:
                         module = Utilities.ModuleParser.readModule(
                             file,
-                            basename=basename, inpackage=inpackage,
-                            ignoreBuiltinModules=ignoreBuiltinModules)
+                            basename=basename,
+                            inpackage=inpackage,
+                            ignoreBuiltinModules=ignoreBuiltinModules,
+                        )
                         apiGenerator = APIGenerator(module)
-                        api = apiGenerator.genAPI(True, basePackage,
-                                                  includePrivate)
+                        api = apiGenerator.genAPI(True, basePackage, includePrivate)
                         bases = apiGenerator.genBases(includePrivate)
                     except OSError as v:
                         sys.stderr.write("{0} error: {1}\n".format(file, v[1]))
@@ -281,40 +305,41 @@
                     except ImportError as v:
                         sys.stderr.write("{0} error: {1}\n".format(file, v))
                         continue
-                    
+
                     for apiEntry in api:
                         if apiEntry not in apis:
                             apis.append(apiEntry)
                     for basesEntry in bases:
                         if bases[basesEntry]:
                             basesDict[basesEntry] = bases[basesEntry][:]
-                    sys.stdout.write("-- {0} -- {1} ok\n".format(
-                        progLanguage, file))
+                    sys.stdout.write("-- {0} -- {1} ok\n".format(progLanguage, file))
 
         outdir = os.path.dirname(outputFile)
         if outdir and not os.path.exists(outdir):
             os.makedirs(outdir)
         try:
-            with open(outputFile, "w", encoding="utf-8",
-                      newline=newline) as out:
+            with open(outputFile, "w", encoding="utf-8", newline=newline) as out:
                 out.write("\n".join(sorted(apis)) + "\n")
         except OSError as v:
             sys.stderr.write("{0} error: {1}\n".format(outputFile, v[1]))
             sys.exit(3)
         try:
-            with open(basesFile, "w", encoding="utf-8",
-                      newline=newline) as out:
+            with open(basesFile, "w", encoding="utf-8", newline=newline) as out:
                 for baseEntry in sorted(basesDict.keys()):
-                    out.write("{0} {1}\n".format(
-                        baseEntry, " ".join(sorted(basesDict[baseEntry]))))
+                    out.write(
+                        "{0} {1}\n".format(
+                            baseEntry, " ".join(sorted(basesDict[baseEntry]))
+                        )
+                    )
         except OSError as v:
             sys.stderr.write("{0} error: {1}\n".format(basesFile, v[1]))
             sys.exit(3)
-    
-    sys.stdout.write('\nDone.\n')
+
+    sys.stdout.write("\nDone.\n")
     sys.exit(0)
 
-if __name__ == '__main__':
+
+if __name__ == "__main__":
     main()
 
 #

eric ide

mercurial