|
| 1 | +# Copyright 2022 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import json |
| 16 | +from pathlib import Path |
| 17 | +import shutil |
| 18 | + |
| 19 | +import synthtool as s |
| 20 | +import synthtool.gcp as gcp |
| 21 | +from synthtool.languages import python |
| 22 | + |
| 23 | +# ---------------------------------------------------------------------------- |
| 24 | +# Copy the generated client from the owl-bot staging directory |
| 25 | +# ---------------------------------------------------------------------------- |
| 26 | + |
| 27 | +clean_up_generated_samples = True |
| 28 | + |
| 29 | +# Load the default version defined in .repo-metadata.json. |
| 30 | +default_version = json.load(open(".repo-metadata.json", "rt")).get( |
| 31 | + "default_version" |
| 32 | +) |
| 33 | + |
| 34 | +for library in s.get_staging_dirs(default_version): |
| 35 | + if clean_up_generated_samples: |
| 36 | + shutil.rmtree("samples/generated_samples", ignore_errors=True) |
| 37 | + clean_up_generated_samples = False |
| 38 | + |
| 39 | + # remove replacement once a new gapic-generator-python version is released |
| 40 | + # which includes this fix https://github.com/googleapis/gapic-generator-python/pull/1483 |
| 41 | + s.replace( |
| 42 | + library / "testing/constraints-3.7.txt", |
| 43 | + "grpc-google-iam-v1=0", |
| 44 | + "grpc-google-iam-v1==0", |
| 45 | + ) |
| 46 | + |
| 47 | + s.move([library], excludes=["**/gapic_version.py"]) |
| 48 | +s.remove_staging_dirs() |
| 49 | + |
| 50 | +# ---------------------------------------------------------------------------- |
| 51 | +# Add templated files |
| 52 | +# ---------------------------------------------------------------------------- |
| 53 | + |
| 54 | +templated_files = gcp.CommonTemplates().py_library( |
| 55 | + cov_level=100, |
| 56 | + microgenerator=True, |
| 57 | + versions=gcp.common.detect_versions(path="./google", default_first=True), |
| 58 | +) |
| 59 | +s.move(templated_files, excludes=[".coveragerc", ".github/release-please.yml"]) |
| 60 | + |
| 61 | +python.py_samples(skip_readmes=True) |
| 62 | + |
| 63 | +# run format session for all directories which have a noxfile |
| 64 | +for noxfile in Path(".").glob("**/noxfile.py"): |
| 65 | + s.shell.run(["nox", "-s", "format"], cwd=noxfile.parent, hide_output=False) |
0 commit comments