Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/pubsub_v1/__init__.py: 99%

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

81 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# 

16from google.pubsub_v1 import gapic_version as package_version 

17 

18import google.api_core as api_core 

19import sys 

20 

21__version__ = package_version.__version__ 

22 

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

24 from importlib import metadata 

25else: # pragma: NO COVER 

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

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

28 import importlib_metadata as metadata 

29 

30 

31from .services.publisher import PublisherClient 

32from .services.publisher import PublisherAsyncClient 

33from .services.schema_service import SchemaServiceClient 

34from .services.schema_service import SchemaServiceAsyncClient 

35from .services.subscriber import SubscriberClient 

36from .services.subscriber import SubscriberAsyncClient 

37 

38from .types.pubsub import AcknowledgeRequest 

39from .types.pubsub import AIInference 

40from .types.pubsub import BigQueryConfig 

41from .types.pubsub import CloudStorageConfig 

42from .types.pubsub import CreateSnapshotRequest 

43from .types.pubsub import DeadLetterPolicy 

44from .types.pubsub import DeleteSnapshotRequest 

45from .types.pubsub import DeleteSubscriptionRequest 

46from .types.pubsub import DeleteTopicRequest 

47from .types.pubsub import DetachSubscriptionRequest 

48from .types.pubsub import DetachSubscriptionResponse 

49from .types.pubsub import ExpirationPolicy 

50from .types.pubsub import GetSnapshotRequest 

51from .types.pubsub import GetSubscriptionRequest 

52from .types.pubsub import GetTopicRequest 

53from .types.pubsub import IngestionDataSourceSettings 

54from .types.pubsub import IngestionFailureEvent 

55from .types.pubsub import JavaScriptUDF 

56from .types.pubsub import ListSnapshotsRequest 

57from .types.pubsub import ListSnapshotsResponse 

58from .types.pubsub import ListSubscriptionsRequest 

59from .types.pubsub import ListSubscriptionsResponse 

60from .types.pubsub import ListTopicSnapshotsRequest 

61from .types.pubsub import ListTopicSnapshotsResponse 

62from .types.pubsub import ListTopicsRequest 

63from .types.pubsub import ListTopicsResponse 

64from .types.pubsub import ListTopicSubscriptionsRequest 

65from .types.pubsub import ListTopicSubscriptionsResponse 

66from .types.pubsub import MessageStoragePolicy 

67from .types.pubsub import MessageTransform 

68from .types.pubsub import ModifyAckDeadlineRequest 

69from .types.pubsub import ModifyPushConfigRequest 

70from .types.pubsub import PlatformLogsSettings 

71from .types.pubsub import PublishRequest 

72from .types.pubsub import PublishResponse 

73from .types.pubsub import PubsubMessage 

74from .types.pubsub import PullRequest 

75from .types.pubsub import PullResponse 

76from .types.pubsub import PushConfig 

77from .types.pubsub import ReceivedMessage 

78from .types.pubsub import RetryPolicy 

79from .types.pubsub import SchemaSettings 

80from .types.pubsub import SeekRequest 

81from .types.pubsub import SeekResponse 

82from .types.pubsub import Snapshot 

83from .types.pubsub import StreamingPullRequest 

84from .types.pubsub import StreamingPullResponse 

85from .types.pubsub import Subscription 

86from .types.pubsub import Topic 

87from .types.pubsub import UpdateSnapshotRequest 

88from .types.pubsub import UpdateSubscriptionRequest 

89from .types.pubsub import UpdateTopicRequest 

90from .types.schema import CommitSchemaRequest 

91from .types.schema import CreateSchemaRequest 

92from .types.schema import DeleteSchemaRequest 

93from .types.schema import DeleteSchemaRevisionRequest 

94from .types.schema import GetSchemaRequest 

95from .types.schema import ListSchemaRevisionsRequest 

96from .types.schema import ListSchemaRevisionsResponse 

97from .types.schema import ListSchemasRequest 

98from .types.schema import ListSchemasResponse 

99from .types.schema import RollbackSchemaRequest 

100from .types.schema import Schema 

101from .types.schema import ValidateMessageRequest 

102from .types.schema import ValidateMessageResponse 

103from .types.schema import ValidateSchemaRequest 

104from .types.schema import ValidateSchemaResponse 

105from .types.schema import Encoding 

106from .types.schema import SchemaView 

107 

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

109 api_core, "check_dependency_versions" 

110): # pragma: NO COVER 

111 api_core.check_python_version("google.pubsub_v1") # type: ignore 

112 api_core.check_dependency_versions("google.pubsub_v1") # type: ignore 

113else: # pragma: NO COVER 

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

115 # functions above. We do equivalent checks manually. 

116 try: 

117 import warnings 

118 import sys 

