scripts/install.py

branch
eric7
changeset 10801
5859861e7a1f
parent 10788
c14f37a9aa74
child 10814
ba20efe10336
child 10828
fc1310995b98
--- a/scripts/install.py	Tue Jun 25 14:44:19 2024 +0200
+++ b/scripts/install.py	Tue Jun 25 16:15:59 2024 +0200
@@ -45,6 +45,7 @@
 yes2All = False
 withPyqt6Tools = False
 verbose = False
+proxy = None
 cfg = {}
 progLanguages = ["MicroPython", "Python3", "QSS"]
 sourceDir = "eric"
@@ -1458,7 +1459,7 @@
     @return flag indicating a successful installation
     @rtype bool
     """
-    global yes2All
+    global yes2All, proxy
 
     ok = False
     if yes2All or force:
@@ -1472,17 +1473,18 @@
         )
         answer = input()  # secok
     if answer in ("", "Y", "y"):
-        exitCode = subprocess.run(  # secok
-            [
-                sys.executable,
-                "-m",
-                "pip",
-                "install",
-                "--prefer-binary",
-                "--upgrade",
-                packageName,
-            ]
-        ).returncode
+        args = [
+            sys.executable,
+            "-m",
+            "pip",
+            "install",
+            "--prefer-binary",
+            "--upgrade",
+        ]
+        if proxy:
+            args.append(f"--proxy={proxy}")
+        args.append(packageName)
+        exitCode = subprocess.run(args).returncode  # secok
         ok = exitCode == 0
 
     return ok
@@ -1495,10 +1497,22 @@
     @return flag indicating an outdated pip
     @rtype bool
     """
+    global proxy
+
     try:
+        args = [
+            sys.executable,
+            "-m",
+            "pip",
+            "list",
+            "--outdated",
+            "--format=json",
+        ]
+        if proxy:
+            args.append(f"--proxy={proxy}")
         pipOut = (
             subprocess.run(  # secok
-                [sys.executable, "-m", "pip", "list", "--outdated", "--format=json"],
+                args,
                 check=True,
                 capture_output=True,
                 text=True,
@@ -1529,7 +1543,7 @@
     """
     Update the installed pip package.
     """
-    global yes2All
+    global yes2All, proxy
 
     if yes2All:
         answer = "y"
@@ -1537,9 +1551,17 @@
         print("Shall 'pip' be updated (recommended)? (Y/n)", end=" ")
         answer = input()  # secok
     if answer in ("", "Y", "y"):
-        subprocess.run(  # secok
-            [sys.executable, "-m", "pip", "install", "--upgrade", "pip"]
-        )
+        args = [
+            sys.executable,
+            "-m",
+            "pip",
+            "install",
+            "--upgrade",
+        ]
+        if proxy:
+            args.append(f"--proxy={proxy}")
+        args.append("pip")
+        subprocess.run(args)  # secok
 
 
 def versionToStr(version):
@@ -2074,11 +2096,11 @@
     parser = argparse.ArgumentParser(
         description="Install eric7 from the source code tree.",
         epilog="The file given to the -f option must be valid Python code defining a"
-        "dictionary called 'cfg' with the keys 'ericDir', 'ericPixDir', ericIconDir',"
+        " dictionary called 'cfg' with the keys 'ericDir', 'ericPixDir', ericIconDir',"
         " 'ericDTDDir', 'ericCSSDir', 'ericStylesDir', 'ericThemesDir', ericDocDir',"
         " ericExamplesDir', ericTranslationsDir', 'ericTemplatesDir',"
         " 'ericCodeTemplatesDir', ericOthersDir','bindir', 'mdir' and 'apidir."
-        "These define the directories for the installation of the various parts of"
+        " These define the directories for the installation of the various parts of"
         " eric.",
     )
 
@@ -2184,6 +2206,12 @@
         action="store_true",
         help="install the 'qt6-applications' package",
     )
+    parser.add_argument(
+        "--proxy",
+        default=None,
+        metavar="url",
+        help="HTTP proxy url will be used with pip (default: no proxy used)",
+    )
 
     return parser
 
@@ -2198,7 +2226,7 @@
     global modDir, doCleanup, doCompile, distDir, cfg, apisDir
     global sourceDir, eric7SourceDir, configName, platBinDir
     global macAppBundlePath, macAppBundleName, macPythonExe
-    global installApis, doCleanDesktopLinks, yes2All
+    global installApis, doCleanDesktopLinks, yes2All, proxy
     global createInstallInfoFile, installCwd
     global withPyqt6Tools
     global verbose
@@ -2225,6 +2253,7 @@
     doCompile = args.z
     installApis = not args.no_apis
     yes2All = args.yes
+    proxy = args.proxy
     withPyqt6Tools = args.with_tools
     createInstallInfoFile = not args.no_info
     verbose = args.verbose

eric ide

mercurial