install scripts eric7

Tue, 06 Sep 2022 15:08:41 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 06 Sep 2022 15:08:41 +0200
branch
eric7
changeset 9314
7ba79b00ea96
parent 9313
6bac6775abb2
child 9315
79be00bfe50c

install scripts
- modified install.py script to differentiate between optional and required dependencies
- extended the install-dependencies.py script to differentiate between optional and required dependencies. Invoke it with
(python3 install-dependencies.py --all | --optional | --required)

docs/changelog file | annotate | diff | comparison | revisions
scripts/install-dependencies.py file | annotate | diff | comparison | revisions
scripts/install.py file | annotate | diff | comparison | revisions
--- a/docs/changelog	Tue Sep 06 13:39:18 2022 +0200
+++ b/docs/changelog	Tue Sep 06 15:08:41 2022 +0200
@@ -8,6 +8,12 @@
   -- extended the testing dialog to allow test case filtering on markers (pytest only)
   -- extended the testing dialog to allow test case filtering by a list of test name
      patterns (unittest) or test name expression (pytest)
+- install scripts
+  -- modified install.py script to differentiate between optional and required
+     dependencies
+  -- extended the install-dependencies.py script to differentiate between optional and
+     required dependencies. Invoke it with
+     (python3 install-dependencies.py --all | --optional | --required)
 
 Version 22.9:
 - bug fixes
--- a/scripts/install-dependencies.py	Tue Sep 06 13:39:18 2022 +0200
+++ b/scripts/install-dependencies.py	Tue Sep 06 15:08:41 2022 +0200
@@ -9,10 +9,26 @@
 Installation script for the eric IDE dependencies.
 """
 
+import contextlib
 import subprocess
 import sys
 
 
+def exit(rcode=0):
+    """
+    Exit the install script.
+
+    @param rcode result code to report back (integer)
+    """
+    print()
+
+    if sys.platform.startswith(("win", "cygwin")):
+        with contextlib.suppress():
+            input("Press enter to continue...")  # secok
+
+    sys.exit(rcode)
+
+
 def pipInstall(packageName):
     """
     Install the given package via pip.
@@ -43,29 +59,51 @@
     """
     Function to install the eric dependencies.
     """
