eric7/PipInterface/Pip.py

branch
eric7
changeset 8997
d8946c2a22b5
parent 8983
46eaed7bf3cb
child 8998
4644064d4454
diff -r 62bd225b489f -r d8946c2a22b5 eric7/PipInterface/Pip.py
--- a/eric7/PipInterface/Pip.py	Tue Mar 22 19:31:29 2022 +0100
+++ b/eric7/PipInterface/Pip.py	Wed Mar 23 20:21:42 2022 +0100
@@ -918,3 +918,55 @@
                                            showArgs=False)
                     if res:
                         dia.exec()
+    
+    #######################################################################
+    ## Dependency tree handling methods below
+    #######################################################################
+    
+    def getDependecyTree(self, envName, localPackages=True, usersite=False,
+                         reverse=False):
+        """
+        Public method to get the dependency tree of installed packages.
+        
+        @param envName name of the environment to get the packages for
+        @type str
+        @param localPackages flag indicating to get the tree for local
+            packages only
+        @type bool
+        @param usersite flag indicating to get the tree for packages
+            installed in user-site directory only
+        @type bool
+        @param reverse flag indicating to get the dependency tree in
+            reverse order (i.e. list packages needed by other)
+        @type bool
+        @return list of nested dictionaries resembling the requested
+            dependency tree
+        @rtype list of dict
+        """
+        dependencies = []
+        
+        if envName:
+            interpreter = self.getVirtualenvInterpreter(envName)
+            if interpreter:
+                args = [
+                    "-m", "pipdeptree",
+                    "--json-tree",
+                    "--python", interpreter,
+                ]
+                if localPackages:
+                    args.append("--local-only")
+                if usersite:
+                    args.append("--user-only")
+                if reverse:
+                    args.append("--reverse")
+                
+                proc = QProcess()
+                proc.start(sys.executable, args)
+                if proc.waitForStarted(15000) and proc.waitForFinished(30000):
+                    output = str(proc.readAllStandardOutput(),
+                                 Preferences.getSystem("IOEncoding"),
+                                 'replace').strip()
+                    with contextlib.suppress(json.JSONDecodeError):
+                        dependencies = json.loads(output)
+           
+        return dependencies

eric ide

mercurial