def convert_dist(name, dest_path, make_variant=True, ignore_dirs=None,<EOL>python_requirement="<STR_LIT>"):
dist = pkg_resources.get_distribution(name)<EOL>pkg_name = convert_name(dist.project_name)<EOL>pkg_version = convert_version(dist.version)<EOL>if python_requirement == "<STR_LIT>":<EOL><INDENT>pyver = str(sys.version_info[<NUM_LIT:0>])<EOL><DEDENT>elif python_requirement == "<STR_LIT>":<EOL><INDENT>pyver = '<STR_LIT:.>'.join(str(x) for x in sys.version_info[:<NUM_LIT:2>])<EOL><DEDENT>else:<EOL><INDENT>pyver = python_requirement<EOL><DEDENT>pypkg = "<STR_LIT>" % pyver<EOL>pkg_requires = []<EOL>if not make_variant:<EOL><INDENT>pkg_requires.append(pypkg)<EOL><DEDENT>for req in dist.requires():<EOL><INDENT>pkg_requires += convert_requirement(req)<EOL><DEDENT>pkg_path = _mkdirs(dest_path, pkg_name, pkg_version)<EOL>pkg_file = os.path.join(pkg_path, "<STR_LIT>")<EOL>root_path = _mkdirs(pkg_path, pypkg) if make_variant else pkg_path<EOL>basename = os.path.basename(dist.location)<EOL>is_egg = (os.path.splitext(basename)[<NUM_LIT:1>] == "<STR_LIT>")<EOL>if os.path.isdir(dist.location):<EOL><INDENT>if is_egg:<EOL><INDENT>for file in os.listdir(dist.location):<EOL><INDENT>fpath = os.path.join(dist.location, file)<EOL>if os.path.isfile(fpath):<EOL><INDENT>shutil.copy(fpath, root_path)<EOL><DEDENT>else:<EOL><INDENT>shutil.copytree(fpath, os.path.join(root_path, file),<EOL>ignore=shutil.ignore_patterns(ignore_dirs))<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>egginfo_dir = "<STR_LIT>" % dist.egg_name()<EOL>eggpath = os.path.join(dist.location, egginfo_dir)<EOL>file = os.path.join(eggpath, "<STR_LIT>")<EOL>if not os.path.isfile(file):<EOL><INDENT>raise RezSystemError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % name)<EOL><DEDENT>with open(file) as f:<EOL><INDENT>installed_files = f.read().strip().split()<EOL><DEDENT>dirs = set()<EOL>files = set()<EOL>for file in installed_files:<EOL><INDENT>path = os.path.join(eggpath, file)<EOL>path = os.path.realpath(path)<EOL>if os.path.isfile(path) and path.startswith(dist.location + os.sep):<EOL><INDENT>dir_ = os.path.dirname(path)<EOL>if ignore_dirs:<EOL><INDENT>reldir = os.path.relpath(dir_, dist.location)<EOL>if set(reldir.split(os.sep)) & set(ignore_dirs):<EOL><INDENT>continue<EOL><DEDENT><DEDENT>files.add(path)<EOL>dirs.add(dir_)<EOL><DEDENT><DEDENT>def _dst(p):<EOL><INDENT>dst = os.path.relpath(p, dist.location)<EOL>dst = os.path.join(root_path, dst)<EOL>return os.path.realpath(dst)<EOL><DEDENT>for dir_ in dirs:<EOL><INDENT>dst_dir = _dst(dir_)<EOL>_mkdirs(dst_dir)<EOL><DEDENT>for file in files:<EOL><INDENT>dst_file = _dst(file)<EOL>shutil.copy(file, dst_file)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>import zipfile<EOL>assert(is_egg and os.path.isfile(dist.location))<EOL>assert(zipfile.is_zipfile(dist.location))<EOL>z = zipfile.ZipFile(dist.location)<EOL>z.extractall(root_path)<EOL><DEDENT>variants_str = "<STR_LIT>" % pypkg if make_variant else '<STR_LIT>'<EOL>content = textwrap.dedent(<EOL>"""<STR_LIT>""" % dict(<EOL>name=pkg_name,<EOL>version=pkg_version,<EOL>variants=variants_str,<EOL>requires=str(pkg_requires)))<EOL>content = content.strip() + '<STR_LIT:\n>'<EOL>with open(pkg_file, '<STR_LIT:w>') as f:<EOL><INDENT>f.write(content)<EOL><DEDENT>return pkg_path<EOL>
Convert an already installed python distribution into a rez package.

    Args:
        dest_path (str): Where to put the rez package. The package will be
            created under dest_path/<NAME>/<VERSION>/.
        make_variant (bool): If True, makes a single variant in the rez package
            based on the MAJOR.MINOR version of python.
        ignore_dirs (bool): List of directory names to not copy from the dist.
        python_requirement (str): How the package should depend on python.
            One of:
            - "major": depend on python-X
            - "major_minor": depend on python-X.X
            - any other value: this string is used as the literal version
              range string.

    Returns:
        Install path of the new Rez package.