Modified ModuleParser to deal with Python stub files (*.pyi) as well. eric7

Wed, 28 Sep 2022 15:35:06 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 28 Sep 2022 15:35:06 +0200
branch
eric7
changeset 9364
83dea9e54ff4
parent 9363
789d739a683a
child 9365
25f6183494e2

Modified ModuleParser to deal with Python stub files (*.pyi) as well.

src/eric7/DocumentationTools/__init__.py file | annotate | diff | comparison | revisions
src/eric7/Utilities/ModuleParser.py file | annotate | diff | comparison | revisions
src/eric7/eric7_api.py file | annotate | diff | comparison | revisions
--- a/src/eric7/DocumentationTools/__init__.py	Wed Sep 28 12:56:35 2022 +0200
+++ b/src/eric7/DocumentationTools/__init__.py	Wed Sep 28 15:35:06 2022 +0200
@@ -8,6 +8,6 @@
 """
 
 supportedExtensionsDictForApis = {
-    "Python3": [".py", ".pyw", ".py3", ".pyw3"],
+    "Python3": [".py", ".pyw", ".py3", ".pyw3", ".pyi"],
     "Ruby": [".rb"],
 }
--- a/src/eric7/Utilities/ModuleParser.py	Wed Sep 28 12:56:35 2022 +0200
+++ b/src/eric7/Utilities/ModuleParser.py	Wed Sep 28 15:35:06 2022 +0200
@@ -1563,7 +1563,7 @@
     global _modules
 
     _extensions = (
-        [".py", ".pyw", ".ptl", ".rb"] if extensions is None else extensions[:]
+        [".py", ".pyw", ".pyi", ".ptl", ".rb"] if extensions is None else extensions[:]
     )
     with contextlib.suppress(ValueError):
         _extensions.remove(".py")
@@ -1576,6 +1576,7 @@
             module = module[:-3]
         if (
             os.path.exists(os.path.join(path[0], "__init__.py"))
+            or os.path.exists(os.path.join(path[0], "__init__.pyi"))
             or os.path.exists(os.path.join(path[0], "__init__.rb"))
             or inpackage
         ):
@@ -1586,7 +1587,7 @@
             else:
                 modname = module
             modname = modname.replace(os.sep, ".")
-            inpackage = 1
+            inpackage = True
         else:
             modname = os.path.basename(module)
         for ext in _extensions:
@@ -1689,7 +1690,7 @@
 
     # standard Python module file
     if name.lower().endswith(".py"):
-        name = name[:-3]
+        name = os.path.splitext(name)[0]
 
     spec = importlib.machinery.PathFinder.find_spec(name, path)
     if spec is None:
@@ -1720,19 +1721,16 @@
     modname = module
 
     if os.path.exists(module):
-        path = [os.path.dirname(module)]
+        modulePath = [os.path.dirname(module)]
         if module.lower().endswith(".py"):
-            module = module[:-3]
-        if os.path.exists(os.path.join(path[0], "__init__.py")):
+            module = os.path.splitext(module)[0]
+        if os.path.exists(os.path.join(modulePath[0], "__init__.py")):
             if basename:
                 module = module.replace(basename, "")
             modname = module.replace(os.sep, ".")
         else:
             modname = os.path.basename(module)
-        if modname.lower().endswith(".ptl") or modname.lower().endswith(".pyw"):
-            modname = modname[:-4]
-        elif modname.lower().endswith(".rb"):
-            modname = modname[:-3]
+        modname = os.path.splitext(modname)[0]
         module = os.path.basename(module)
 
     if modname in _modules:
--- a/src/eric7/eric7_api.py	Wed Sep 28 12:56:35 2022 +0200
+++ b/src/eric7/eric7_api.py	Wed Sep 28 15:35:06 2022 +0200
@@ -213,7 +213,9 @@
         supportedExtensions = DocumentationTools.supportedExtensionsDictForApis[
             progLanguage
         ]
-        supportedExtensions.extend(extensions)
+        supportedExtensions.extend(
+            e for e in extensions if e not in supportedExtensions
+        )
 
         if not outputFileName.endswith(".api"):
             # append the .api extension, if not given by the user

eric ide

mercurial