From 7311f2d248ad0b2543d5827b2837c7c58fc1859a Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Mon, 17 May 2021 10:42:52 -0400 Subject: [PATCH] chore: migrate to owl bot (#158) This PR migrates from autosynth to owl bot. owl bot will save time for maintainers as it will automatically open PRs when there are updates in googleapis-gen without requiring maintainers to run synthtool to build the client from protos. Additionally, similar to autosynth, PRs will be automatically opened when there are template updates. --- .../.github/.OwlBot.yaml | 26 +++ .../.pre-commit-config.yaml | 2 +- .../CONTRIBUTING.rst | 16 +- .../docs/_static/custom.css | 13 +- .../google/cloud/speech_v1p1beta1/__init__.py | 4 +- .../google-cloud-python-speech/noxfile.py | 14 +- .../{synth.py => owlbot.py} | 53 ++--- .../google-cloud-python-speech/renovate.json | 5 +- .../samples/microphone/noxfile.py | 10 +- .../samples/snippets/noxfile.py | 10 +- .../google-cloud-python-speech/synth.metadata | 185 ------------------ 11 files changed, 85 insertions(+), 253 deletions(-) create mode 100644 packages/google-cloud-python-speech/.github/.OwlBot.yaml rename packages/google-cloud-python-speech/{synth.py => owlbot.py} (63%) delete mode 100644 packages/google-cloud-python-speech/synth.metadata diff --git a/packages/google-cloud-python-speech/.github/.OwlBot.yaml b/packages/google-cloud-python-speech/.github/.OwlBot.yaml new file mode 100644 index 000000000000..05ac93c71420 --- /dev/null +++ b/packages/google-cloud-python-speech/.github/.OwlBot.yaml @@ -0,0 +1,26 @@ +# Copyright 2021 Google LLC +# +# 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 +# +# http://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. + +docker: + image: gcr.io/repo-automation-bots/owlbot-python:latest + +deep-remove-regex: + - /owl-bot-staging + +deep-copy-regex: + - source: /google/cloud/speech/(v.*)/.*-py/(.*) + dest: /owl-bot-staging/$1/$2 + +begin-after-commit-hash: 5b168da672b70ae9b5897b268b5e62f1c932a411 + diff --git a/packages/google-cloud-python-speech/.pre-commit-config.yaml b/packages/google-cloud-python-speech/.pre-commit-config.yaml index 8912e9b5d7d7..1bbd787833ec 100644 --- a/packages/google-cloud-python-speech/.pre-commit-config.yaml +++ b/packages/google-cloud-python-speech/.pre-commit-config.yaml @@ -26,6 +26,6 @@ repos: hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 - rev: 3.9.0 + rev: 3.9.1 hooks: - id: flake8 diff --git a/packages/google-cloud-python-speech/CONTRIBUTING.rst b/packages/google-cloud-python-speech/CONTRIBUTING.rst index 780172493553..0a83859e9360 100644 --- a/packages/google-cloud-python-speech/CONTRIBUTING.rst +++ b/packages/google-cloud-python-speech/CONTRIBUTING.rst @@ -160,21 +160,7 @@ Running System Tests auth settings and change some configuration in your project to run all the tests. -- System tests will be run against an actual project and - so you'll need to provide some environment variables to facilitate - authentication to your project: - - - ``GOOGLE_APPLICATION_CREDENTIALS``: The path to a JSON key file; - Such a file can be downloaded directly from the developer's console by clicking - "Generate new JSON key". See private key - `docs `__ - for more details. - -- Once you have downloaded your json keys, set the environment variable - ``GOOGLE_APPLICATION_CREDENTIALS`` to the absolute path of the json file:: - - $ export GOOGLE_APPLICATION_CREDENTIALS="/Users//path/to/app_credentials.json" - +- System tests will be run against an actual project. You should use local credentials from gcloud when possible. See `Best practices for application authentication `__. Some tests require a service account. For those tests see `Authenticating as a service account `__. ************* Test Coverage diff --git a/packages/google-cloud-python-speech/docs/_static/custom.css b/packages/google-cloud-python-speech/docs/_static/custom.css index bcd37bbd3c4a..b0a295464b23 100644 --- a/packages/google-cloud-python-speech/docs/_static/custom.css +++ b/packages/google-cloud-python-speech/docs/_static/custom.css @@ -1,9 +1,20 @@ div#python2-eol { border-color: red; border-width: medium; -} +} /* Ensure minimum width for 'Parameters' / 'Returns' column */ dl.field-list > dt { min-width: 100px } + +/* Insert space between methods for readability */ +dl.method { + padding-top: 10px; + padding-bottom: 10px +} + +/* Insert empty space between classes */ +dl.class { + padding-bottom: 50px +} diff --git a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/__init__.py b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/__init__.py index 576dd5d0877d..a45dedd41ebe 100644 --- a/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/__init__.py +++ b/packages/google-cloud-python-speech/google/cloud/speech_v1p1beta1/__init__.py @@ -60,7 +60,6 @@ class SpeechClient(SpeechHelpers, SpeechClient): __all__ = ( - "AdaptationClient", "CreateCustomClassRequest", "CreatePhraseSetRequest", "CustomClass", @@ -83,6 +82,7 @@ class SpeechClient(SpeechHelpers, SpeechClient): "RecognizeResponse", "SpeakerDiarizationConfig", "SpeechAdaptation", + "SpeechClient", "SpeechContext", "SpeechRecognitionAlternative", "SpeechRecognitionResult", @@ -94,5 +94,5 @@ class SpeechClient(SpeechHelpers, SpeechClient): "UpdateCustomClassRequest", "UpdatePhraseSetRequest", "WordInfo", - "SpeechClient", + "AdaptationClient", ) diff --git a/packages/google-cloud-python-speech/noxfile.py b/packages/google-cloud-python-speech/noxfile.py index af50a606196c..1d45cadce4dd 100644 --- a/packages/google-cloud-python-speech/noxfile.py +++ b/packages/google-cloud-python-speech/noxfile.py @@ -62,16 +62,9 @@ def lint(session): session.run("flake8", "google", "tests") -@nox.session(python="3.6") +@nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): - """Run black. - - Format code to uniform standard. - - This currently uses Python 3.6 due to the automated Kokoro run of synthtool. - That run uses an image that doesn't have 3.6 installed. Before updating this - check the state of the `gcp_ubuntu_config` we use for that Kokoro run. - """ + """Run black. Format code to uniform standard.""" session.install(BLACK_VERSION) session.run( "black", *BLACK_PATHS, @@ -131,9 +124,6 @@ def system(session): # Check the value of `RUN_SYSTEM_TESTS` env var. It defaults to true. if os.environ.get("RUN_SYSTEM_TESTS", "true") == "false": session.skip("RUN_SYSTEM_TESTS is set to false, skipping") - # Sanity check: Only run tests if the environment variable is set. - if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""): - session.skip("Credentials must be set via environment variable") # Install pyopenssl for mTLS testing. if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true": session.install("pyopenssl") diff --git a/packages/google-cloud-python-speech/synth.py b/packages/google-cloud-python-speech/owlbot.py similarity index 63% rename from packages/google-cloud-python-speech/synth.py rename to packages/google-cloud-python-speech/owlbot.py index 55e578534f46..2b1152a9d3c8 100644 --- a/packages/google-cloud-python-speech/synth.py +++ b/packages/google-cloud-python-speech/owlbot.py @@ -18,47 +18,36 @@ from synthtool import gcp from synthtool.languages import python -gapic = gcp.GAPICBazel() common = gcp.CommonTemplates() -versions = ["v1p1beta1", "v1"] +default_version = "v1" -# ---------------------------------------------------------------------------- -# Generate speech GAPIC layer -# ---------------------------------------------------------------------------- -for version in versions: - library = gapic.py_library( - service="speech", - version=version, - bazel_target=f"//google/cloud/speech/{version}:speech-{version}-py", - include_protos=True, - ) - - # Don't move over __init__.py, as we modify it to make the generated client - # use helpers.py. - s.move(library, excludes=["setup.py", "docs/index.rst", "README.rst"]) - - -# Add the manually written SpeechHelpers to v1 and v1p1beta1 -# See google/cloud/speech_v1/helpers.py for details -count = s.replace( -["google/cloud/speech_v1/__init__.py", "google/cloud/speech_v1p1beta1/__init__.py"], -"""__all__ = \(""", -"""from google.cloud.speech_v1.helpers import SpeechHelpers +for library in s.get_staging_dirs(default_version): + # Add the manually written SpeechHelpers to v1 and v1p1beta1 + # See google/cloud/speech_v1/helpers.py for details + count = s.replace(library / f"google/cloud/speech_{library.name}/__init__.py", + """__all__ = \(""", + """from google.cloud.speech_v1.helpers import SpeechHelpers class SpeechClient(SpeechHelpers, SpeechClient): __doc__ = SpeechClient.__doc__ __all__ = ( -""", - ) + """, + ) -# Import from speech_v1 to get the client with SpeechHelpers -count = s.replace( -"google/cloud/speech/__init__.py", -"""from google\.cloud\.speech_v1\.services\.speech\.client import SpeechClient""", -"""from google.cloud.speech_v1 import SpeechClient""" -) + if library.name == "v1": + # Import from speech_v1 to get the client with SpeechHelpers + count = s.replace(library / "google/cloud/speech/__init__.py", + """from google\.cloud\.speech_v1\.services\.speech\.client import SpeechClient""", + """from google.cloud.speech_v1 import SpeechClient""" + ) + + # Don't move over __init__.py, as we modify it to make the generated client + # use helpers.py. + s.move(library, excludes=["setup.py", "docs/index.rst", "README.rst"]) + +s.remove_staging_dirs() # ---------------------------------------------------------------------------- # Add templated files diff --git a/packages/google-cloud-python-speech/renovate.json b/packages/google-cloud-python-speech/renovate.json index f08bc22c9a55..c04895563e69 100644 --- a/packages/google-cloud-python-speech/renovate.json +++ b/packages/google-cloud-python-speech/renovate.json @@ -2,5 +2,8 @@ "extends": [ "config:base", ":preserveSemverRanges" ], - "ignorePaths": [".pre-commit-config.yaml"] + "ignorePaths": [".pre-commit-config.yaml"], + "pip_requirements": { + "fileMatch": ["requirements-test.txt", "samples/[\\S/]*constraints.txt", "samples/[\\S/]*constraints-test.txt"] + } } diff --git a/packages/google-cloud-python-speech/samples/microphone/noxfile.py b/packages/google-cloud-python-speech/samples/microphone/noxfile.py index 97bf7da80e39..956cdf4f9250 100644 --- a/packages/google-cloud-python-speech/samples/microphone/noxfile.py +++ b/packages/google-cloud-python-speech/samples/microphone/noxfile.py @@ -172,10 +172,16 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): - session.install("-r", "requirements.txt") + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") if os.path.exists("requirements-test.txt"): - session.install("-r", "requirements-test.txt") + if os.path.exists("constraints-test.txt"): + session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") + else: + session.install("-r", "requirements-test.txt") if INSTALL_LIBRARY_FROM_SOURCE: session.install("-e", _get_repo_root()) diff --git a/packages/google-cloud-python-speech/samples/snippets/noxfile.py b/packages/google-cloud-python-speech/samples/snippets/noxfile.py index 97bf7da80e39..956cdf4f9250 100644 --- a/packages/google-cloud-python-speech/samples/snippets/noxfile.py +++ b/packages/google-cloud-python-speech/samples/snippets/noxfile.py @@ -172,10 +172,16 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): - session.install("-r", "requirements.txt") + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") if os.path.exists("requirements-test.txt"): - session.install("-r", "requirements-test.txt") + if os.path.exists("constraints-test.txt"): + session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") + else: + session.install("-r", "requirements-test.txt") if INSTALL_LIBRARY_FROM_SOURCE: session.install("-e", _get_repo_root()) diff --git a/packages/google-cloud-python-speech/synth.metadata b/packages/google-cloud-python-speech/synth.metadata deleted file mode 100644 index a5f8e43de2c5..000000000000 --- a/packages/google-cloud-python-speech/synth.metadata +++ /dev/null @@ -1,185 +0,0 @@ -{ - "sources": [ - { - "git": { - "name": ".", - "remote": "https://github.com/googleapis/python-speech.git", - "sha": "cc9cc3ecdef32a8bf1198aa2ff8561398bf359f8" - } - }, - { - "git": { - "name": "googleapis", - "remote": "https://github.com/googleapis/googleapis.git", - "sha": "847464c110e3cb6a5078b6b15086c73c4b622938", - "internalRef": "367346981" - } - }, - { - "git": { - "name": "synthtool", - "remote": "https://github.com/googleapis/synthtool.git", - "sha": "5b5bf6d519b2d658d9f2e483d9f6f3d0ba8ee6bc" - } - }, - { - "git": { - "name": "synthtool", - "remote": "https://github.com/googleapis/synthtool.git", - "sha": "5b5bf6d519b2d658d9f2e483d9f6f3d0ba8ee6bc" - } - } - ], - "destinations": [ - { - "client": { - "source": "googleapis", - "apiName": "speech", - "apiVersion": "v1p1beta1", - "language": "python", - "generator": "bazel" - } - }, - { - "client": { - "source": "googleapis", - "apiName": "speech", - "apiVersion": "v1", - "language": "python", - "generator": "bazel" - } - } - ], - "generatedFiles": [ - ".coveragerc", - ".flake8", - ".github/CONTRIBUTING.md", - ".github/ISSUE_TEMPLATE/bug_report.md", - ".github/ISSUE_TEMPLATE/feature_request.md", - ".github/ISSUE_TEMPLATE/support_request.md", - ".github/PULL_REQUEST_TEMPLATE.md", - ".github/header-checker-lint.yml", - ".github/release-please.yml", - ".github/snippet-bot.yml", - ".gitignore", - ".kokoro/build.sh", - ".kokoro/continuous/common.cfg", - ".kokoro/continuous/continuous.cfg", - ".kokoro/docker/docs/Dockerfile", - ".kokoro/docker/docs/fetch_gpg_keys.sh", - ".kokoro/docs/common.cfg", - ".kokoro/docs/docs-presubmit.cfg", - ".kokoro/docs/docs.cfg", - ".kokoro/populate-secrets.sh", - ".kokoro/presubmit/common.cfg", - ".kokoro/presubmit/presubmit.cfg", - ".kokoro/publish-docs.sh", - ".kokoro/release.sh", - ".kokoro/release/common.cfg", - ".kokoro/release/release.cfg", - ".kokoro/samples/lint/common.cfg", - ".kokoro/samples/lint/continuous.cfg", - ".kokoro/samples/lint/periodic.cfg", - ".kokoro/samples/lint/presubmit.cfg", - ".kokoro/samples/python3.6/common.cfg", - ".kokoro/samples/python3.6/continuous.cfg", - ".kokoro/samples/python3.6/periodic-head.cfg", - ".kokoro/samples/python3.6/periodic.cfg", - ".kokoro/samples/python3.6/presubmit.cfg", - ".kokoro/samples/python3.7/common.cfg", - ".kokoro/samples/python3.7/continuous.cfg", - ".kokoro/samples/python3.7/periodic-head.cfg", - ".kokoro/samples/python3.7/periodic.cfg", - ".kokoro/samples/python3.7/presubmit.cfg", - ".kokoro/samples/python3.8/common.cfg", - ".kokoro/samples/python3.8/continuous.cfg", - ".kokoro/samples/python3.8/periodic-head.cfg", - ".kokoro/samples/python3.8/periodic.cfg", - ".kokoro/samples/python3.8/presubmit.cfg", - ".kokoro/test-samples-against-head.sh", - ".kokoro/test-samples-impl.sh", - ".kokoro/test-samples.sh", - ".kokoro/trampoline.sh", - ".kokoro/trampoline_v2.sh", - ".pre-commit-config.yaml", - ".trampolinerc", - "CODE_OF_CONDUCT.md", - "CONTRIBUTING.rst", - "LICENSE", - "MANIFEST.in", - "docs/_static/custom.css", - "docs/_templates/layout.html", - "docs/conf.py", - "docs/multiprocessing.rst", - "docs/speech_v1/services.rst", - "docs/speech_v1/speech.rst", - "docs/speech_v1/types.rst", - "docs/speech_v1p1beta1/adaptation.rst", - "docs/speech_v1p1beta1/services.rst", - "docs/speech_v1p1beta1/speech.rst", - "docs/speech_v1p1beta1/types.rst", - "google/cloud/speech/__init__.py", - "google/cloud/speech/py.typed", - "google/cloud/speech_v1/__init__.py", - "google/cloud/speech_v1/proto/cloud_speech.proto", - "google/cloud/speech_v1/py.typed", - "google/cloud/speech_v1/services/__init__.py", - "google/cloud/speech_v1/services/speech/__init__.py", - "google/cloud/speech_v1/services/speech/async_client.py", - "google/cloud/speech_v1/services/speech/client.py", - "google/cloud/speech_v1/services/speech/transports/__init__.py", - "google/cloud/speech_v1/services/speech/transports/base.py", - "google/cloud/speech_v1/services/speech/transports/grpc.py", - "google/cloud/speech_v1/services/speech/transports/grpc_asyncio.py", - "google/cloud/speech_v1/types/__init__.py", - "google/cloud/speech_v1/types/cloud_speech.py", - "google/cloud/speech_v1p1beta1/__init__.py", - "google/cloud/speech_v1p1beta1/proto/cloud_speech.proto", - "google/cloud/speech_v1p1beta1/proto/cloud_speech_adaptation.proto", - "google/cloud/speech_v1p1beta1/proto/resource.proto", - "google/cloud/speech_v1p1beta1/py.typed", - "google/cloud/speech_v1p1beta1/services/__init__.py", - "google/cloud/speech_v1p1beta1/services/adaptation/__init__.py", - "google/cloud/speech_v1p1beta1/services/adaptation/async_client.py", - "google/cloud/speech_v1p1beta1/services/adaptation/client.py", - "google/cloud/speech_v1p1beta1/services/adaptation/pagers.py", - "google/cloud/speech_v1p1beta1/services/adaptation/transports/__init__.py", - "google/cloud/speech_v1p1beta1/services/adaptation/transports/base.py", - "google/cloud/speech_v1p1beta1/services/adaptation/transports/grpc.py", - "google/cloud/speech_v1p1beta1/services/adaptation/transports/grpc_asyncio.py", - "google/cloud/speech_v1p1beta1/services/speech/__init__.py", - "google/cloud/speech_v1p1beta1/services/speech/async_client.py", - "google/cloud/speech_v1p1beta1/services/speech/client.py", - "google/cloud/speech_v1p1beta1/services/speech/transports/__init__.py", - "google/cloud/speech_v1p1beta1/services/speech/transports/base.py", - "google/cloud/speech_v1p1beta1/services/speech/transports/grpc.py", - "google/cloud/speech_v1p1beta1/services/speech/transports/grpc_asyncio.py", - "google/cloud/speech_v1p1beta1/types/__init__.py", - "google/cloud/speech_v1p1beta1/types/cloud_speech.py", - "google/cloud/speech_v1p1beta1/types/cloud_speech_adaptation.py", - "google/cloud/speech_v1p1beta1/types/resource.py", - "mypy.ini", - "noxfile.py", - "renovate.json", - "samples/AUTHORING_GUIDE.md", - "samples/CONTRIBUTING.md", - "samples/microphone/noxfile.py", - "samples/snippets/noxfile.py", - "scripts/decrypt-secrets.sh", - "scripts/fixup_speech_v1_keywords.py", - "scripts/fixup_speech_v1p1beta1_keywords.py", - "scripts/readme-gen/readme_gen.py", - "scripts/readme-gen/templates/README.tmpl.rst", - "scripts/readme-gen/templates/auth.tmpl.rst", - "scripts/readme-gen/templates/auth_api_key.tmpl.rst", - "scripts/readme-gen/templates/install_deps.tmpl.rst", - "scripts/readme-gen/templates/install_portaudio.tmpl.rst", - "setup.cfg", - "testing/.gitignore", - "tests/unit/gapic/speech_v1/__init__.py", - "tests/unit/gapic/speech_v1/test_speech.py", - "tests/unit/gapic/speech_v1p1beta1/__init__.py", - "tests/unit/gapic/speech_v1p1beta1/test_adaptation.py", - "tests/unit/gapic/speech_v1p1beta1/test_speech.py" - ] -} \ No newline at end of file