Tue, 25 Jun 2024 16:15:59 +0200
Extended the install scripts to allow the configuration of a proxy URL for the pip command (see issue (see issue 563).
--- a/scripts/install-debugclients.py Tue Jun 25 14:44:19 2024 +0200 +++ b/scripts/install-debugclients.py Tue Jun 25 16:15:59 2024 +0200 @@ -33,6 +33,7 @@ installPackage = "eric7" doCleanup = True doCompile = True +proxy = None sourceDir = "eric" eric7SourceDir = "" @@ -230,6 +231,8 @@ @return flag indicating a successful installation @rtype bool """ + global proxy + ok = False if force: answer = "y" @@ -242,17 +245,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 @@ -265,10 +269,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, @@ -299,17 +315,22 @@ """ Update the installed pip package. """ - global yes2All + global proxy - if yes2All: - answer = "y" - else: - print("Shall 'pip' be updated (recommended)? (Y/n)", end=" ") - answer = input() # secok + 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 doDependancyChecks(): @@ -405,6 +426,12 @@ action="store_false", help="don't compile the installed python files", ) + parser.add_argument( + "--proxy", + default=None, + metavar="url", + help="HTTP proxy url will be used with pip (default: no proxy used)", + ) return parser @@ -416,7 +443,7 @@ @param argv the list of command line arguments @type list of str """ - global modDir, doCleanup, doCompile, distDir + global modDir, doCleanup, doCompile, distDir, proxy global sourceDir, eric7SourceDir if sys.version_info < (3, 8, 0) or sys.version_info >= (4, 0, 0): @@ -434,6 +461,7 @@ modDir = args.d doCleanup = args.c doCompile = args.z + proxy = args.proxy if not sys.platform.startswith(("win", "cygwin")) and args.i: distDir = os.path.normpath(args.i)
--- a/scripts/install-dependencies.py Tue Jun 25 14:44:19 2024 +0200 +++ b/scripts/install-dependencies.py Tue Jun 25 16:15:59 2024 +0200 @@ -30,27 +30,30 @@ sys.exit(rcode) -def pipInstall(packageName): +def pipInstall(packageName, proxy): """ Install the given package via pip. @param packageName name of the package to be installed @type str + @param proxy URL of a network proxy to be used + @type str @return flag indicating a successful installation @rtype bool """ ok = False - 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(proxy) + args.append(packageName) + exitCode = subprocess.run(args).returncode # secok ok = exitCode == 0 return ok @@ -92,6 +95,13 @@ "esprima", ) + if "--proxy" in sys.argv: + proxyIndex = sys.argv.index("--proxy") + proxy = sys.argv[proxyIndex + 1] + del sys.argv[proxyIndex : proxyIndex + 2] + else: + proxy = None + packages = [] if len(sys.argv) == 2: if sys.argv[1] == "--all": @@ -103,7 +113,7 @@ if not packages: print("Usage:") - print(" install-dependencies --all | --optional | --required") + print(" install-dependencies [--proxy url] --all | --optional | --required") print("where:") print(" --all install all dependencies") print(" --optional install all optional dependencies") @@ -113,7 +123,7 @@ failedPackages = [] for package in packages: - ok = pipInstall(package) + ok = pipInstall(package, proxy) if not ok: failedPackages.append(package)
--- a/scripts/install-server.py Tue Jun 25 14:44:19 2024 +0200 +++ b/scripts/install-server.py Tue Jun 25 16:15:59 2024 +0200 @@ -35,6 +35,7 @@ doCleanup = True doCompile = True doDepChecks = True +proxy = None sourceDir = "eric" eric7SourceDir = "" @@ -295,6 +296,8 @@ @return flag indicating a successful installation @rtype bool """ + global proxy + ok = False if force: answer = "y" @@ -307,17 +310,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 @@ -330,10 +334,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, @@ -364,17 +380,22 @@ """ Update the installed pip package. """ - global yes2All + global proxy - if yes2All: - answer = "y" - else: - print("Shall 'pip' be updated (recommended)? (Y/n)", end=" ") - answer = input() # secok + 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 doDependancyChecks(): @@ -544,6 +565,12 @@ action="store_false", help="don't perform dependency checks (use on your own risk)", ) + parser.add_argument( + "--proxy", + default=None, + metavar="url", + help="HTTP proxy url will be used with pip (default: no proxy used)", + ) return parser @@ -555,11 +582,11 @@ @param argv the list of command line arguments @type list of str """ - global modDir, doCleanup, doCompile, doDepChecks, distDir, scriptsDir + global modDir, doCleanup, doCompile, doDepChecks, distDir, scriptsDir, proxy global sourceDir, eric7SourceDir if sys.version_info < (3, 8, 0) or sys.version_info >= (4, 0, 0): - print("Sorry, the eric debugger requires Python 3.8 or better for running.") + print("Sorry, the eric-ide serverr requires Python 3.8 or better for running.") exit(5) if os.path.dirname(argv[0]): @@ -575,6 +602,7 @@ doDepChecks = args.x doCleanup = args.c doCompile = args.z + proxy = args.proxy if not sys.platform.startswith(("win", "cygwin")) and args.i: distDir = os.path.normpath(args.i)
--- 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