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

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

37 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.cloud.errorreporting_v1beta1 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.error_group_service import ErrorGroupServiceClient 

32from .services.error_group_service import ErrorGroupServiceAsyncClient 

33from .services.error_stats_service import ErrorStatsServiceClient 

34from .services.error_stats_service import ErrorStatsServiceAsyncClient 

35from .services.report_errors_service import ReportErrorsServiceClient 

36from .services.report_errors_service import ReportErrorsServiceAsyncClient 

37 

38from .types.common import ErrorContext 

39from .types.common import ErrorEvent 

40from .types.common import ErrorGroup 

41from .types.common import HttpRequestContext 

42from .types.common import ServiceContext 

43from .types.common import SourceLocation 

44from .types.common import TrackingIssue 

45from .types.common import ResolutionStatus 

46from .types.error_group_service import GetGroupRequest 

47from .types.error_group_service import UpdateGroupRequest 

48from .types.error_stats_service import DeleteEventsRequest 

49from .types.error_stats_service import DeleteEventsResponse 

50from .types.error_stats_service import ErrorGroupStats 

51from .types.error_stats_service import ListEventsRequest 

52from .types.error_stats_service import ListEventsResponse 

53from .types.error_stats_service import ListGroupStatsRequest 

54from .types.error_stats_service import ListGroupStatsResponse 

55from .types.error_stats_service import QueryTimeRange 

56from .types.error_stats_service import ServiceContextFilter 

57from .types.error_stats_service import TimedCount 

58from .types.error_stats_service import ErrorGroupOrder 

59from .types.error_stats_service import TimedCountAlignment 

60from .types.report_errors_service import ReportedErrorEvent 

61from .types.report_errors_service import ReportErrorEventRequest 

62from .types.report_errors_service import ReportErrorEventResponse 

63 

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

65 api_core, "check_dependency_versions" 

66): # pragma: NO COVER 

67 api_core.check_python_version("google.cloud.errorreporting_v1beta1") # type: ignore 

68 api_core.check_dependency_versions("google.cloud.errorreporting_v1beta1") # type: ignore 

69else: # pragma: NO COVER 

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

71 # functions above. We do equivalent checks manually. 

72 try: 

73 import warnings 

74 import sys 

75 

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

77 _package_label = "google.cloud.errorreporting_v1beta1" 

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

79 warnings.warn( 

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

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

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

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

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

85 FutureWarning, 

86 ) 

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

88 warnings.warn( 

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

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

91 + "January 2026. Please " 

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

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

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

95 FutureWarning, 

96 ) 

97 

98 def parse_version_to_tuple(version_string: str): 

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

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

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

102 Args: 

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

104 Returns: 

105 Tuple of integers for the parsed version string. 

106 """ 

107 parts = [] 

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

109 try: 

110 parts.append(int(part)) 

111 except ValueError: 

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

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

114 # for comparing strictly numeric semantic versions. 

115 break 

116 return tuple(parts) 

117 

118 def _get_version(dependency_name): 

119 try: 

120 version_string: str = metadata.version(dependency_name) 

121 parsed_version = parse_version_to_tuple(version_string) 

122 return (parsed_version, version_string) 

123 except Exception: 

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

125 # or errors during parse_version_to_tuple 

126 return (None, "--") 

127 

128 _dependency_package = "google.protobuf" 

129 _next_supported_version = "4.25.8" 

130 _next_supported_version_tuple = (4, 25, 8) 

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

132 (_version_used, _version_used_string) = _get_version(_dependency_package) 

133 if _version_used and _version_used < _next_supported_version_tuple: 

134 warnings.warn( 

135 f"Package {_package_label} depends on " 

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

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

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

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

140 + " Please ensure " 

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

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

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

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

145 + f"least version {_next_supported_version} of " 

146 + f"{_dependency_package}.", 

147 FutureWarning, 

148 ) 

149 except Exception: 

150 warnings.warn( 

151 "Could not determine the version of Python " 

152 + "currently being used. To continue receiving " 

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

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

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

156 ) 

157 

158__all__ = ( 

159 "ErrorGroupServiceAsyncClient", 

160 "ErrorStatsServiceAsyncClient", 

161 "ReportErrorsServiceAsyncClient", 

162 "DeleteEventsRequest", 

163 "DeleteEventsResponse", 

164 "ErrorContext", 

165 "ErrorEvent", 

166 "ErrorGroup", 

167 "ErrorGroupOrder", 

168 "ErrorGroupServiceClient", 

169 "ErrorGroupStats", 

170 "ErrorStatsServiceClient", 

171 "GetGroupRequest", 

172 "HttpRequestContext", 

173 "ListEventsRequest", 

174 "ListEventsResponse", 

175 "ListGroupStatsRequest", 

176 "ListGroupStatsResponse", 

177 "QueryTimeRange", 

178 "ReportErrorEventRequest", 

179 "ReportErrorEventResponse", 

180 "ReportErrorsServiceClient", 

181 "ReportedErrorEvent", 

182 "ResolutionStatus", 

183 "ServiceContext", 

184 "ServiceContextFilter", 

185 "SourceLocation", 

186 "TimedCount", 

187 "TimedCountAlignment", 

188 "TrackingIssue", 

189 "UpdateGroupRequest", 

190)