Skip to content

Commit

Permalink
fix: Add deprecation warning for python 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
parthea committed Aug 16, 2023
1 parent 3f46545 commit f5feaca
Show file tree
Hide file tree
Showing 12 changed files with 282 additions and 0 deletions.
24 changes: 24 additions & 0 deletions gapic/templates/%namespace/%name/__init__.py.j2
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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 %}
Expand Down
23 changes: 23 additions & 0 deletions gapic/templates/%namespace/%name_%version/%sub/__init__.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/goldens/asset/google/cloud/asset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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',
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/goldens/asset/google/cloud/asset_v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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',
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/goldens/logging/google/cloud/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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',
Expand Down
Loading

0 comments on commit f5feaca

Please sign in to comment.