From f5feaca57912640e7f04bb23756a4c69bbb89888 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Wed, 16 Aug 2023 15:54:38 +0000 Subject: [PATCH] fix: Add deprecation warning for python 3.7 --- .../templates/%namespace/%name/__init__.py.j2 | 24 +++++++++++++++++++ .../%name_%version/%sub/__init__.py.j2 | 23 ++++++++++++++++++ .../asset/google/cloud/asset/__init__.py | 24 +++++++++++++++++++ .../asset/google/cloud/asset_v1/__init__.py | 23 ++++++++++++++++++ .../google/iam/credentials/__init__.py | 24 +++++++++++++++++++ .../google/iam/credentials_v1/__init__.py | 23 ++++++++++++++++++ .../google/cloud/eventarc/__init__.py | 24 +++++++++++++++++++ .../google/cloud/eventarc_v1/__init__.py | 23 ++++++++++++++++++ .../logging/google/cloud/logging/__init__.py | 24 +++++++++++++++++++ .../google/cloud/logging_v2/__init__.py | 23 ++++++++++++++++++ .../redis/google/cloud/redis/__init__.py | 24 +++++++++++++++++++ .../redis/google/cloud/redis_v1/__init__.py | 23 ++++++++++++++++++ 12 files changed, 282 insertions(+) diff --git a/gapic/templates/%namespace/%name/__init__.py.j2 b/gapic/templates/%namespace/%name/__init__.py.j2 index a5e61f219a..c13742185e 100644 --- a/gapic/templates/%namespace/%name/__init__.py.j2 +++ b/gapic/templates/%namespace/%name/__init__.py.j2 @@ -1,6 +1,9 @@ {% extends '_base.py.j2' %} {% block content %} +import sys +import warnings + {% set package_path = api.naming.module_namespace|join('.') + "." + api.naming.module_name %} from {{package_path}} import gapic_version as package_version @@ -48,6 +51,27 @@ from {% if api.naming.module_namespace %}{{ api.naming.module_namespace|join('.' them again. #} + +class Python37DeprecationWarning(DeprecationWarning): + """ + Deprecation warning raised when Python 3.7 runtime is detected. + Python 3.7 support will be dropped after January 1, 2024. See + https://cloud.google.com/python/docs/python37-sunset/ for more information. + """ + pass + +# Checks if the current runtime is Python 3.7. +if sys.version_info.major == 3 and sys.version_info.minor == 7: + message = ( + "After January 1, 2024, new releases of this client library will drop support " + "for Python 3.7. More details about Python 3.7 support for Client Libraries " + "can be found at https://cloud.google.com/python/docs/python37-sunset/" + ) + # Configure the Python37DeprecationWarning warning so that it is only emitted once. + warnings.simplefilter('once', Python37DeprecationWarning) + warnings.warn(message, Python37DeprecationWarning) + + __all__ = ( {%- filter indent %} {% for subpackage, _ in api.subpackages|dictsort %} diff --git a/gapic/templates/%namespace/%name_%version/%sub/__init__.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/__init__.py.j2 index 8ee1670431..6568981484 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/__init__.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/__init__.py.j2 @@ -2,6 +2,9 @@ {% block content %} +import sys +import warnings + {% set package_path = api.naming.module_namespace|join('.') + "." + api.naming.versioned_module_name %} from {{package_path}} import gapic_version as package_version @@ -36,6 +39,26 @@ from .types.{{ proto.module_name }} import {{ enum.name }} {% endfor %} {% endfor %} + +class Python37DeprecationWarning(DeprecationWarning): + """ + Deprecation warning raised when Python 3.7 runtime is detected. + Python 3.7 support will be dropped after January 1, 2024. See + https://cloud.google.com/python/docs/python37-sunset/ for more information. + """ + pass + +# Checks if the current runtime is Python 3.7. +if sys.version_info.major == 3 and sys.version_info.minor == 7: + message = ( + "After January 1, 2024, new releases of this client library will drop support " + "for Python 3.7. More details about Python 3.7 support for Client Libraries " + "can be found at https://cloud.google.com/python/docs/python37-sunset/" + ) + # print only the first occurrence of Python37DeprecationWarning, regardless of location + warnings.simplefilter('once', Python37DeprecationWarning) + warnings.warn(message, Python37DeprecationWarning) + {# Define __all__. This requires the full set of imported names, so we iterate over them again. diff --git a/tests/integration/goldens/asset/google/cloud/asset/__init__.py b/tests/integration/goldens/asset/google/cloud/asset/__init__.py index 366ca0861d..61ff227013 100755 --- a/tests/integration/goldens/asset/google/cloud/asset/__init__.py +++ b/tests/integration/goldens/asset/google/cloud/asset/__init__.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import sys +import warnings + from google.cloud.asset import gapic_version as package_version __version__ = package_version.__version__ @@ -99,6 +102,27 @@ from google.cloud.asset_v1.types.assets import TimeWindow from google.cloud.asset_v1.types.assets import VersionedResource + +class Python37DeprecationWarning(DeprecationWarning): + """ + Deprecation warning raised when Python 3.7 runtime is detected. + Python 3.7 support will be dropped after January 1, 2024. See + https://cloud.google.com/python/docs/python37-sunset/ for more information. + """ + pass + +# Checks if the current runtime is Python 3.7. +if sys.version_info.major == 3 and sys.version_info.minor == 7: + message = ( + "After January 1, 2024, new releases of this client library will drop support " + "for Python 3.7. More details about Python 3.7 support for Client Libraries " + "can be found at https://cloud.google.com/python/docs/python37-sunset/" + ) + # Configure the Python37DeprecationWarning warning so that it is only emitted once. + warnings.simplefilter('once', Python37DeprecationWarning) + warnings.warn(message, Python37DeprecationWarning) + + __all__ = ('AssetServiceClient', 'AssetServiceAsyncClient', 'AnalyzeIamPolicyLongrunningMetadata', diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/__init__.py b/tests/integration/goldens/asset/google/cloud/asset_v1/__init__.py index 8fbe3ed54f..c10ce5dcb6 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/__init__.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/__init__.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import sys +import warnings + from google.cloud.asset_v1 import gapic_version as package_version __version__ = package_version.__version__ @@ -99,6 +102,26 @@ from .types.assets import TimeWindow from .types.assets import VersionedResource + +class Python37DeprecationWarning(DeprecationWarning): + """ + Deprecation warning raised when Python 3.7 runtime is detected. + Python 3.7 support will be dropped after January 1, 2024. See + https://cloud.google.com/python/docs/python37-sunset/ for more information. + """ + pass + +# Checks if the current runtime is Python 3.7. +if sys.version_info.major == 3 and sys.version_info.minor == 7: + message = ( + "After January 1, 2024, new releases of this client library will drop support " + "for Python 3.7. More details about Python 3.7 support for Client Libraries " + "can be found at https://cloud.google.com/python/docs/python37-sunset/" + ) + # print only the first occurrence of Python37DeprecationWarning, regardless of location + warnings.simplefilter('once', Python37DeprecationWarning) + warnings.warn(message, Python37DeprecationWarning) + __all__ = ( 'AssetServiceAsyncClient', 'AnalyzeIamPolicyLongrunningMetadata', diff --git a/tests/integration/goldens/credentials/google/iam/credentials/__init__.py b/tests/integration/goldens/credentials/google/iam/credentials/__init__.py index 6344d9b69f..0ff3150fb0 100755 --- a/tests/integration/goldens/credentials/google/iam/credentials/__init__.py +++ b/tests/integration/goldens/credentials/google/iam/credentials/__init__.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import sys +import warnings + from google.iam.credentials import gapic_version as package_version __version__ = package_version.__version__ @@ -30,6 +33,27 @@ from google.iam.credentials_v1.types.common import SignJwtRequest from google.iam.credentials_v1.types.common import SignJwtResponse + +class Python37DeprecationWarning(DeprecationWarning): + """ + Deprecation warning raised when Python 3.7 runtime is detected. + Python 3.7 support will be dropped after January 1, 2024. See + https://cloud.google.com/python/docs/python37-sunset/ for more information. + """ + pass + +# Checks if the current runtime is Python 3.7. +if sys.version_info.major == 3 and sys.version_info.minor == 7: + message = ( + "After January 1, 2024, new releases of this client library will drop support " + "for Python 3.7. More details about Python 3.7 support for Client Libraries " + "can be found at https://cloud.google.com/python/docs/python37-sunset/" + ) + # Configure the Python37DeprecationWarning warning so that it is only emitted once. + warnings.simplefilter('once', Python37DeprecationWarning) + warnings.warn(message, Python37DeprecationWarning) + + __all__ = ('IAMCredentialsClient', 'IAMCredentialsAsyncClient', 'GenerateAccessTokenRequest', diff --git a/tests/integration/goldens/credentials/google/iam/credentials_v1/__init__.py b/tests/integration/goldens/credentials/google/iam/credentials_v1/__init__.py index 10dccc1f36..60693c184c 100755 --- a/tests/integration/goldens/credentials/google/iam/credentials_v1/__init__.py +++ b/tests/integration/goldens/credentials/google/iam/credentials_v1/__init__.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import sys +import warnings + from google.iam.credentials_v1 import gapic_version as package_version __version__ = package_version.__version__ @@ -30,6 +33,26 @@ from .types.common import SignJwtRequest from .types.common import SignJwtResponse + +class Python37DeprecationWarning(DeprecationWarning): + """ + Deprecation warning raised when Python 3.7 runtime is detected. + Python 3.7 support will be dropped after January 1, 2024. See + https://cloud.google.com/python/docs/python37-sunset/ for more information. + """ + pass + +# Checks if the current runtime is Python 3.7. +if sys.version_info.major == 3 and sys.version_info.minor == 7: + message = ( + "After January 1, 2024, new releases of this client library will drop support " + "for Python 3.7. More details about Python 3.7 support for Client Libraries " + "can be found at https://cloud.google.com/python/docs/python37-sunset/" + ) + # print only the first occurrence of Python37DeprecationWarning, regardless of location + warnings.simplefilter('once', Python37DeprecationWarning) + warnings.warn(message, Python37DeprecationWarning) + __all__ = ( 'IAMCredentialsAsyncClient', 'GenerateAccessTokenRequest', diff --git a/tests/integration/goldens/eventarc/google/cloud/eventarc/__init__.py b/tests/integration/goldens/eventarc/google/cloud/eventarc/__init__.py index 76921a7ee0..cbd1a0eb83 100755 --- a/tests/integration/goldens/eventarc/google/cloud/eventarc/__init__.py +++ b/tests/integration/goldens/eventarc/google/cloud/eventarc/__init__.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import sys +import warnings + from google.cloud.eventarc import gapic_version as package_version __version__ = package_version.__version__ @@ -59,6 +62,27 @@ from google.cloud.eventarc_v1.types.trigger import Transport from google.cloud.eventarc_v1.types.trigger import Trigger + +class Python37DeprecationWarning(DeprecationWarning): + """ + Deprecation warning raised when Python 3.7 runtime is detected. + Python 3.7 support will be dropped after January 1, 2024. See + https://cloud.google.com/python/docs/python37-sunset/ for more information. + """ + pass + +# Checks if the current runtime is Python 3.7. +if sys.version_info.major == 3 and sys.version_info.minor == 7: + message = ( + "After January 1, 2024, new releases of this client library will drop support " + "for Python 3.7. More details about Python 3.7 support for Client Libraries " + "can be found at https://cloud.google.com/python/docs/python37-sunset/" + ) + # Configure the Python37DeprecationWarning warning so that it is only emitted once. + warnings.simplefilter('once', Python37DeprecationWarning) + warnings.warn(message, Python37DeprecationWarning) + + __all__ = ('EventarcClient', 'EventarcAsyncClient', 'Channel', diff --git a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/__init__.py b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/__init__.py index 5b322f29c5..cd8428a65b 100755 --- a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/__init__.py +++ b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/__init__.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import sys +import warnings + from google.cloud.eventarc_v1 import gapic_version as package_version __version__ = package_version.__version__ @@ -59,6 +62,26 @@ from .types.trigger import Transport from .types.trigger import Trigger + +class Python37DeprecationWarning(DeprecationWarning): + """ + Deprecation warning raised when Python 3.7 runtime is detected. + Python 3.7 support will be dropped after January 1, 2024. See + https://cloud.google.com/python/docs/python37-sunset/ for more information. + """ + pass + +# Checks if the current runtime is Python 3.7. +if sys.version_info.major == 3 and sys.version_info.minor == 7: + message = ( + "After January 1, 2024, new releases of this client library will drop support " + "for Python 3.7. More details about Python 3.7 support for Client Libraries " + "can be found at https://cloud.google.com/python/docs/python37-sunset/" + ) + # print only the first occurrence of Python37DeprecationWarning, regardless of location + warnings.simplefilter('once', Python37DeprecationWarning) + warnings.warn(message, Python37DeprecationWarning) + __all__ = ( 'EventarcAsyncClient', 'Channel', diff --git a/tests/integration/goldens/logging/google/cloud/logging/__init__.py b/tests/integration/goldens/logging/google/cloud/logging/__init__.py index fb661a83ae..740d27c0a0 100755 --- a/tests/integration/goldens/logging/google/cloud/logging/__init__.py +++ b/tests/integration/goldens/logging/google/cloud/logging/__init__.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import sys +import warnings + from google.cloud.logging import gapic_version as package_version __version__ = package_version.__version__ @@ -102,6 +105,27 @@ from google.cloud.logging_v2.types.logging_metrics import LogMetric from google.cloud.logging_v2.types.logging_metrics import UpdateLogMetricRequest + +class Python37DeprecationWarning(DeprecationWarning): + """ + Deprecation warning raised when Python 3.7 runtime is detected. + Python 3.7 support will be dropped after January 1, 2024. See + https://cloud.google.com/python/docs/python37-sunset/ for more information. + """ + pass + +# Checks if the current runtime is Python 3.7. +if sys.version_info.major == 3 and sys.version_info.minor == 7: + message = ( + "After January 1, 2024, new releases of this client library will drop support " + "for Python 3.7. More details about Python 3.7 support for Client Libraries " + "can be found at https://cloud.google.com/python/docs/python37-sunset/" + ) + # Configure the Python37DeprecationWarning warning so that it is only emitted once. + warnings.simplefilter('once', Python37DeprecationWarning) + warnings.warn(message, Python37DeprecationWarning) + + __all__ = ('ConfigServiceV2Client', 'ConfigServiceV2AsyncClient', 'LoggingServiceV2Client', diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/__init__.py b/tests/integration/goldens/logging/google/cloud/logging_v2/__init__.py index b6bfee061f..5f9212d118 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/__init__.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/__init__.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import sys +import warnings + from google.cloud.logging_v2 import gapic_version as package_version __version__ = package_version.__version__ @@ -102,6 +105,26 @@ from .types.logging_metrics import LogMetric from .types.logging_metrics import UpdateLogMetricRequest + +class Python37DeprecationWarning(DeprecationWarning): + """ + Deprecation warning raised when Python 3.7 runtime is detected. + Python 3.7 support will be dropped after January 1, 2024. See + https://cloud.google.com/python/docs/python37-sunset/ for more information. + """ + pass + +# Checks if the current runtime is Python 3.7. +if sys.version_info.major == 3 and sys.version_info.minor == 7: + message = ( + "After January 1, 2024, new releases of this client library will drop support " + "for Python 3.7. More details about Python 3.7 support for Client Libraries " + "can be found at https://cloud.google.com/python/docs/python37-sunset/" + ) + # print only the first occurrence of Python37DeprecationWarning, regardless of location + warnings.simplefilter('once', Python37DeprecationWarning) + warnings.warn(message, Python37DeprecationWarning) + __all__ = ( 'ConfigServiceV2AsyncClient', 'LoggingServiceV2AsyncClient', diff --git a/tests/integration/goldens/redis/google/cloud/redis/__init__.py b/tests/integration/goldens/redis/google/cloud/redis/__init__.py index 92a9215362..e60f097d08 100755 --- a/tests/integration/goldens/redis/google/cloud/redis/__init__.py +++ b/tests/integration/goldens/redis/google/cloud/redis/__init__.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import sys +import warnings + from google.cloud.redis import gapic_version as package_version __version__ = package_version.__version__ @@ -49,6 +52,27 @@ from google.cloud.redis_v1.types.cloud_redis import WeeklyMaintenanceWindow from google.cloud.redis_v1.types.cloud_redis import ZoneMetadata + +class Python37DeprecationWarning(DeprecationWarning): + """ + Deprecation warning raised when Python 3.7 runtime is detected. + Python 3.7 support will be dropped after January 1, 2024. See + https://cloud.google.com/python/docs/python37-sunset/ for more information. + """ + pass + +# Checks if the current runtime is Python 3.7. +if sys.version_info.major == 3 and sys.version_info.minor == 7: + message = ( + "After January 1, 2024, new releases of this client library will drop support " + "for Python 3.7. More details about Python 3.7 support for Client Libraries " + "can be found at https://cloud.google.com/python/docs/python37-sunset/" + ) + # Configure the Python37DeprecationWarning warning so that it is only emitted once. + warnings.simplefilter('once', Python37DeprecationWarning) + warnings.warn(message, Python37DeprecationWarning) + + __all__ = ('CloudRedisClient', 'CloudRedisAsyncClient', 'CreateInstanceRequest', diff --git a/tests/integration/goldens/redis/google/cloud/redis_v1/__init__.py b/tests/integration/goldens/redis/google/cloud/redis_v1/__init__.py index 0d4ccb8a35..175ffcdc76 100755 --- a/tests/integration/goldens/redis/google/cloud/redis_v1/__init__.py +++ b/tests/integration/goldens/redis/google/cloud/redis_v1/__init__.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import sys +import warnings + from google.cloud.redis_v1 import gapic_version as package_version __version__ = package_version.__version__ @@ -49,6 +52,26 @@ from .types.cloud_redis import WeeklyMaintenanceWindow from .types.cloud_redis import ZoneMetadata + +class Python37DeprecationWarning(DeprecationWarning): + """ + Deprecation warning raised when Python 3.7 runtime is detected. + Python 3.7 support will be dropped after January 1, 2024. See + https://cloud.google.com/python/docs/python37-sunset/ for more information. + """ + pass + +# Checks if the current runtime is Python 3.7. +if sys.version_info.major == 3 and sys.version_info.minor == 7: + message = ( + "After January 1, 2024, new releases of this client library will drop support " + "for Python 3.7. More details about Python 3.7 support for Client Libraries " + "can be found at https://cloud.google.com/python/docs/python37-sunset/" + ) + # print only the first occurrence of Python37DeprecationWarning, regardless of location + warnings.simplefilter('once', Python37DeprecationWarning) + warnings.warn(message, Python37DeprecationWarning) + __all__ = ( 'CloudRedisAsyncClient', 'CloudRedisClient',