GeezerVison is showing github.com — fix: suppress no project id warning (#160) · googleapis/python-aiplatform@ce7b7a3
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: google/cloud/aiplatform/base.py -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -276,7 +276,6 @@ def _instantiate_client( |
276 | 276 | """Helper method to instantiate service client for resource noun. |
277 | 277 |
|
278 | 278 | Args: |
279 | | - project (str): Project of the resource noun. |
280 | 279 | location (str): The location of the resource noun. |
281 | 280 | credentials (google.auth.credentials.Credentials): |
282 | 281 | Optional custom credentials to use when accessing interacting with |
|
Collapse file
Copy file name to clipboardExpand all lines: google/cloud/aiplatform/initializer.py +12-1Lines changed: 12 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -116,9 +116,20 @@ def staging_bucket(self) -> Optional[str]: |
116 | 116 |
|
117 | 117 | @property |
118 | 118 | def credentials(self) -> Optional[auth_credentials.Credentials]: |
119 | | - """Default credentials, if provided.""" |
| 119 | + """Default credentials.""" |
120 | 120 | return self._credentials |
121 | 121 |
|
| 122 | + @credentials.setter |
| 123 | + def credentials(self, credentials): |
| 124 | + """Set credentials if provided, or to the default credentials, .""" |
| 125 | + if not credentials: |
| 126 | + logger = logging.getLogger("google.auth._default") |
| 127 | + logging_warning_filter = utils.LoggingWarningFilter() |
| 128 | + logger.addFilter(logging_warning_filter) |
| 129 | + credentials, _ = google.auth.default() |
| 130 | + logger.removeFilter(logging_warning_filter) |
| 131 | + self._credentials = credentials |
| 132 | + |
122 | 133 | def get_client_options( |
123 | 134 | self, location_override: Optional[str] = None, prediction_client: bool = False, |
124 | 135 | ) -> client_options.ClientOptions: |
|
Collapse file
Copy file name to clipboardExpand all lines: google/cloud/aiplatform/utils.py +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
17 | 17 |
|
18 | 18 |
|
19 | 19 | import re |
| 20 | +import logging |
20 | 21 |
|
21 | 22 | from typing import Any, Match, Optional, Type, TypeVar, Tuple |
22 | 23 | from collections import namedtuple |
@@ -308,3 +309,8 @@ def __getattr__(self, name: str) -> Any: |
308 | 309 | client_info=self._client_info, |
309 | 310 | ) |
310 | 311 | return getattr(temporary_client, name) |
| 312 | + |
| 313 | + |
| 314 | +class LoggingWarningFilter(logging.Filter): |
| 315 | + def filter(self, record): |
| 316 | + return record.levelname == logging.WARNING |