コード例 #1
0
def init_dist_target(project, logger):
    dist_target = project.expand_path("$" + DISTRIBUTION_PROPERTY)

    if exists(dist_target):
        logger.debug("Removing preexisting distribution %s", dist_target)
        shutil.rmtree(dist_target)

    logger.debug("Creating directory %s", dist_target)
    makedirs(dist_target)
コード例 #2
0
def vendorize(project, reactor, logger):
    target_dir = project.expand_path("$vendorize_target_dir")
    packages = [
        Dependency(p)
        for p in as_list(project.get_property("vendorize_packages"))
    ]
    clean = project.get_property("vendorize_clean_target_dir")
    logfile = project.expand_path("$dir_logs", "vendorize.log")

    logger.info("Will vendorize packages %r into %r%s", packages, target_dir,
                " (cleaning)" if clean else "")

    if clean:
        rmtree(target_dir, ignore_errors=False)
    makedirs(target_dir, exist_ok=True)

    reactor.pybuilder_venv.install_dependencies(packages,
                                                install_log_path=logfile,
                                                package_type="vendorized",
                                                target_dir=target_dir,
                                                ignore_installed=True)

    # Vendorize
    _vendorize(target_dir)

    # Cleanup globs
    for g in project.get_property("vendorize_cleanup_globs"):
        for p in iglob(jp(target_dir, g)):
            if isdir(p):
                rmtree(p)
            else:
                unlink(p)

    # Populate names after cleanup
    cleaned_up_packages = _list_top_level_packages(target_dir)
    with open(jp(target_dir, "__init__.py"), "wt") as init_py:
        init_py.write("__names__ = %r\n" % sorted(cleaned_up_packages))

    # Cleanup metadata
    for p in _list_metadata_dirs(target_dir):
        if isdir(p):
            rmtree(p)
        else:
            unlink(p)
コード例 #3
0
def vendorize(project, reactor, logger):
    target_dir = project.expand_path("$vendorize_target_dir")
    packages = [
        Dependency(p)
        for p in as_list(project.get_property("vendorize_packages"))
    ]
    clean = project.get_property("vendorize_clean_target_dir")
    logfile = project.expand_path("$dir_logs", "vendorize.log")

    logger.info("Will vendorize packages %r into %r%s", packages, target_dir,
                " (cleaning)" if clean else "")

    if clean:
        rmtree(target_dir, ignore_errors=False)
    makedirs(target_dir, exist_ok=True)

    reactor.pybuilder_venv.install_dependencies(packages,
                                                install_log_path=logfile,
                                                package_type="vendorized",
                                                target_dir=target_dir,
                                                ignore_installed=True)

    # Vendorize
    _vendorize(target_dir, logger)

    if project.get_property("vendorize_collect_licenses"):
        licenses_content = ""
        for p in _list_metadata_dirs(target_dir):
            package_name, _ = splitext(basename(p))
            lic_file = None
            for f in ("LICENSE", "LICENSE.txt"):
                f = jp(p, f)
                if exists(f):
                    lic_file = f
                    break

            if not lic_file:
                logger.warn("No license file found in package %r",
                            package_name)
                continue

            with open(lic_file, "rt") as f:
                licenses_content += "%s\n==========\n%s\n\n" % (package_name,
                                                                f.read())

            logger.debug("Collected license file for package %r", package_name)

        with open(project.expand_path("$vendorize_licenses"), "wt") as f:
            f.write(licenses_content)

    # Cleanup globs
    for g in project.get_property("vendorize_cleanup_globs"):
        for p in iglob(jp(target_dir, g), recursive=True):
            print(p)
            if isdir(p):
                rmtree(p)
            else:
                unlink(p)

    # Cleanup metadata
    for p in _list_metadata_dirs(target_dir):
        if isdir(p):
            rmtree(p)
        else:
            unlink(p)

    # Populate names after cleanup
    cleaned_up_packages = list(
        chain((basename(dirname(f))
               for f in iglob(jp(target_dir, "*", "__init__.py"))),
              (basename(f)[:-3] for f in iglob(jp(target_dir, "*.py")))))
    with open(jp(target_dir, "__init__.py"), "wt") as init_py:
        init_py.write("__names__ = %r\n" % sorted(cleaned_up_packages))