Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add deprecation warning for python 3.7 #1743

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

@@ -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)
Comment on lines +70 to +71
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Configure the Python37DeprecationWarning warning so that it is only emitted once.
warnings.simplefilter('once', Python37DeprecationWarning)

This code should be removed. See googleapis/google-auth-library-python#1427

warnings.warn(message, Python37DeprecationWarning)


__all__ = (
{%- filter indent %}
{% for subpackage, _ in api.subpackages|dictsort %}
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
@@ -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)
Comment on lines +58 to +59
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# print only the first occurrence of Python37DeprecationWarning, regardless of location
warnings.simplefilter('once', Python37DeprecationWarning)

This code should be removed. See googleapis/google-auth-library-python#1427

warnings.warn(message, Python37DeprecationWarning)

{# Define __all__.
This requires the full set of imported names, so we iterate over
them again.
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
@@ -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',
Original file line number Diff line number Diff line change
@@ -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',
Original file line number Diff line number Diff line change
@@ -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',
Original file line number Diff line number Diff line change
@@ -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',
Original file line number Diff line number Diff line change
@@ -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',
Original file line number Diff line number Diff line change
@@ -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',
Original file line number Diff line number Diff line change
@@ -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',
Original file line number Diff line number Diff line change
@@ -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',
24 changes: 24 additions & 0 deletions tests/integration/goldens/redis/google/cloud/redis/__init__.py
Original file line number Diff line number Diff line change
@@ -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',
Original file line number Diff line number Diff line change
@@ -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',