119 

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

121 _package_label = "google.pubsub_v1" 

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

123 warnings.warn( 

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

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

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

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

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

129 FutureWarning, 

130 ) 

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

132 warnings.warn( 

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

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

135 + "January 2026. Please " 

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

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

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

139 FutureWarning, 

140 ) 

141 

142 def parse_version_to_tuple(version_string: str): 

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

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

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

146 Args: 

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

148 Returns: 

149 Tuple of integers for the parsed version string. 

150 """ 

151 parts = [] 

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

153 try: 

154 parts.append(int(part)) 

155 except ValueError: 

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

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

158 # for comparing strictly numeric semantic versions. 

159 break 

160 return tuple(parts) 

161 

162 def _get_version(dependency_name): 

163 try: 

164 version_string: str = metadata.version(dependency_name) 

165 parsed_version = parse_version_to_tuple(version_string) 

166 return (parsed_version, version_string) 

167 except Exception: 

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

169 # or errors during parse_version_to_tuple 

170 return (None, "--") 

171 

172 _dependency_package = "google.protobuf" 

173 _next_supported_version = "4.25.8" 

174 _next_supported_version_tuple = (4, 25, 8) 

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

176 (_version_used, _version_used_string) = _get_version(_dependency_package) 

177 if _version_used and _version_used < _next_supported_version_tuple: 

178 warnings.warn( 

179 f"Package {_package_label} depends on " 

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

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

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

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

184 + " Please ensure " 

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

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

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

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

189 + f"least version {_next_supported_version} of " 

190 + f"{_dependency_package}.", 

191 FutureWarning, 

192 ) 

193 except Exception: 

194 warnings.warn( 

195 "Could not determine the version of Python " 

196 + "currently being used. To continue receiving " 

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

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

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

200 ) 

201 

202__all__ = ( 

203 "PublisherAsyncClient", 

204 "SchemaServiceAsyncClient", 

205 "SubscriberAsyncClient", 

206 "AIInference", 

207 "AcknowledgeRequest", 

208 "BigQueryConfig", 

209 "CloudStorageConfig", 

210 "CommitSchemaRequest", 

211 "CreateSchemaRequest", 

212 "CreateSnapshotRequest", 

213 "DeadLetterPolicy", 

214 "DeleteSchemaRequest", 

215 "DeleteSchemaRevisionRequest", 

216 "DeleteSnapshotRequest", 

217 "DeleteSubscriptionRequest", 

218 "DeleteTopicRequest", 

219 "DetachSubscriptionRequest", 

220 "DetachSubscriptionResponse", 

221 "Encoding", 

222 "ExpirationPolicy", 

223 "GetSchemaRequest", 

224 "GetSnapshotRequest", 

225 "GetSubscriptionRequest", 

226 "GetTopicRequest", 

227 "IngestionDataSourceSettings", 

228 "IngestionFailureEvent", 

229 "JavaScriptUDF", 

230 "ListSchemaRevisionsRequest", 

231 "ListSchemaRevisionsResponse", 

232 "ListSchemasRequest", 

233 "ListSchemasResponse", 

234 "ListSnapshotsRequest", 

235 "ListSnapshotsResponse", 

236 "ListSubscriptionsRequest", 

237 "ListSubscriptionsResponse", 

238 "ListTopicSnapshotsRequest", 

239 "ListTopicSnapshotsResponse", 

240 "ListTopicSubscriptionsRequest", 

241 "ListTopicSubscriptionsResponse", 

242 "ListTopicsRequest", 

243 "ListTopicsResponse", 

244 "MessageStoragePolicy", 

245 "MessageTransform", 

246 "ModifyAckDeadlineRequest", 

247 "ModifyPushConfigRequest", 

248 "PlatformLogsSettings", 

249 "PublishRequest", 

250 "PublishResponse", 

251 "PublisherClient", 

252 "PubsubMessage", 

253 "PullRequest", 

254 "PullResponse", 

255 "PushConfig", 

256 "ReceivedMessage", 

257 "RetryPolicy", 

258 "RollbackSchemaRequest", 

259 "Schema", 

260 "SchemaServiceClient", 

261 "SchemaSettings", 

262 "SchemaView", 

263 "SeekRequest", 

264 "SeekResponse", 

265 "Snapshot", 

266 "StreamingPullRequest", 

267 "StreamingPullResponse", 

268 "SubscriberClient", 

269 "Subscription", 

270 "Topic", 

271 "UpdateSnapshotRequest", 

272 "UpdateSubscriptionRequest", 

273 "UpdateTopicRequest", 

274 "ValidateMessageRequest", 

275 "ValidateMessageResponse", 

276 "ValidateSchemaRequest", 

277 "ValidateSchemaResponse", 

278)