From ffe75554f2e66f2cab17d2a170b237bf5c8d3ff6 Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Tue, 19 Dec 2023 16:02:49 -0800 Subject: [PATCH 1/8] fix(WIP): for backwards compatibility, expose legacy retry imports --- google/api_core/retry/__init__.py | 17 +++++++- tests/unit/retry/test_retry_imports.py | 55 ++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 tests/unit/retry/test_retry_imports.py diff --git a/google/api_core/retry/__init__.py b/google/api_core/retry/__init__.py index 79428415..32f27659 100644 --- a/google/api_core/retry/__init__.py +++ b/google/api_core/retry/__init__.py @@ -1,5 +1,4 @@ # Copyright 2017 Google LLC - # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -29,6 +28,22 @@ from .retry_streaming_async import AsyncStreamingRetry from .retry_streaming_async import retry_target_stream as retry_target_stream_async +# The following imports are for backwards compatibility with https://github.com/googleapis/python-api-core/blob/4d7d2edee2c108d43deb151e6e0fdceb56b73275/google/api_core/retry.py +# +# TODO: Revert these imports on the next major version release (https://github.com/googleapis/python-api-core/issues/576) +import datetime +import functools +import logging +import random +import sys +import time +import inspect +import warnings +from typing import Any, Callable, TypeVar, TYPE_CHECKING +from google.api_core import datetime_helpers +from google.api_core import exceptions +from google.auth import exceptions as auth_exceptions + __all__ = ( "exponential_sleep_generator", "if_exception_type", diff --git a/tests/unit/retry/test_retry_imports.py b/tests/unit/retry/test_retry_imports.py new file mode 100644 index 00000000..c967eb2a --- /dev/null +++ b/tests/unit/retry/test_retry_imports.py @@ -0,0 +1,55 @@ +# Copyright 2023 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. + +import pytest + +def test_legacy_imports_retry_unary_sync(): + # TODO: Delete this test when when we revert these imports on the + # next major version release + # (https://github.com/googleapis/python-api-core/issues/576) + + from google.api_core.retry import logging + from google.api_core.retry import datetime + from google.api_core.retry import functools + from google.api_core.retry import logging + from google.api_core.retry import random + from google.api_core.retry import sys + from google.api_core.retry import time + from google.api_core.retry import inspect + from google.api_core.retry import warnings + from google.api_core.retry import Any, Callable, TypeVar, TYPE_CHECKING + + from google.api_core.retry import datetime_helpers + from google.api_core.retry import exceptions + from google.api_core.retry import auth_exceptions + + ### FIXME: How do we test the following, and how do we import it in __init__.py? + # import google.api_core.retry.requests.exceptions + + +def test_legacy_imports_retry_unary_async(): + # TODO: Delete this test when when we revert these imports on the + # next major version release + # (https://github.com/googleapis/python-api-core/issues/576) + + from google.api_core import retry_async + + ### FIXME: each of the following cause errors on the "retry_async" part: module not found + # import google.api_core.retry_async.functools + # from google.api_core.retry_async import functools + # + ## For the above, I tried the following in api_core/__init__.py + ## and none made the above statements pass: + # from google.api_core.retry import retry_unary_async as retry_async + # import google.api_core.retry.retry_unary_async as retry_async From 5bcd7a3968e98f05024ce47c7334504ffab48290 Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Fri, 26 Jan 2024 13:21:59 -0800 Subject: [PATCH 2/8] fix: add legacy imports to preserve backwards compatibility --- google/api_core/retry/__init__.py | 24 ++++++++++----------- tests/unit/retry/test_retry_imports.py | 30 ++++++++++++-------------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/google/api_core/retry/__init__.py b/google/api_core/retry/__init__.py index 32f27659..7402563a 100644 --- a/google/api_core/retry/__init__.py +++ b/google/api_core/retry/__init__.py @@ -31,18 +31,18 @@ # The following imports are for backwards compatibility with https://github.com/googleapis/python-api-core/blob/4d7d2edee2c108d43deb151e6e0fdceb56b73275/google/api_core/retry.py # # TODO: Revert these imports on the next major version release (https://github.com/googleapis/python-api-core/issues/576) -import datetime -import functools -import logging -import random -import sys -import time -import inspect -import warnings -from typing import Any, Callable, TypeVar, TYPE_CHECKING -from google.api_core import datetime_helpers -from google.api_core import exceptions -from google.auth import exceptions as auth_exceptions +import datetime # noqa: F401 +import functools # noqa: F401 +import logging # noqa: F401 +import random # noqa: F401 +import sys # noqa: F401 +import time # noqa: F401 +import inspect # noqa: F401 +import warnings # noqa: F401 +from typing import Any, Callable, TypeVar, TYPE_CHECKING # noqa: F401 +from google.api_core import datetime_helpers # noqa: F401 +from google.api_core import exceptions # noqa: F401 +from google.auth import exceptions as auth_exceptions # noqa: F401 __all__ = ( "exponential_sleep_generator", diff --git a/tests/unit/retry/test_retry_imports.py b/tests/unit/retry/test_retry_imports.py index c967eb2a..5525e6f8 100644 --- a/tests/unit/retry/test_retry_imports.py +++ b/tests/unit/retry/test_retry_imports.py @@ -12,27 +12,25 @@ # See the License for the specific language governing permissions and # limitations under the License. -import pytest - def test_legacy_imports_retry_unary_sync(): # TODO: Delete this test when when we revert these imports on the # next major version release # (https://github.com/googleapis/python-api-core/issues/576) from google.api_core.retry import logging - from google.api_core.retry import datetime - from google.api_core.retry import functools - from google.api_core.retry import logging - from google.api_core.retry import random - from google.api_core.retry import sys - from google.api_core.retry import time - from google.api_core.retry import inspect - from google.api_core.retry import warnings - from google.api_core.retry import Any, Callable, TypeVar, TYPE_CHECKING - - from google.api_core.retry import datetime_helpers - from google.api_core.retry import exceptions - from google.api_core.retry import auth_exceptions + from google.api_core.retry import datetime # noqa: F401 + from google.api_core.retry import functools # noqa: F401 + from google.api_core.retry import logging # noqa: F401 + from google.api_core.retry import random # noqa: F401 + from google.api_core.retry import sys # noqa: F401 + from google.api_core.retry import time # noqa: F401 + from google.api_core.retry import inspect # noqa: F401 + from google.api_core.retry import warnings # noqa: F401 + from google.api_core.retry import Any, Callable, TypeVar, TYPE_CHECKING # noqa: F401 + + from google.api_core.retry import datetime_helpers # noqa: F401 + from google.api_core.retry import exceptions # noqa: F401 + from google.api_core.retry import auth_exceptions # noqa: F401 ### FIXME: How do we test the following, and how do we import it in __init__.py? # import google.api_core.retry.requests.exceptions @@ -43,7 +41,7 @@ def test_legacy_imports_retry_unary_async(): # next major version release # (https://github.com/googleapis/python-api-core/issues/576) - from google.api_core import retry_async + from google.api_core import retry_async # noqa: F401 ### FIXME: each of the following cause errors on the "retry_async" part: module not found # import google.api_core.retry_async.functools From b25579ebf0fbd9dcf3ccf2ff51801c04a016a623 Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Fri, 26 Jan 2024 13:37:15 -0800 Subject: [PATCH 3/8] reformat as requiired by prechecks --- tests/unit/retry/test_retry_imports.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/unit/retry/test_retry_imports.py b/tests/unit/retry/test_retry_imports.py index 5525e6f8..cd002e63 100644 --- a/tests/unit/retry/test_retry_imports.py +++ b/tests/unit/retry/test_retry_imports.py @@ -12,12 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. + def test_legacy_imports_retry_unary_sync(): # TODO: Delete this test when when we revert these imports on the # next major version release # (https://github.com/googleapis/python-api-core/issues/576) - from google.api_core.retry import logging from google.api_core.retry import datetime # noqa: F401 from google.api_core.retry import functools # noqa: F401 from google.api_core.retry import logging # noqa: F401 @@ -26,7 +26,12 @@ def test_legacy_imports_retry_unary_sync(): from google.api_core.retry import time # noqa: F401 from google.api_core.retry import inspect # noqa: F401 from google.api_core.retry import warnings # noqa: F401 - from google.api_core.retry import Any, Callable, TypeVar, TYPE_CHECKING # noqa: F401 + from google.api_core.retry import ( + Any, # noqa: F401 + Callable, # noqa: F401 + TypeVar, # noqa: F401 + TYPE_CHECKING, # noqa: F401 + ) from google.api_core.retry import datetime_helpers # noqa: F401 from google.api_core.retry import exceptions # noqa: F401 From febe8b818dd8c3ef31159c0d23f6c06a9c22563a Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Fri, 26 Jan 2024 13:47:01 -0800 Subject: [PATCH 4/8] Import individually --- tests/unit/retry/test_retry_imports.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/unit/retry/test_retry_imports.py b/tests/unit/retry/test_retry_imports.py index cd002e63..0a0e42bd 100644 --- a/tests/unit/retry/test_retry_imports.py +++ b/tests/unit/retry/test_retry_imports.py @@ -26,12 +26,10 @@ def test_legacy_imports_retry_unary_sync(): from google.api_core.retry import time # noqa: F401 from google.api_core.retry import inspect # noqa: F401 from google.api_core.retry import warnings # noqa: F401 - from google.api_core.retry import ( - Any, # noqa: F401 - Callable, # noqa: F401 - TypeVar, # noqa: F401 - TYPE_CHECKING, # noqa: F401 - ) + from google.api_core.retry import Any # noqa: F401 + from google.api_core.retry import Callable # noqa: F401 + from google.api_core.retry import TypeVar # noqa: F401 + from google.api_core.retry import TYPE_CHECKING # noqa: F401 from google.api_core.retry import datetime_helpers # noqa: F401 from google.api_core.retry import exceptions # noqa: F401 From 6e7e90bcb4f490003d0b8a3be8ea4b57230fc95e Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Mon, 29 Jan 2024 13:11:08 -0800 Subject: [PATCH 5/8] fix: do not expose transitive imports purely for bw compatibility --- google/api_core/retry/__init__.py | 9 --------- tests/unit/retry/test_retry_imports.py | 24 ------------------------ 2 files changed, 33 deletions(-) diff --git a/google/api_core/retry/__init__.py b/google/api_core/retry/__init__.py index 7402563a..1724fdbd 100644 --- a/google/api_core/retry/__init__.py +++ b/google/api_core/retry/__init__.py @@ -31,15 +31,6 @@ # The following imports are for backwards compatibility with https://github.com/googleapis/python-api-core/blob/4d7d2edee2c108d43deb151e6e0fdceb56b73275/google/api_core/retry.py # # TODO: Revert these imports on the next major version release (https://github.com/googleapis/python-api-core/issues/576) -import datetime # noqa: F401 -import functools # noqa: F401 -import logging # noqa: F401 -import random # noqa: F401 -import sys # noqa: F401 -import time # noqa: F401 -import inspect # noqa: F401 -import warnings # noqa: F401 -from typing import Any, Callable, TypeVar, TYPE_CHECKING # noqa: F401 from google.api_core import datetime_helpers # noqa: F401 from google.api_core import exceptions # noqa: F401 from google.auth import exceptions as auth_exceptions # noqa: F401 diff --git a/tests/unit/retry/test_retry_imports.py b/tests/unit/retry/test_retry_imports.py index 0a0e42bd..adbf6004 100644 --- a/tests/unit/retry/test_retry_imports.py +++ b/tests/unit/retry/test_retry_imports.py @@ -17,20 +17,6 @@ def test_legacy_imports_retry_unary_sync(): # TODO: Delete this test when when we revert these imports on the # next major version release # (https://github.com/googleapis/python-api-core/issues/576) - - from google.api_core.retry import datetime # noqa: F401 - from google.api_core.retry import functools # noqa: F401 - from google.api_core.retry import logging # noqa: F401 - from google.api_core.retry import random # noqa: F401 - from google.api_core.retry import sys # noqa: F401 - from google.api_core.retry import time # noqa: F401 - from google.api_core.retry import inspect # noqa: F401 - from google.api_core.retry import warnings # noqa: F401 - from google.api_core.retry import Any # noqa: F401 - from google.api_core.retry import Callable # noqa: F401 - from google.api_core.retry import TypeVar # noqa: F401 - from google.api_core.retry import TYPE_CHECKING # noqa: F401 - from google.api_core.retry import datetime_helpers # noqa: F401 from google.api_core.retry import exceptions # noqa: F401 from google.api_core.retry import auth_exceptions # noqa: F401 @@ -43,14 +29,4 @@ def test_legacy_imports_retry_unary_async(): # TODO: Delete this test when when we revert these imports on the # next major version release # (https://github.com/googleapis/python-api-core/issues/576) - from google.api_core import retry_async # noqa: F401 - - ### FIXME: each of the following cause errors on the "retry_async" part: module not found - # import google.api_core.retry_async.functools - # from google.api_core.retry_async import functools - # - ## For the above, I tried the following in api_core/__init__.py - ## and none made the above statements pass: - # from google.api_core.retry import retry_unary_async as retry_async - # import google.api_core.retry.retry_unary_async as retry_async From f7b633743d85fd4b244e39535517d6171b873adc Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Mon, 29 Jan 2024 13:23:08 -0800 Subject: [PATCH 6/8] remove cruft --- tests/unit/retry/test_retry_imports.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/unit/retry/test_retry_imports.py b/tests/unit/retry/test_retry_imports.py index adbf6004..d2d33b63 100644 --- a/tests/unit/retry/test_retry_imports.py +++ b/tests/unit/retry/test_retry_imports.py @@ -21,10 +21,6 @@ def test_legacy_imports_retry_unary_sync(): from google.api_core.retry import exceptions # noqa: F401 from google.api_core.retry import auth_exceptions # noqa: F401 - ### FIXME: How do we test the following, and how do we import it in __init__.py? - # import google.api_core.retry.requests.exceptions - - def test_legacy_imports_retry_unary_async(): # TODO: Delete this test when when we revert these imports on the # next major version release From 7f542ec4d1222448ee209d469247ca0edafb8751 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 29 Jan 2024 21:26:07 +0000 Subject: [PATCH 7/8] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- tests/unit/retry/test_retry_imports.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/retry/test_retry_imports.py b/tests/unit/retry/test_retry_imports.py index d2d33b63..0bb92a4e 100644 --- a/tests/unit/retry/test_retry_imports.py +++ b/tests/unit/retry/test_retry_imports.py @@ -21,6 +21,7 @@ def test_legacy_imports_retry_unary_sync(): from google.api_core.retry import exceptions # noqa: F401 from google.api_core.retry import auth_exceptions # noqa: F401 + def test_legacy_imports_retry_unary_async(): # TODO: Delete this test when when we revert these imports on the # next major version release From 821ebce6a4ddd5c841b2f07074b7d463573c49f3 Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Mon, 29 Jan 2024 13:31:10 -0800 Subject: [PATCH 8/8] Update Copyright year --- tests/unit/retry/test_retry_imports.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/retry/test_retry_imports.py b/tests/unit/retry/test_retry_imports.py index 0bb92a4e..5d035be4 100644 --- a/tests/unit/retry/test_retry_imports.py +++ b/tests/unit/retry/test_retry_imports.py @@ -1,4 +1,4 @@ -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.