Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/cloud/tasks_v2/__init__.py: 91%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

11 statements  

1# -*- coding: utf-8 -*- 

2# Copyright 2025 Google LLC 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

13# See the License for the specific language governing permissions and 

14# limitations under the License. 

15# 

16import sys 

17 

18import google.api_core as api_core 

19 

20from google.cloud.tasks_v2 import gapic_version as package_version 

21 

22__version__ = package_version.__version__ 

23 

24if sys.version_info >= (3, 8): # pragma: NO COVER 

25 from importlib import metadata 

26else: # pragma: NO COVER 

27 # TODO(https://github.com/googleapis/python-api-core/issues/835): Remove 

28 # this code path once we drop support for Python 3.7 

29 import importlib_metadata as metadata 

30 

31from .services.cloud_tasks import CloudTasksAsyncClient, CloudTasksClient 

32from .types.cloudtasks import ( 

33 CreateQueueRequest, 

34 CreateTaskRequest, 

35 DeleteQueueRequest, 

36 DeleteTaskRequest, 

37 GetQueueRequest, 

38 GetTaskRequest, 

39 ListQueuesRequest, 

40 ListQueuesResponse, 

41 ListTasksRequest, 

42 ListTasksResponse, 

43 PauseQueueRequest, 

44 PurgeQueueRequest, 

45 ResumeQueueRequest, 

46 RunTaskRequest, 

47 UpdateQueueRequest, 

48) 

49from .types.queue import Queue, RateLimits, RetryConfig, StackdriverLoggingConfig 

50from .types.target import ( 

51 AppEngineHttpRequest, 

52 AppEngineRouting, 

53 HttpMethod, 

54 HttpRequest, 

55 OAuthToken, 

56 OidcToken, 

57) 

58from .types.task import Attempt, Task 

59 

60if hasattr(api_core, "check_python_version") and hasattr( 

61 api_core, "check_dependency_versions" 

62): # pragma: NO COVER 

63 api_core.check_python_version("google.cloud.tasks_v2") # type: ignore 

64 api_core.check_dependency_versions("google.cloud.tasks_v2") # type: ignore 

65else: # pragma: NO COVER 

66 # An older version of api_core is installed which does not define the 

67 # functions above. We do equivalent checks manually. 

68 try: 

69 import sys 

70 import warnings 

71 

72 _py_version_str = sys.version.split()[0] 

73 _package_label = "google.cloud.tasks_v2" 

74 if sys.version_info < (3, 9): 

75 warnings.warn( 

76 "You are using a non-supported Python version " 

77 + f"({_py_version_str}). Google will not post any further " 

78 + f"updates to {_package_label} supporting this Python version. " 

79 + "Please upgrade to the latest Python version, or at " 

80 + f"least to Python 3.9, and then update {_package_label}.", 

81 FutureWarning, 

82 ) 

83 if sys.version_info[:2] == (3, 9): 

84 warnings.warn( 

85 f"You are using a Python version ({_py_version_str}) " 

86 + f"which Google will stop supporting in {_package_label} in " 

87 + "January 2026. Please " 

88 + "upgrade to the latest Python version, or at " 

89 + "least to Python 3.10, before then, and " 

90 + f"then update {_package_label}.", 

91 FutureWarning, 

92 ) 

93 

94 def parse_version_to_tuple(version_string: str): 

95 """Safely converts a semantic version string to a comparable tuple of integers. 

96 Example: "4.25.8" -> (4, 25, 8) 

97 Ignores non-numeric parts and handles common version formats. 

98 Args: 

99 version_string: Version string in the format "x.y.z" or "x.y.z<suffix>" 

100 Returns: 

101 Tuple of integers for the parsed version string. 

102 """ 

103 parts = [] 

104 for part in version_string.split("."): 

105 try: 

106 parts.append(int(part)) 

107 except ValueError: 

108 # If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here. 

109 # This is a simplification compared to 'packaging.parse_version', but sufficient 

110 # for comparing strictly numeric semantic versions. 

111 break 

112 return tuple(parts) 

113 

114 def _get_version(dependency_name): 

115 try: 

116 version_string: str = metadata.version(dependency_name) 

117 parsed_version = parse_version_to_tuple(version_string) 

118 return (parsed_version, version_string) 

119 except Exception: 

120 # Catch exceptions from metadata.version() (e.g., PackageNotFoundError) 

121 # or errors during parse_version_to_tuple 

122 return (None, "--") 

123 

124 _dependency_package = "google.protobuf" 

125 _next_supported_version = "4.25.8" 

126 _next_supported_version_tuple = (4, 25, 8) 

127 _recommendation = " (we recommend 6.x)" 

128 (_version_used, _version_used_string) = _get_version(_dependency_package) 

129 if _version_used and _version_used < _next_supported_version_tuple: 

130 warnings.warn( 

131 f"Package {_package_label} depends on " 

132 + f"{_dependency_package}, currently installed at version " 

133 + f"{_version_used_string}. Future updates to " 

134 + f"{_package_label} will require {_dependency_package} at " 

135 + f"version {_next_supported_version} or higher{_recommendation}." 

136 + " Please ensure " 

137 + "that either (a) your Python environment doesn't pin the " 

138 + f"version of {_dependency_package}, so that updates to " 

139 + f"{_package_label} can require the higher version, or " 

140 + "(b) you manually update your Python environment to use at " 

141 + f"least version {_next_supported_version} of " 

142 + f"{_dependency_package}.", 

143 FutureWarning, 

144 ) 

145 except Exception: 

146 warnings.warn( 

147 "Could not determine the version of Python " 

148 + "currently being used. To continue receiving " 

149 + "updates for {_package_label}, ensure you are " 

150 + "using a supported version of Python; see " 

151 + "https://devguide.python.org/versions/" 

152 ) 

153 

154__all__ = ( 

155 "CloudTasksAsyncClient", 

156 "AppEngineHttpRequest", 

157 "AppEngineRouting", 

158 "Attempt", 

159 "CloudTasksClient", 

160 "CreateQueueRequest", 

161 "CreateTaskRequest", 

162 "DeleteQueueRequest", 

163 "DeleteTaskRequest", 

164 "GetQueueRequest", 

165 "GetTaskRequest", 

166 "HttpMethod", 

167 "HttpRequest", 

168 "ListQueuesRequest", 

169 "ListQueuesResponse", 

170 "ListTasksRequest", 

171 "ListTasksResponse", 

172 "OAuthToken", 

173 "OidcToken", 

174 "PauseQueueRequest", 

175 "PurgeQueueRequest", 

176 "Queue", 

177 "RateLimits", 

178 "ResumeQueueRequest", 

179 "RetryConfig", 

180 "RunTaskRequest", 

181 "StackdriverLoggingConfig", 

182 "Task", 

183 "UpdateQueueRequest", 

184)