Esempio n. 1
0
def get_package_info(path, variant_index):
    """
    Get valuable information about a package that can be used in different contexts.

    :param path: Path to the root of a project
    :param variant: index of the variant to resolve
    :return: Dict with various info about a package
    """
    data = {
        "variants": [],
    }
    package = get_developer_package(path)
    variants = list(package.iter_variants())
    for v in variants:
        data["variants"].append(v.qualified_name)
    variant = variants[variant_index]
    request = variant.get_requires(build_requires=True, private_build_requires=True)
    context = ResolvedContext(request)
    data["name"] = package.name
    data["interpreter"] = context.which("python")
    data["dependencies"] = get_dependencies(context)
    return data
Esempio n. 2
0
def get_package_info(path, variant_index):
    """
    Get valuable information about a package that can be used in different contexts.

    :param path: Path to the root of a project
    :param variant: index of the variant to resolve
    :return: Dict with various info about a package
    """
    data = {
        "variants": [],
    }
    package = get_developer_package(path)
    variants = list(package.iter_variants())
    for v in variants:
        data["variants"].append(v.qualified_name)
    variant = variants[variant_index]
    request = variant.get_requires(build_requires=True,
                                   private_build_requires=True)
    context = ResolvedContext(request)
    data["name"] = package.name
    data["interpreter"] = context.which("python")
    data["dependencies"] = get_dependencies(context)
    return data
Esempio n. 3
0
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