Beispiel #1
0
def owlbot_main() -> None:
    """Copies files from staging and template directories into current working dir.

    When there is no owlbot.py file, run this function instead.

    Depends on owl-bot copying into a staging directory, so your .Owlbot.yaml should
    look a lot like this:

        docker:
            image: docker pull gcr.io/cloud-devrel-public-resources/owlbot-python:latest

        deep-remove-regex:
            - /owl-bot-staging

        deep-copy-regex:
            - source: /google/cloud/video/transcoder/(.*)/.*-nodejs/(.*)
              dest: /owl-bot-staging/$1/$2

    Also, this function requires a default_version in your .repo-metadata.json.  Ex:
        "default_version": "v1",
    """

    clean_up_generated_samples = True

    try:
        # Load the default version defined in .repo-metadata.json.
        default_version = json.load(open(".repo-metadata.json",
                                         "rt")).get("default_version")
    except FileNotFoundError:
        default_version = None

    if default_version:
        for library in s.get_staging_dirs(default_version):
            if clean_up_generated_samples:
                shutil.rmtree("samples/generated_samples", ignore_errors=True)
                clean_up_generated_samples = False
            s.move([library],
                   excludes=["setup.py", "README.rst", "docs/index.rst"])
        s.remove_staging_dirs()

        templated_files = CommonTemplates().py_library(
            microgenerator=True,
            versions=detect_versions(path="./google", default_first=True),
        )
        s.move([templated_files],
               excludes=[".coveragerc"
                         ])  # the microgenerator has a good coveragerc file

        py_samples(skip_readmes=True)

        # run blacken session for all directories which a noxfile
        for noxfile in Path(".").glob("**/noxfile.py"):
            s.shell.run(["nox", "-s", "blacken"],
                        cwd=noxfile.parent,
                        hide_output=False)

    configure_previous_major_version_branches()
        [library / "google/**/*.py", library / "tests/**/*.py"],
        "google-cloud-servicedirectory",
        "google-cloud-service-directory",
    )

    # surround path with * with ``
    s.replace(library / "google/**/*.py", """["'](projects/\*/.*)["']\.""", "``\g<1>``")

    s.move(
        library,
        excludes=[
            "setup.py",
            "README.rst",
            "docs/index.rst",
            f"scripts/fixup_servicedirectory_{library.name}_keywords.py",
        ],
    )

s.remove_staging_dirs()

# ----------------------------------------------------------------------------
# Add templated files
# ----------------------------------------------------------------------------
templated_files = common.py_library(cov_level=100, samples=False, microgenerator=True,)

s.move(
    templated_files, excludes=[".coveragerc"]
)  # the microgenerator has a good coveragerc file

s.shell.run(["nox", "-s", "blacken"], hide_output=False)