From 351e6637a566d4a44c153791cfa738f335b85299 Mon Sep 17 00:00:00 2001 From: alifeee Date: Wed, 24 Apr 2024 14:51:08 +0100 Subject: [PATCH 1/4] coerce test package versions to those in `pyproject.toml` (test fails) --- test-requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-requirements.txt b/test-requirements.txt index f9ccfd0d5..ec7d225ce 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,5 +1,5 @@ -google-auth==2.15.0 -google-auth-oauthlib>=0.8.0 +google-auth==1.12.0 +google-auth-oauthlib==0.4.1 vcrpy pytest pytest-vcr From 6fae543708a228f6e92cf7e4ff29ee0a8099ec62 Mon Sep 17 00:00:00 2001 From: alifeee Date: Wed, 24 Apr 2024 14:53:47 +0100 Subject: [PATCH 2/4] catch failed import (and report as `NotImplementedError`) --- gspread/auth.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gspread/auth.py b/gspread/auth.py index c46a86671..3375c711a 100644 --- a/gspread/auth.py +++ b/gspread/auth.py @@ -11,8 +11,12 @@ from pathlib import Path from typing import Any, Dict, Iterable, Mapping, Optional, Protocol, Tuple, Union -from google.auth.api_key import Credentials as APIKeyCredentials from google.auth.credentials import Credentials +try: + from google.auth.api_key import Credentials as APIKeyCredentials + GOOGLE_AUTH_API_KEY_AVAILABLE = True +except ImportError: + GOOGLE_AUTH_API_KEY_AVAILABLE = False from google.oauth2.credentials import Credentials as OAuthCredentials from google.oauth2.service_account import Credentials as SACredentials from google_auth_oauthlib.flow import InstalledAppFlow @@ -379,5 +383,7 @@ def api_key(token: str, http_client: HTTPClientType = HTTPClient) -> Client: :rtype: :class:`gspread.client.Client` """ + if GOOGLE_AUTH_API_KEY_AVAILABLE is False: + raise NotImplementedError(f'api_key is only available with package google.auth>=2.4.0. Install it with "pip install google-auth>=2.4.0".') creds = APIKeyCredentials(token) return Client(auth=creds, http_client=http_client) From 2aa7d455728e2ba4726a2ec25ff8cd7791583a8c Mon Sep 17 00:00:00 2001 From: alifeee Date: Wed, 24 Apr 2024 15:01:18 +0100 Subject: [PATCH 3/4] format --- gspread/auth.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gspread/auth.py b/gspread/auth.py index 3375c711a..a24e75214 100644 --- a/gspread/auth.py +++ b/gspread/auth.py @@ -12,8 +12,10 @@ from typing import Any, Dict, Iterable, Mapping, Optional, Protocol, Tuple, Union from google.auth.credentials import Credentials + try: from google.auth.api_key import Credentials as APIKeyCredentials + GOOGLE_AUTH_API_KEY_AVAILABLE = True except ImportError: GOOGLE_AUTH_API_KEY_AVAILABLE = False @@ -384,6 +386,8 @@ def api_key(token: str, http_client: HTTPClientType = HTTPClient) -> Client: """ if GOOGLE_AUTH_API_KEY_AVAILABLE is False: - raise NotImplementedError(f'api_key is only available with package google.auth>=2.4.0. Install it with "pip install google-auth>=2.4.0".') + raise NotImplementedError( + f'api_key is only available with package google.auth>=2.4.0. Install it with "pip install google-auth>=2.4.0".' + ) creds = APIKeyCredentials(token) return Client(auth=creds, http_client=http_client) From 29f490b92635f32cf00ad4babb45c25d35a3913c Mon Sep 17 00:00:00 2001 From: alifeee Date: Wed, 24 Apr 2024 15:05:23 +0100 Subject: [PATCH 4/4] remove f-string --- gspread/auth.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gspread/auth.py b/gspread/auth.py index a24e75214..8e3b63b09 100644 --- a/gspread/auth.py +++ b/gspread/auth.py @@ -387,7 +387,8 @@ def api_key(token: str, http_client: HTTPClientType = HTTPClient) -> Client: """ if GOOGLE_AUTH_API_KEY_AVAILABLE is False: raise NotImplementedError( - f'api_key is only available with package google.auth>=2.4.0. Install it with "pip install google-auth>=2.4.0".' + "api_key is only available with package google.auth>=2.4.0." + 'Install it with "pip install google-auth>=2.4.0".' ) creds = APIKeyCredentials(token) return Client(auth=creds, http_client=http_client)