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()
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """This script is used to synthesize generated parts of this library.""" import os import synthtool as s import synthtool.gcp as gcp from synthtool.languages import python common = gcp.CommonTemplates() default_version = "v1" for library in s.get_staging_dirs(default_version): # rename library to google-cloud-service-directory s.replace( [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",
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import synthtool as s from synthtool.languages import java for library in s.get_staging_dirs(): # put any special-case replacements here # Ensure backwards-compat for Java-microgenerator migration # Details: https://github.com/googleapis/synthtool/pull/883 java.remove_method( 'owl-bot-staging/v1/proto-google-cloud-bigquerydatatransfer-v1/src/main/java/com/google/cloud/bigquery/datatransfer/v1/DataSourceName.java', 'public static List<DataSourceName> parseList(List<String> formattedStrings)' ) java.remove_method( 'owl-bot-staging/v1/proto-google-cloud-bigquerydatatransfer-v1/src/main/java/com/google/cloud/bigquery/datatransfer/v1/DataSourceName.java', 'public static List<String> toStringList(List<DataSourceName> values)') java.remove_method( 'owl-bot-staging/v1/proto-google-cloud-bigquerydatatransfer-v1/src/main/java/com/google/cloud/bigquery/datatransfer/v1/TransferConfigName.java', 'public static List<TransferConfigName> parseList(List<String> formattedStrings)' )
import libcst as cst except ImportError: raise ImportError('Run `python -m pip install "libcst >= 0.2.5"` to install libcst.') """, ) # This library ships clients for 3 different APIs, # firestore, firestore_admin and firestore_bundle default_version = "v1" admin_default_version = "v1" bundle_default_version = "v1" for library in s.get_staging_dirs(default_version): if library.parent.absolute() == 'firestore': s.move( library / f"google/cloud/firestore_{library.name}", f"google/cloud/firestore_{library.name}", excludes=[f"google/cloud/firestore_{library.name}/__init__.py"], ) s.move(library / f"tests/", f"tests") update_fixup_scripts(library) s.move(library / "scripts") s.remove_staging_dirs() for library in s.get_staging_dirs(admin_default_version): if library.parent.absolute() == 'admin':
import pathlib import synthtool as s from synthtool import gcp from synthtool.languages import python REPO_ROOT = pathlib.Path(__file__).parent.absolute() common = gcp.CommonTemplates() # ---------------------------------------------------------------------------- # Generate bigquery_datatransfer GAPIC layer # ---------------------------------------------------------------------------- for library in s.get_staging_dirs("v1"): # Fix incorrect DeprecationWarning # Fixed in https://github.com/googleapis/gapic-generator-python/pull/943 s.replace("google/**/*client.py", "warnings\.DeprecationWarning", "DeprecationWarning") s.move(library, excludes=["*.tar.gz", "docs/index.rst", "README.rst", "setup.py"]) s.remove_staging_dirs() # ---------------------------------------------------------------------------- # Add templated files # ---------------------------------------------------------------------------- templated_files = common.py_library(microgenerator=True,
"""This script is used to synthesize generated parts of this library.""" import os import synthtool as s import synthtool.gcp as gcp from synthtool.languages import python common = gcp.CommonTemplates() # This library ships clients for two different APIs, # Workflows and Workflows Executions workflows_default_version = "v1" workflows_executions_default_version = "v1" for library in s.get_staging_dirs(workflows_executions_default_version): if library.parent.absolute() == 'executions': # Make sure this library is named 'google-cloud-workflows' s.replace( library / "google/**/*.py", "google-cloud-workflows-executions", "google-cloud-workflow" ) s.move( library, excludes=[ "setup.py", "README.rst", "docs/index.rst", f"scripts/fixup_executions_{library.name}_keywords.py", ], )
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """This script is used to synthesize generated parts of this library.""" import synthtool as s from synthtool import gcp common = gcp.CommonTemplates() # This library ships clients for two different APIs, # Datastore and Datastore Admin datastore_default_version = "v1" datastore_admin_default_version = "v1" for library in s.get_staging_dirs(datastore_default_version): if library.parent.absolute() == 'datastore': s.move(library / f"google/cloud/datastore_{library.name}") s.move(library / f"tests/") s.move(library / "scripts") for library in s.get_staging_dirs(datastore_admin_default_version): if library.parent.absolute() == 'datastore_admin': s.replace(library / "google/**/datastore_admin_client.py", "google-cloud-datastore-admin", "google-cloud-datstore") # Remove spurious markup s.replace("google/**/datastore_admin/client.py", "\s+---------------------------------(-)+", "") s.move(library / f"google/cloud/datastore_admin_{library.name}")
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """This script is used to synthesize generated parts of this library.""" import synthtool as s from synthtool import gcp from synthtool.languages import python common = gcp.CommonTemplates() spanner_default_version = "v1" spanner_admin_instance_default_version = "v1" spanner_admin_database_default_version = "v1" for library in s.get_staging_dirs(spanner_default_version): if library.parent.absolute() == "spanner": s.move(library, excludes=[ "google/cloud/spanner/**", "*.*", "docs/index.rst", "google/cloud/spanner_v1/__init__.py" ]) for library in s.get_staging_dirs(spanner_admin_instance_default_version): if library.parent.absolute() == "spanner_admin_instance": s.move(library, excludes=[ "google/cloud/spanner_admin_instance/**", "*.*", "docs/index.rst" ])