def get_plugins(package_name, paths=None): """Find packages that are plugins of the given package. Args: package_name (str): Name of the package. paths (list of str): Paths to search for packages, defaults to `config.packages_path`. Returns: list of str: The packages that are plugins of the given package. """ pkg = get_latest_package(package_name, paths=paths, error=True) if not pkg.has_plugins: return [] it = iter_package_families(paths) package_names = set(x.name for x in it) bar = ProgressBar("Searching", len(package_names)) plugin_pkgs = [] for package_name_ in package_names: bar.next() if package_name_ == package_name: continue # not a plugin of itself plugin_pkg = get_latest_package(package_name_, paths=paths) if not plugin_pkg.plugin_for: continue for plugin_for in plugin_pkg.plugin_for: if plugin_for == pkg.name: plugin_pkgs.append(package_name_) bar.finish() return plugin_pkgs
def _get_dest_pkg(self, name, version): return get_latest_package( name, range_=VersionRange("==" + version), paths=[self.dest_install_root], error=True )
def expand_version(version): rank = len(version) wildcard_found = False while version and str(version[-1]) in wildcard_map: token = wildcard_map[str(version[-1])] version = version.trim(len(version) - 1) if token == "**": if wildcard_found: # catches bad syntax '**.*' return None else: wildcard_found = True rank = 0 break wildcard_found = True if not wildcard_found: return None range_ = VersionRange(str(version)) package = get_latest_package(name=req.name, range_=range_, paths=paths) if package is None: return version if rank: return package.version.trim(rank) else: return package.version
def _make_row(self, row, family_name): self.setItem(row, 0, QtGui.QStandardItem(family_name)) versions = [None] version_max = None # Fill the spreadsheet for irepo, repo in enumerate(self.repos): latest = packages.get_latest_package(family_name, paths=[repo]) package_folder = os.path.join(repo, family_name) item = QtGui.QStandardItem() item.latest = None item.empty_folder = None if not latest: versions.append(None) if os.path.isdir(os.path.join(repo, family_name)): item.empty_folder = package_folder else: item.latest = latest version_max = max(latest.version, version_max) \ if version_max else latest.version versions.append(latest.version or None) item.setText(generate_item_text(item)) item.setToolTip(generate_item_tooltip(item)) self.setItem(row, irepo + 1, item) # Find the winner winner_found = False for i in range(len(self.repos)): if (not winner_found and versions[i + 1] and versions[i + 1] == version_max): winner_found = True else: self.item(row, i + 1).setForeground(QtGui.QColor('gray'))
def find_pip_from_context(python_version, pip_version=None): """Find pip from rez context. Args: python_version (str or `Version`): Python version to use pip_version (str or `Version`): Version of pip to use, or latest. Returns: 3-tuple: - str: Python executable or None if we fell back to system pip. - str: Pip version or None if we fell back to system pip. - `ResolvedContext`: Context containing pip, or None if we fell back to system pip. """ target = "python" package_request = [] if python_version: ver = Version(str(python_version)) python_major_minor_ver = ver.trim(2) else: # use latest major.minor package = get_latest_package("python") if package: python_major_minor_ver = package.version.trim(2) else: raise BuildError("Found no python package.") python_package = "python-%s" % str(python_major_minor_ver) package_request.append(python_package) if pip_version: target = "pip" if pip_version == "latest": package_request.append("pip") else: package_request.append("pip-%s" % str(pip_version)) print_info("Trying to use pip from %s package", target) try: context = ResolvedContext(package_request) except (PackageFamilyNotFoundError, PackageNotFoundError): print_debug("No rez package called %s found", target) return None, None, None py_exe_name = "python" if platform_.name != "windows": # Python < 2 on Windows doesn't have versionned executable. py_exe_name += str(python_major_minor_ver.trim(1)) py_exe = context.which(py_exe_name) proc = context.execute_command( # -E and -s are used to isolate the environment as much as possible. # See python --help for more details. We absolutely don't want to get # pip from the user home. [ py_exe, "-E", "-s", "-c", "import pip, sys; sys.stdout.write(pip.__version__)" ], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) out, err = proc.communicate() if proc.returncode: print_debug("Failed to get pip from package %s", target) print_debug(out) print_debug(err) return None, None, None pip_version = out.strip() variant = context.get_resolved_package(target) package = variant.parent print_info("Found pip-%s inside %s. Will use it with %s", pip_version, package.uri, py_exe) return py_exe, pip_version, context