From e3d34d4cf7098f3d4317f28ee3a8f60a3f8c8558 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 30 Aug 2021 15:26:19 +0000 Subject: [PATCH 1/5] chore(python): disable dependency dashboard (#266) --- .github/.OwlBot.lock.yaml | 2 +- renovate.json | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index a9fcd07c..b75186cf 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,3 @@ docker: image: gcr.io/repo-automation-bots/owlbot-python:latest - digest: sha256:9743664022bd63a8084be67f144898314c7ca12f0a03e422ac17c733c129d803 + digest: sha256:d6761eec279244e57fe9d21f8343381a01d3632c034811a72f68b83119e58c69 diff --git a/renovate.json b/renovate.json index c0489556..9fa8816f 100644 --- a/renovate.json +++ b/renovate.json @@ -1,6 +1,8 @@ { "extends": [ - "config:base", ":preserveSemverRanges" + "config:base", + ":preserveSemverRanges", + ":disableDependencyDashboard" ], "ignorePaths": [".pre-commit-config.yaml"], "pip_requirements": { From 1db493cafff62e3a9f0b2d8ddf3071199db1af7e Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Mon, 30 Aug 2021 13:45:35 -0400 Subject: [PATCH 2/5] chore: migrate default branch to main (#264) --- .kokoro/build.sh | 2 +- .kokoro/test-samples-impl.sh | 2 +- CONTRIBUTING.rst | 12 +++---- docs/conf.py | 10 +++--- google/api_core/exceptions.py | 3 +- google/api_core/future/async_future.py | 6 ++-- google/api_core/future/polling.py | 6 ++-- noxfile.py | 12 ++++++- owlbot.py | 45 ++++++++++++++++++++++++++ 9 files changed, 78 insertions(+), 20 deletions(-) diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 8b9fd8a1..0394c8aa 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -41,7 +41,7 @@ python3 -m pip install --upgrade --quiet nox python3 -m nox --version # If this is a continuous build, send the test log to the FlakyBot. -# See https://github.com/googleapis/repo-automation-bots/tree/master/packages/flakybot. +# See https://github.com/googleapis/repo-automation-bots/tree/main/packages/flakybot. if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"continuous"* ]]; then cleanup() { chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot diff --git a/.kokoro/test-samples-impl.sh b/.kokoro/test-samples-impl.sh index 311a8d54..8a324c9c 100755 --- a/.kokoro/test-samples-impl.sh +++ b/.kokoro/test-samples-impl.sh @@ -80,7 +80,7 @@ for file in samples/**/requirements.txt; do EXIT=$? # If this is a periodic build, send the test log to the FlakyBot. - # See https://github.com/googleapis/repo-automation-bots/tree/master/packages/flakybot. + # See https://github.com/googleapis/repo-automation-bots/tree/main/packages/flakybot. if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot $KOKORO_GFILE_DIR/linux_amd64/flakybot diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 358404f2..6db668ef 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -49,9 +49,9 @@ You'll have to create a development environment using a Git checkout: # Configure remotes such that you can pull changes from the googleapis/python-api-core # repository into your local repository. $ git remote add upstream git@github.com:googleapis/python-api-core.git - # fetch and merge changes from upstream into master + # fetch and merge changes from upstream into main $ git fetch upstream - $ git merge upstream/master + $ git merge upstream/main Now your local repo is set up such that you will push changes to your GitHub repo, from which you can submit a pull request. @@ -109,12 +109,12 @@ Coding Style variables:: export GOOGLE_CLOUD_TESTING_REMOTE="upstream" - export GOOGLE_CLOUD_TESTING_BRANCH="master" + export GOOGLE_CLOUD_TESTING_BRANCH="main" By doing this, you are specifying the location of the most up-to-date version of ``python-api-core``. The the suggested remote name ``upstream`` should point to the official ``googleapis`` checkout and the - the branch should be the main branch on that remote (``master``). + the branch should be the main branch on that remote (``main``). - This repository contains configuration for the `pre-commit `__ tool, which automates checking @@ -185,7 +185,7 @@ The `description on PyPI`_ for the project comes directly from the ``README``. Due to the reStructuredText (``rst``) parser used by PyPI, relative links which will work on GitHub (e.g. ``CONTRIBUTING.rst`` instead of -``https://github.com/googleapis/python-api-core/blob/master/CONTRIBUTING.rst``) +``https://github.com/googleapis/python-api-core/blob/main/CONTRIBUTING.rst``) may cause problems creating links or rendering the description. .. _description on PyPI: https://pypi.org/project/google-api-core @@ -210,7 +210,7 @@ We support: Supported versions can be found in our ``noxfile.py`` `config`_. -.. _config: https://github.com/googleapis/python-api-core/blob/master/noxfile.py +.. _config: https://github.com/googleapis/python-api-core/blob/main/noxfile.py We also explicitly decided to support Python 3 beginning with version 3.6. diff --git a/docs/conf.py b/docs/conf.py index aec958f3..09f0c2b6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -76,8 +76,8 @@ # The encoding of source files. # source_encoding = 'utf-8-sig' -# The master toctree document. -master_doc = "index" +# The root toctree document. +root_doc = "index" # General information about the project. project = "google-api-core" @@ -280,7 +280,7 @@ # author, documentclass [howto, manual, or own class]). latex_documents = [ ( - master_doc, + root_doc, "google-api-core.tex", "google-api-core Documentation", author, @@ -314,7 +314,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, "google-api-core", "google-api-core Documentation", [author], 1,) + (root_doc, "google-api-core", "google-api-core Documentation", [author], 1,) ] # If true, show URL addresses after external links. @@ -328,7 +328,7 @@ # dir menu entry, description, category) texinfo_documents = [ ( - master_doc, + root_doc, "google-api-core", "google-api-core Documentation", author, diff --git a/google/api_core/exceptions.py b/google/api_core/exceptions.py index 13be917e..b0909f1e 100644 --- a/google/api_core/exceptions.py +++ b/google/api_core/exceptions.py @@ -293,8 +293,7 @@ class Cancelled(ClientError): """Exception mapping a :attr:`grpc.StatusCode.CANCELLED` error.""" # This maps to HTTP status code 499. See - # https://github.com/googleapis/googleapis/blob/master/google/rpc\ - # /code.proto + # https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto code = 499 grpc_status_code = grpc.StatusCode.CANCELLED if grpc is not None else None diff --git a/google/api_core/future/async_future.py b/google/api_core/future/async_future.py index 0343fbe2..88c183f9 100644 --- a/google/api_core/future/async_future.py +++ b/google/api_core/future/async_future.py @@ -43,8 +43,10 @@ class AsyncFuture(base.Future): The :meth:`done` method should be implemented by subclasses. The polling behavior will repeatedly call ``done`` until it returns True. - .. note: Privacy here is intended to prevent the final class from - overexposing, not to prevent subclasses from accessing methods. + .. note:: + + Privacy here is intended to prevent the final class from + overexposing, not to prevent subclasses from accessing methods. Args: retry (google.api_core.retry.Retry): The retry configuration used diff --git a/google/api_core/future/polling.py b/google/api_core/future/polling.py index 2f80efb5..02e680f6 100644 --- a/google/api_core/future/polling.py +++ b/google/api_core/future/polling.py @@ -45,8 +45,10 @@ class PollingFuture(base.Future): The :meth:`done` method should be implemented by subclasses. The polling behavior will repeatedly call ``done`` until it returns True. - .. note: Privacy here is intended to prevent the final class from - overexposing, not to prevent subclasses from accessing methods. + .. note:: + + Privacy here is intended to prevent the final class from + overexposing, not to prevent subclasses from accessing methods. Args: retry (google.api_core.retry.Retry): The retry configuration used diff --git a/noxfile.py b/noxfile.py index 84470f5a..6478bfde 100644 --- a/noxfile.py +++ b/noxfile.py @@ -29,7 +29,17 @@ DEFAULT_PYTHON_VERSION = "3.7" CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() -_MINIMAL_ASYNCIO_SUPPORT_PYTHON_VERSION = [3, 6] +# 'docfx' is excluded since it only needs to run in 'docs-presubmit' +nox.options.sessions = [ + "unit", + "unit_grpc_gcp", + "cover", + "pytype", + "lint", + "lint_setup_py", + "blacken", + "docs", +] def _greater_or_equal_than_36(version_string): diff --git a/owlbot.py b/owlbot.py index 451f7c48..a2f04592 100644 --- a/owlbot.py +++ b/owlbot.py @@ -44,4 +44,49 @@ """, ) +# Remove the replacements below once https://github.com/googleapis/synthtool/pull/1188 is merged + +# Update googleapis/repo-automation-bots repo to main in .kokoro/*.sh files +s.replace( + ".kokoro/*.sh", "repo-automation-bots/tree/master", "repo-automation-bots/tree/main" +) + +# Customize CONTRIBUTING.rst to replace master with main +s.replace( + "CONTRIBUTING.rst", + "fetch and merge changes from upstream into master", + "fetch and merge changes from upstream into main", +) + +s.replace( + "CONTRIBUTING.rst", "git merge upstream/master", "git merge upstream/main", +) + +s.replace( + "CONTRIBUTING.rst", + """export GOOGLE_CLOUD_TESTING_BRANCH=\"master\"""", + """export GOOGLE_CLOUD_TESTING_BRANCH=\"main\"""", +) + +s.replace( + "CONTRIBUTING.rst", r"remote \(``master``\)", "remote (``main``)", +) + +s.replace( + "CONTRIBUTING.rst", "blob/master/CONTRIBUTING.rst", "blob/main/CONTRIBUTING.rst", +) + +s.replace( + "CONTRIBUTING.rst", "blob/master/noxfile.py", "blob/main/noxfile.py", +) + +s.replace( + "docs/conf.py", "master_doc", "root_doc", +) + +s.replace( + "docs/conf.py", "# The master toctree document.", "# The root toctree document.", +) + + s.shell.run(["nox", "-s", "blacken"], hide_output=False) From 82ca2fd3792e20bea20ba96273fde4f2bb07b497 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Tue, 31 Aug 2021 13:16:20 -0400 Subject: [PATCH 3/5] tests: close coverage gap for race condition (#261) Closes #260 --- tests/unit/test_bidi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_bidi.py b/tests/unit/test_bidi.py index b876d9ad..15994ee0 100644 --- a/tests/unit/test_bidi.py +++ b/tests/unit/test_bidi.py @@ -836,7 +836,7 @@ def test_consumer_unexpected_error(self, caplog): # Wait for the consumer's thread to exit. while consumer.is_active: - pass + pass # pragma: NO COVER (race condition) on_response.assert_not_called() bidi_rpc.recv.assert_called_once() From 618f19201af729205892fcecd9c8e315ba3174a3 Mon Sep 17 00:00:00 2001 From: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Date: Tue, 31 Aug 2021 12:08:42 -0600 Subject: [PATCH 4/5] fix: do not error on LROs with no response or error (#258) Co-authored-by: Tres Seaver --- google/api_core/operation.py | 10 +++++----- google/api_core/operation_async.py | 10 +++++----- tests/asyncio/test_operation_async.py | 6 +++--- tests/unit/test_operation.py | 6 ++---- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/google/api_core/operation.py b/google/api_core/operation.py index b17f753b..a66e4a50 100644 --- a/google/api_core/operation.py +++ b/google/api_core/operation.py @@ -140,11 +140,11 @@ def _set_result_from_operation(self): ) self.set_exception(exception) else: - exception = exceptions.GoogleAPICallError( - "Unexpected state: Long-running operation had neither " - "response nor error set." - ) - self.set_exception(exception) + # Some APIs set `done: true`, with an empty response. + # Set the result to an empty message of the expected + # result type. + # https://google.aip.dev/151 + self.set_result(self._result_type()) def _refresh_and_update(self, retry=polling.DEFAULT_RETRY): """Refresh the operation and update the result if needed. diff --git a/google/api_core/operation_async.py b/google/api_core/operation_async.py index 6bae8654..17624d62 100644 --- a/google/api_core/operation_async.py +++ b/google/api_core/operation_async.py @@ -136,11 +136,11 @@ def _set_result_from_operation(self): ) self.set_exception(exception) else: - exception = exceptions.GoogleAPICallError( - "Unexpected state: Long-running operation had neither " - "response nor error set." - ) - self.set_exception(exception) + # Some APIs set `done: true`, with an empty response. + # Set the result to an empty message of the expected + # result type. + # https://google.aip.dev/151 + self.set_result(self._result_type()) async def _refresh_and_update(self, retry=async_future.DEFAULT_RETRY): """Refresh the operation and update the result if needed. diff --git a/tests/asyncio/test_operation_async.py b/tests/asyncio/test_operation_async.py index 907cda7c..342184fb 100644 --- a/tests/asyncio/test_operation_async.py +++ b/tests/asyncio/test_operation_async.py @@ -153,7 +153,7 @@ async def test_exception(): @mock.patch("asyncio.sleep", autospec=True) @pytest.mark.asyncio -async def test_unexpected_result(unused_sleep): +async def test_done_with_no_error_or_response(unused_sleep): responses = [ make_operation_proto(), # Second operation response is done, but has not error or response. @@ -161,9 +161,9 @@ async def test_unexpected_result(unused_sleep): ] future, _, _ = make_operation_future(responses) - exception = await future.exception() + result = await future.result() - assert "Unexpected state" in "{!r}".format(exception) + assert isinstance(result, struct_pb2.Struct) def test_from_gapic(): diff --git a/tests/unit/test_operation.py b/tests/unit/test_operation.py index 28fbfe27..7a3e3c6c 100644 --- a/tests/unit/test_operation.py +++ b/tests/unit/test_operation.py @@ -163,7 +163,7 @@ def test_exception_with_error_code(): assert isinstance(exception, exceptions.NotFound) -def test_unexpected_result(): +def test_done_with_no_error_or_response(): responses = [ make_operation_proto(), # Second operation response is done, but has not error or response. @@ -171,9 +171,7 @@ def test_unexpected_result(): ] future, _, _ = make_operation_future(responses) - exception = future.exception() - - assert "Unexpected state" in "{!r}".format(exception) + assert isinstance(future.result(), struct_pb2.Struct) def test__refresh_http(): From dcb6ebd9994fddcb1729150df1675ebf8c503a73 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Tue, 31 Aug 2021 15:47:14 -0400 Subject: [PATCH 5/5] chore: release 2.0.1 (#267) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- CHANGELOG.md | 7 +++++++ google/api_core/version.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3629c6e9..fdca59ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ [1]: https://pypi.org/project/google-api-core/#history +### [2.0.1](https://www.github.com/googleapis/python-api-core/compare/v2.0.0...v2.0.1) (2021-08-31) + + +### Bug Fixes + +* do not error on LROs with no response or error ([#258](https://www.github.com/googleapis/python-api-core/issues/258)) ([618f192](https://www.github.com/googleapis/python-api-core/commit/618f19201af729205892fcecd9c8e315ba3174a3)) + ## [2.0.0](https://www.github.com/googleapis/python-api-core/compare/v2.0.0-b1...v2.0.0) (2021-08-18) ### ⚠ BREAKING CHANGES diff --git a/google/api_core/version.py b/google/api_core/version.py index a12de3d2..956a957b 100644 --- a/google/api_core/version.py +++ b/google/api_core/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "2.0.0" +__version__ = "2.0.1"