@contextmanager<EOL>def make_package(name, path, make_base=None, make_root=None, skip_existing=True,<EOL>warn_on_skip=True):
maker = PackageMaker(name)<EOL>yield maker<EOL>package = maker.get_package()<EOL>cwd = os.getcwd()<EOL>src_variants = []<EOL>if skip_existing:<EOL><INDENT>for variant in package.iter_variants():<EOL><INDENT>variant_ = variant.install(path, dry_run=True)<EOL>if variant_ is None:<EOL><INDENT>src_variants.append(variant)<EOL><DEDENT>else:<EOL><INDENT>maker.skipped_variants.append(variant_)<EOL>if warn_on_skip:<EOL><INDENT>print_warning("<STR_LIT>"<EOL>"<STR_LIT>" % variant_.uri)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>src_variants = package.iter_variants()<EOL><DEDENT>with retain_cwd():<EOL><INDENT>for variant in src_variants:<EOL><INDENT>variant_ = variant.install(path)<EOL>base = variant_.base<EOL>if make_base and base:<EOL><INDENT>if not os.path.exists(base):<EOL><INDENT>os.makedirs(base)<EOL><DEDENT>os.chdir(base)<EOL>make_base(variant_, base)<EOL><DEDENT>root = variant_.root<EOL>if make_root and root:<EOL><INDENT>if not os.path.exists(root):<EOL><INDENT>os.makedirs(root)<EOL><DEDENT>os.chdir(root)<EOL>make_root(variant_, root)<EOL><DEDENT>maker.installed_variants.append(variant_)<EOL><DEDENT><DEDENT>
Make and install a package.

    Example:

        >>> def make_root(variant, path):
        >>>     os.symlink("/foo_payload/misc/python27", "ext")
        >>>
        >>> with make_package('foo', '/packages', make_root=make_root) as pkg:
        >>>     pkg.version = '1.0.0'
        >>>     pkg.description = 'does foo things'
        >>>     pkg.requires = ['python-2.7']

    Args:
        name (str): Package name.
        path (str): Package repository path to install package into.
        make_base (callable): Function that is used to create the package
            payload, if applicable.
        make_root (callable): Function that is used to create the package
            variant payloads, if applicable.
        skip_existing (bool): If True, detect if a variant already exists, and
            skip with a warning message if so.
        warn_on_skip (bool): If True, print warning when a variant is skipped.

    Yields:
        `PackageMaker` object.

    Note:
        Both `make_base` and `make_root` are called once per variant install,
        and have the signature (variant, path).

    Note:
        The 'installed_variants' attribute on the `PackageMaker` instance will
        be appended with variant(s) created by this function, if any.