Skip to content

Commit 39f5f22

Browse files
committed
lint changes
1 parent 85618f3 commit 39f5f22

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

pyiceberg/catalog/rest/auth.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import base64
1919
import importlib
20-
from abc import ABC, abstractmethod
2120
import logging
21+
from abc import ABC, abstractmethod
2222
from typing import Any, Dict, List, Optional, Type
2323

2424
from requests import HTTPError, PreparedRequest, Session
@@ -111,9 +111,7 @@ def auth_header(self) -> str:
111111

112112

113113
class GoogleAuthManager(AuthManager):
114-
"""
115-
An auth manager that is responsible for handling Google credentials.
116-
"""
114+
"""An auth manager that is responsible for handling Google credentials."""
117115

118116
def __init__(self, credentials_path: Optional[str] = None, scopes: Optional[List[str]] = None):
119117
"""
@@ -127,9 +125,7 @@ def __init__(self, credentials_path: Optional[str] = None, scopes: Optional[List
127125
import google.auth
128126
import google.auth.transport.requests
129127
except ImportError as e:
130-
raise ImportError(
131-
"Google Auth libraries not found. Please install 'google-auth'."
132-
) from e
128+
raise ImportError("Google Auth libraries not found. Please install 'google-auth'.") from e
133129

134130
if credentials_path:
135131
self.credentials, _ = google.auth.load_credentials_from_file(credentials_path, scopes=scopes)
@@ -142,6 +138,7 @@ def auth_header(self) -> Optional[str]:
142138
self.credentials.refresh(self._auth_request)
143139
return f"Bearer {self.credentials.token}"
144140

141+
145142
class AuthManagerAdapter(AuthBase):
146143
"""A `requests.auth.AuthBase` adapter that integrates an `AuthManager` into a `requests.Session` to automatically attach the appropriate Authorization header to every request.
147144

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ zstandard = ">=0.13.0,<1.0.0"
6363
tenacity = ">=8.2.3,<10.0.0"
6464
pyroaring = ">=1.0.0,<2.0.0"
6565
pyarrow = { version = ">=17.0.0,<21.0.0", optional = true }
66+
google-auth = { version = ">=2.4.0", optional = true }
6667
pandas = { version = ">=1.0.0,<3.0.0", optional = true }
6768
duckdb = { version = ">=0.5.0,<2.0.0", optional = true }
6869
ray = [
@@ -125,6 +126,10 @@ ignore_missing_imports = true
125126
module = "pyarrow.*"
126127
ignore_missing_imports = true
127128

129+
[[tool.mypy.overrides]]
130+
module = "google.*"
131+
ignore_missing_imports = true
132+
128133
[[tool.mypy.overrides]]
129134
module = "pandas.*"
130135
ignore_missing_imports = true
@@ -309,6 +314,7 @@ gcsfs = ["gcsfs"]
309314
rest-sigv4 = ["boto3"]
310315
hf = ["huggingface-hub"]
311316
pyiceberg-core = ["pyiceberg-core"]
317+
gcp-auth=["google-auth"]
312318

313319
[tool.pytest.ini_options]
314320
markers = [

tests/catalog/test_rest_auth.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import pytest
2222
import requests
2323
from requests_mock import Mocker
24+
2425
from pyiceberg.catalog.rest.auth import AuthManagerAdapter, BasicAuthManager, GoogleAuthManager, NoopAuthManager
2526

2627
TEST_URI = "https://iceberg-test-catalog/"
@@ -36,18 +37,18 @@ def rest_mock(requests_mock: Mocker) -> Mocker:
3637
)
3738
return requests_mock
3839

40+
3941
@pytest.fixture
4042
def google_mock(requests_mock: Mocker) -> Mocker:
41-
requests_mock.post(GOOGLE_CREDS_URI,
42-
json={"access_token": "aaaabbb"},
43-
status_code=200)
43+
requests_mock.post(GOOGLE_CREDS_URI, json={"access_token": "aaaabbb"}, status_code=200)
4444
requests_mock.get(
4545
TEST_URI,
4646
json={},
4747
status_code=200,
4848
)
4949
return requests_mock
5050

51+
5152
def test_noop_auth_header(rest_mock: Mocker) -> None:
5253
auth_manager = NoopAuthManager()
5354
session = requests.Session()
@@ -77,9 +78,11 @@ def test_basic_auth_header(rest_mock: Mocker) -> None:
7778
assert actual_headers["Authorization"] == expected_header
7879

7980

80-
@patch('google.auth.transport.requests.Request')
81-
@patch('google.auth.default')
82-
def test_google_auth_manager_default_credentials(mock_google_auth_default: MagicMock, mock_google_request: MagicMock, rest_mock: Mocker) -> None:
81+
@patch("google.auth.transport.requests.Request")
82+
@patch("google.auth.default")
83+
def test_google_auth_manager_default_credentials(
84+
mock_google_auth_default: MagicMock, mock_google_request: MagicMock, rest_mock: Mocker
85+
) -> None:
8386
"""Test GoogleAuthManager with default application credentials."""
8487
mock_credentials = MagicMock()
8588
mock_credentials.token = "test_token"
@@ -98,9 +101,11 @@ def test_google_auth_manager_default_credentials(mock_google_auth_default: Magic
98101
assert actual_headers["Authorization"] == "Bearer test_token"
99102

100103

101-
@patch('google.auth.transport.requests.Request')
102-
@patch('google.auth.load_credentials_from_file')
103-
def test_google_auth_manager_with_credentials_file(mock_load_creds: MagicMock, mock_google_request: MagicMock, rest_mock: Mocker) -> None:
104+
@patch("google.auth.transport.requests.Request")
105+
@patch("google.auth.load_credentials_from_file")
106+
def test_google_auth_manager_with_credentials_file(
107+
mock_load_creds: MagicMock, mock_google_request: MagicMock, rest_mock: Mocker
108+
) -> None:
104109
"""Test GoogleAuthManager with a credentials file path."""
105110
mock_credentials = MagicMock()
106111
mock_credentials.token = "file_token"
@@ -119,9 +124,11 @@ def test_google_auth_manager_with_credentials_file(mock_load_creds: MagicMock, m
119124
assert actual_headers["Authorization"] == "Bearer file_token"
120125

121126

122-
@patch('google.auth.transport.requests.Request')
123-
@patch('google.auth.load_credentials_from_file')
124-
def test_google_auth_manager_with_credentials_file_and_scopes(mock_load_creds: MagicMock, mock_google_request: MagicMock, rest_mock: Mocker) -> None:
127+
@patch("google.auth.transport.requests.Request")
128+
@patch("google.auth.load_credentials_from_file")
129+
def test_google_auth_manager_with_credentials_file_and_scopes(
130+
mock_load_creds: MagicMock, mock_google_request: MagicMock, rest_mock: Mocker
131+
) -> None:
125132
"""Test GoogleAuthManager with a credentials file path and scopes."""
126133
mock_credentials = MagicMock()
127134
mock_credentials.token = "scoped_token"
@@ -143,6 +150,6 @@ def test_google_auth_manager_with_credentials_file_and_scopes(mock_load_creds: M
143150

144151
def test_google_auth_manager_import_error() -> None:
145152
"""Test GoogleAuthManager raises ImportError if google-auth is not installed."""
146-
with patch.dict('sys.modules', {'google.auth': None, 'google.auth.transport.requests': None}):
153+
with patch.dict("sys.modules", {"google.auth": None, "google.auth.transport.requests": None}):
147154
with pytest.raises(ImportError, match="Google Auth libraries not found. Please install 'google-auth'."):
148-
GoogleAuthManager()
155+
GoogleAuthManager()

0 commit comments

Comments
 (0)