def pip_install_package(source_name, pip_version=None, python_version=None,<EOL>mode=InstallMode.min_deps, release=False):
installed_variants = []<EOL>skipped_variants = []<EOL>pip_exe, context = find_pip(pip_version, python_version)<EOL>packages_path = (config.release_packages_path if release<EOL>else config.local_packages_path)<EOL>tmpdir = mkdtemp(suffix="<STR_LIT>", prefix="<STR_LIT>")<EOL>stagingdir = os.path.join(tmpdir, "<STR_LIT>")<EOL>stagingsep = "<STR_LIT>".join([os.path.sep, "<STR_LIT>", os.path.sep])<EOL>destpath = os.path.join(stagingdir, "<STR_LIT>")<EOL>binpath = os.path.join(stagingdir, "<STR_LIT>")<EOL>incpath = os.path.join(stagingdir, "<STR_LIT>")<EOL>datapath = stagingdir<EOL>if context and config.debug("<STR_LIT>"):<EOL><INDENT>buf = StringIO()<EOL>print >> buf, "<STR_LIT>"<EOL>context.print_info(buf)<EOL>_log(buf.getvalue())<EOL><DEDENT>cmd = [pip_exe, "<STR_LIT>",<EOL>"<STR_LIT>" % destpath,<EOL>"<STR_LIT>" % binpath,<EOL>"<STR_LIT>" % incpath,<EOL>"<STR_LIT>" % datapath]<EOL>if mode == InstallMode.no_deps:<EOL><INDENT>cmd.append("<STR_LIT>")<EOL><DEDENT>cmd.append(source_name)<EOL>_cmd(context=context, command=cmd)<EOL>_system = System()<EOL>distribution_path = DistributionPath([destpath], include_egg=True)<EOL>distributions = [d for d in distribution_path.get_distributions()]<EOL>for distribution in distribution_path.get_distributions():<EOL><INDENT>requirements = []<EOL>if distribution.metadata.run_requires:<EOL><INDENT>for requirement in distribution.metadata.run_requires:<EOL><INDENT>if "<STR_LIT>" in requirement:<EOL><INDENT>if interpret(requirement["<STR_LIT>"]):<EOL><INDENT>requirements.extend(_get_dependencies(requirement, distributions))<EOL><DEDENT><DEDENT>elif "<STR_LIT>" in requirement:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>requirements.extend(_get_dependencies(requirement, distributions))<EOL><DEDENT><DEDENT><DEDENT>tools = []<EOL>src_dst_lut = {}<EOL>for installed_file in distribution.list_installed_files(allow_fail=True):<EOL><INDENT>source_file = os.path.normpath(os.path.join(destpath, installed_file[<NUM_LIT:0>]))<EOL>if os.path.exists(source_file):<EOL><INDENT>destination_file = installed_file[<NUM_LIT:0>].split(stagingsep)[<NUM_LIT:1>]<EOL>exe = False<EOL>if is_exe(source_file) anddestination_file.startswith("<STR_LIT>" % ("<STR_LIT>", os.path.sep)):<EOL><INDENT>_, _file = os.path.split(destination_file)<EOL>tools.append(_file)<EOL>exe = True<EOL><DEDENT>data = [destination_file, exe]<EOL>src_dst_lut[source_file] = data<EOL><DEDENT>else:<EOL><INDENT>_log("<STR_LIT>" + source_file + "<STR_LIT:!>")<EOL><DEDENT><DEDENT>def make_root(variant, path):<EOL><INDENT>"""<STR_LIT>"""<EOL>for source_file, data in src_dst_lut.items():<EOL><INDENT>destination_file, exe = data<EOL>destination_file = os.path.normpath(os.path.join(path, destination_file))<EOL>if not os.path.exists(os.path.dirname(destination_file)):<EOL><INDENT>os.makedirs(os.path.dirname(destination_file))<EOL><DEDENT>shutil.copyfile(source_file, destination_file)<EOL>if exe:<EOL><INDENT>shutil.copystat(source_file, destination_file)<EOL><DEDENT><DEDENT><DEDENT>variant_reqs = []<EOL>variant_reqs.append("<STR_LIT>" % _system.platform)<EOL>variant_reqs.append("<STR_LIT>" % _system.arch)<EOL>variant_reqs.append("<STR_LIT>" % _system.os)<EOL>if context is None:<EOL><INDENT>py_ver = '<STR_LIT:.>'.join(map(str, sys.version_info[:<NUM_LIT:2>]))<EOL><DEDENT>else:<EOL><INDENT>python_variant = context.get_resolved_package("<STR_LIT>")<EOL>py_ver = python_variant.version.trim(<NUM_LIT:2>)<EOL><DEDENT>variant_reqs.append("<STR_LIT>" % py_ver)<EOL>name, _ = parse_name_and_version(distribution.name_and_version)<EOL>name = distribution.name[<NUM_LIT:0>:len(name)].replace("<STR_LIT:->", "<STR_LIT:_>")<EOL>with make_package(name, packages_path, make_root=make_root) as pkg:<EOL><INDENT>pkg.version = distribution.version<EOL>if distribution.metadata.summary:<EOL><INDENT>pkg.description = distribution.metadata.summary<EOL><DEDENT>pkg.variants = [variant_reqs]<EOL>if requirements:<EOL><INDENT>pkg.requires = requirements<EOL><DEDENT>commands = []<EOL>commands.append("<STR_LIT>")<EOL>if tools:<EOL><INDENT>pkg.tools = tools<EOL>commands.append("<STR_LIT>")<EOL><DEDENT>pkg.commands = '<STR_LIT:\n>'.join(commands)<EOL><DEDENT>installed_variants.extend(pkg.installed_variants or [])<EOL>skipped_variants.extend(pkg.skipped_variants or [])<EOL><DEDENT>shutil.rmtree(tmpdir)<EOL>return installed_variants, skipped_variants<EOL>
Install a pip-compatible python package as a rez package.
    Args:
        source_name (str): Name of package or archive/url containing the pip
            package source. This is the same as the arg you would pass to
            the 'pip install' command.
        pip_version (str or `Version`): Version of pip to use to perform the
            install, uses latest if None.
        python_version (str or `Version`): Python version to use to perform the
            install, and subsequently have the resulting rez package depend on.
        mode (`InstallMode`): Installation mode, determines how dependencies are
            managed.
        release (bool): If True, install as a released package; otherwise, it
            will be installed as a local package.

    Returns:
        2-tuple:
            List of `Variant`: Installed variants;
            List of `Variant`: Skipped variants (already installed).