-    packages = (
-        "wheel",
+    requiredPackages = (
         "PyQt6>=6.2.0",
         "PyQt6-Charts>=6.2.0",
         "PyQt6-WebEngine>=6.2.0",
         "PyQt6-QScintilla>=2.13.0",
-        "docutils",
-        "Markdown",
-        "pyyaml",
         "tomlkit",
-        "chardet",
         "asttokens",
         "EditorConfig",
-        "Send2Trash",
         "Pygments",
         "parso",
         "jedi",
         "packaging",
-        "pipdeptree",
         "cyclonedx-python-lib",
         "cyclonedx-bom",
         "trove-classifiers",
+        "black>=22.6.0",
     )
+    optionalPackages = (
+        "docutils",
+        "Markdown",
+        "pyyaml",
+        "chardet",
+        "Send2Trash",
+        "pyenchant",
+        "wheel",
+    )
+
+    packages = []
+    if len(sys.argv) == 2:
+        if sys.argv[1] == "--all":
+            packages = requiredPackages + optionalPackages
+        elif sys.argv[1] == "--required":
+            packages = requiredPackages
+        elif sys.argv[1] == "--optional":
+            packages = optionalPackages
+
+    if not packages:
+        print("Usage:")
+        print("    install-dependencies --all | --optional | --required")
+        print("where:")
+        print("    --all         install all dependencies")
+        print("    --optional    install all optional dependencies")
+        print("    --required    install all required dependencies")
+
+        exit(42)
 
     failedPackages = []
     for package in packages:
@@ -83,6 +121,8 @@
     else:
         print("All packages installed successfully.")
 
+    exit(0)
+
 
 if __name__ == "__main__":
     main()
--- a/scripts/install.py	Tue Sep 06 13:39:18 2022 +0200
+++ b/scripts/install.py	Tue Sep 06 15:08:41 2022 +0200
@@ -1738,7 +1738,7 @@
             exit(1)
     print("Found PyQt6-QScintilla")
 
-    impModulesList = [
+    pyqt6BaseModulesList = [
         "PyQt6.QtGui",
         "PyQt6.QtNetwork",
         "PyQt6.QtPrintSupport",
@@ -1747,20 +1747,13 @@
         "PyQt6.QtSvgWidgets",
         "PyQt6.QtWidgets",
     ]
-    optionalModulesList = {
+    requiredModulesList = {
         # key is pip project name
         # value is tuple of package name, pip install constraint
-        "docutils": ("docutils", ""),
-        "Markdown": ("markdown", ""),
-        "pyyaml": ("yaml", ""),
         "tomlkit": ("tomlkit", ""),
-        "chardet": ("chardet", ""),
         "asttokens": ("asttokens", ""),
         "EditorConfig": ("editorconfig", ""),
-        "Send2Trash": ("send2trash", ""),
         "Pygments": ("pygments", ""),
-        "pyenchant": ("enchant", ""),
-        "wheel": ("wheel", ""),
         "parso": ("parso", ""),
         "jedi": ("jedi", ""),
         "packaging": ("packaging", ""),
@@ -1769,15 +1762,26 @@
         "trove-classifiers": ("trove_classifiers", ""),
         "black": ("black", ">=22.6.0"),
     }
+    optionalModulesList = {
+        # key is pip project name
+        # value is tuple of package name, pip install constraint
+        "docutils": ("docutils", ""),
+        "Markdown": ("markdown", ""),
+        "pyyaml": ("yaml", ""),
+        "chardet": ("chardet", ""),
+        "Send2Trash": ("send2trash", ""),
+        "pyenchant": ("enchant", ""),
+        "wheel": ("wheel", ""),
+    }
     if not ignorePyqt6Tools:
         optionalModulesList["qt6-applications"] = ("qt6_applications", "")
 
-    # check mandatory modules
+    # check mandatory PyQt6 modules
     modulesOK = True
-    for impModule in impModulesList:
-        name = impModule.split(".")[1]
+    for pyqt6BaseModule in pyqt6BaseModulesList:
+        name = pyqt6BaseModule.split(".")[1]
         try:
-            __import__(impModule)
+            __import__(pyqt6BaseModule)
             print("Found", name)
         except ImportError as err:
             print("Sorry, please install {0}.".format(name))
@@ -1787,7 +1791,32 @@
     if not modulesOK:
         exit(1)
 
+    # check required modules
+    requiredMissing = False
+    for requiredPackage in requiredModulesList:
+        try:
+            __import__(requiredModulesList[requiredPackage][0])
+            print("Found", requiredPackage)
+        except ImportError as err:
+            if isSudo:
+                print("Required '{0}' could not be detected.".format(requiredPackage))
+                requiredMissing = True
+            else:
+                msg = "Required '{0}' could not be detected.{1}".format(
+                    requiredPackage, "\nError: {0}".format(err) if verbose else ""
+                )
+                pipInstall(
+                    requiredPackage + requiredModulesList[requiredPackage][1],
+                    msg,
+                    force=True,
+                )
+    if requiredMissing:
+        print("Some required packages are missing and could not be installed.")
+        print("Install them manually with:")
+        print("    {0} install-dependencies.py --required".format(sys.executable))
+
     # check optional modules
+    optionalMissing = False
     for optPackage in optionalModulesList:
         try:
             __import__(optionalModulesList[optPackage][0])
@@ -1795,11 +1824,20 @@
         except ImportError as err:
             if isSudo:
                 print("Optional '{0}' could not be detected.".format(optPackage))
+                optionalMissing = True
             else:
                 msg = "Optional '{0}' could not be detected.{1}".format(
                     optPackage, "\nError: {0}".format(err) if verbose else ""
                 )
                 pipInstall(optPackage + optionalModulesList[optPackage][1], msg)
+    if optionalMissing:
+        print("Some optional packages are missing and could not be installed.")
+        print("Install them manually with:")
+        print("    {0} install-dependencies.py --optional".format(sys.executable))
+
+    if requiredMissing and optionalMissing:
+        print("Alternatively you may install all of them with:")
+        print("    {0} install-dependencies.py --all".format(sys.executable))
 
     # determine the platform dependent black list
     if sys.platform.startswith(("win", "cygwin")):

eric ide

mercurial