--- a/PipxInterface/Pipx.py Wed Jun 26 11:57:04 2024 +0200 +++ b/PipxInterface/Pipx.py Wed Jun 26 18:40:48 2024 +0200 @@ -18,6 +18,8 @@ from eric7 import Preferences from eric7.SystemUtilities import OSUtilities +from .PipxExecDialog import PipxExecDialog + class Pipx(QObject): """ @@ -104,7 +106,7 @@ """ binDir = sysconfig.get_path("scripts") pipx = os.path.join(binDir, "pipx") - if OSUtilities.isWindowsPlatform: + if OSUtilities.isWindowsPlatform(): pipx += ".exe" return pipx @@ -180,3 +182,112 @@ packages.append(package) return packages + + def installPackages( + self, + packages, + interpreterVersion="", + fetchMissingInterpreter=False, + forceVenvModification=False, + systemSitePackages=False + ): + """ + Public method + + @param packages list of packages to install + @type list of str + @param interpreterVersion version of the Python interpreter (defaults to "") + @type str (optional) + @param fetchMissingInterpreter flag indicating to fetch a standalone Python + build from GitHub if the specified Python version is not found locally + on the system (defaults to False) + @type bool (optional) + @param forceVenvModification flag indicating to allow modification of already + existing virtual environments (defaults to False) + @type bool (optional) + @param systemSitePackages flag indicating to give access to the system + site-packages directory (defaults to False) + @type bool (optional) + """ + args = ["install"] + if Preferences.getPip("PipSearchIndex"): + indexUrl = Preferences.getPip("PipSearchIndex") + "/simple" + args += ["--index-url", indexUrl] + if interpreterVersion: + args += ["--python", interpreterVersion] + if fetchMissingInterpreter: + args.append("--fetch-missing-python") + if forceVenvModification: + args.append("--force") + if systemSitePackages: + args.append("--system-site-packages") + args += packages + dia = PipxExecDialog(self.tr("Install Packages")) + res = dia.startProcess(self.__getPipxExecutable(), args) + if res: + dia.exec() + + def installAllPackages( + self, + specFile, + interpreterVersion="", + fetchMissingInterpreter=False, + forceVenvModification=False, + systemSitePackages=False + ): + """ + Public method + + @param specFile path of the spec metadata file + @type str + @param interpreterVersion version of the Python interpreter (defaults to "") + @type str (optional) + @param fetchMissingInterpreter flag indicating to fetch a standalone Python + build from GitHub if the specified Python version is not found locally + on the system (defaults to False) + @type bool (optional) + @param forceVenvModification flag indicating to allow modification of already + existing virtual environments (defaults to False) + @type bool (optional) + @param systemSitePackages flag indicating to give access to the system + site-packages directory (defaults to False) + @type bool (optional) + """ + args = ["install-all"] + if Preferences.getPip("PipSearchIndex"): + indexUrl = Preferences.getPip("PipSearchIndex") + "/simple" + args += ["--index-url", indexUrl] + if interpreterVersion: + args += ["--python", interpreterVersion] + if fetchMissingInterpreter: + args.append("--fetch-missing-python") + if forceVenvModification: + args.append("--force") + if systemSitePackages: + args.append("--system-site-packages") + args += specFile + dia = PipxExecDialog(self.tr("Install All Packages")) + res = dia.startProcess(self.__getPipxExecutable(), args) + if res: + dia.exec() + + def createSpecMetadataFile(self, specFile): + """ + Public method to create a spec metadata file. + + @param specFile path of the spec metadata file + @type str + @return tuple containing a flag indicating success and an error message in case + of failure + @rtype tuple of (bool, str) + """ + ok, output = self.runProcess(["list", "--json"]) + if ok: + try: + with open(specFile, "w") as f: + f.write(output) + return True, "" + except IOError as err: + return False, str(err) + else: + return False, output