Beispiel #1
0
def make_package(name, path, make_base=None, make_root=None):
    """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.

    Note:
        Both `make_base` and `make_root` are called once per variant install,
        and have the signature (variant, path).
    """
    maker = PackageMaker(name)
    yield maker

    # post-with-block:
    package = maker.get_package()

    with retain_cwd():
        for variant in package.iter_variants():
            variant_ = variant.install(path)

            base = variant_.base
            if make_base and base:
                if not os.path.exists(base):
                    os.makedirs(base)
                os.chdir(base)
                make_base(variant_, base)

            root = variant_.root
            if make_root and root:
                if not os.path.exists(root):
                    os.makedirs(root)
                os.chdir(root)
                make_root(variant_, root)
Beispiel #2
0
def make_package(name, path, make_base=None, make_root=None, skip_existing=True,
                 warn_on_skip=True):
    """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.
    """
    maker = PackageMaker(name)
    yield maker

    # post-with-block:
    #

    package = maker.get_package()
    cwd = os.getcwd()
    src_variants = []

    # skip those variants that already exist
    if skip_existing:
        for variant in package.iter_variants():
            variant_ = variant.install(path, dry_run=True)
            if variant_ is None:
                src_variants.append(variant)
            else:
                maker.skipped_variants.append(variant_)
                if warn_on_skip:
                    print_warning("Skipping installation: Package variant already "
                                  "exists: %s" % variant_.uri)
    else:
        src_variants = package.iter_variants()

    with retain_cwd():
        # install the package variant(s) into the filesystem package repo at `path`
        for variant in src_variants:
            variant_ = variant.install(path)

            base = variant_.base
            if make_base and base:
                if not os.path.exists(base):
                    os.makedirs(base)
                os.chdir(base)
                make_base(variant_, base)

            root = variant_.root
            if make_root and root:
                if not os.path.exists(root):
                    os.makedirs(root)
                os.chdir(root)
                make_root(variant_, root)

            maker.installed_variants.append(variant_)
Beispiel #3
0
def deploy(package, path, shim="binary", as_bundle=False):
    """Deploy `distribution` as `package` at `path`

    Arguments:
        package (rez.Package): Source package
        path (str): Path to install directory, e.g. "~/packages"
        shim (str): Windows-only, whether to generate binary or bat scripts.
            Valid input is "binary" or "bat", default is "binary".
        as_bundle (bool): Deploy packages as one bundle. No variant will be
            installed nor returned if this is `True`.

    """

    def _deploy(destination_root):
        distribution = _package_to_distribution[package]

        # Store files from distribution for deployment
        files = list()

        if distribution.dumb:
            for relpath in _dumb_files_from_distribution(distribution):
                files += [(distribution.location, relpath)]

        else:
            for relpath in _files_from_distribution(distribution):
                files += [(distribution.location, relpath)]

        for source_root, relpath in files:
            src = os.path.join(source_root, relpath)
            src = os.path.normpath(src)

            if not os.path.exists(src):
                continue

            dst = os.path.join(root, "python", relpath)
            dst = os.path.normpath(dst)

            if not os.path.exists(os.path.dirname(dst)):
                os.makedirs(os.path.dirname(dst))

            shutil.copyfile(src, dst)

        console_scripts = find_console_scripts(distribution)

        if not console_scripts:
            return

        dst = os.path.join(destination_root, "bin")
        dst = os.path.normpath(dst)

        if not os.path.exists(dst):
            os.makedirs(dst)

        for exe, command in console_scripts.items():
            write_console_script(dst, exe, command, shim == "binary")

    if as_bundle:
        root = path
        variant_ = None
    else:
        variant = next(package.iter_variants())
        variant_ = variant.install(path)

        root = variant_.root

    if root:
        try:
            os.makedirs(root)
        except OSError as e:
            if e.errno == errno.EEXIST:
                # That's ok
                pass
            else:
                raise

    with retain_cwd():
        os.chdir(root)
        _deploy(root)

    return variant_
Beispiel #4
0
def deploy(package, path, shim="binary"):
    """Deploy `distribution` as `package` at `path`

    Arguments:
        package (rez.Package): Source package
        path (str): Path to install directory, e.g. "~/packages"

    """
    def make_root(variant, destination_root):
        distribution = _package_to_distribution[package]

        # Store files from distribution for deployment
        files = list()

        if distribution.dumb:
            for relpath in _dumb_files_from_distribution(distribution):
                files += [(distribution.location, relpath)]

        else:
            for relpath in _files_from_distribution(distribution):
                files += [(distribution.location, relpath)]

        for source_root, relpath in files:
            src = os.path.join(source_root, relpath)
            src = os.path.normpath(src)

            if not os.path.exists(src):
                continue

            dst = os.path.join(root, "python", relpath)
            dst = os.path.normpath(dst)

            if not os.path.exists(os.path.dirname(dst)):
                os.makedirs(os.path.dirname(dst))

            shutil.copyfile(src, dst)

        console_scripts = find_console_scripts(distribution)

        if not console_scripts:
            return

        dst = os.path.join(root, "bin")
        dst = os.path.normpath(dst)

        if not os.path.exists(dst):
            os.makedirs(dst)

        for exe, command in console_scripts.items():
            write_console_script(dst, exe, command, shim == "binary")

    variant = next(package.iter_variants())
    variant_ = variant.install(path)

    root = variant_.root
    if make_root and root:
        try:
            os.makedirs(root)
        except OSError as e:
            if e.errno == errno.EEXIST:
                # That's ok
                pass
            else:
                raise

    with retain_cwd():
        os.chdir(root)
        make_root(variant_, root)

    return variant_