Skip to content

Commit 140c1e4

Browse files
committed
added formatter and checked
1 parent 4b7df5b commit 140c1e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+795
-602
lines changed

.github/workflows/code-quality-checks.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ jobs:
169169
170170
- name: Run tests
171171
run: poetry run python -m pytest tests/unit
172-
check-linting:
172+
code-format-check:
173173
runs-on: ubuntu-latest
174174
strategy:
175175
matrix:
@@ -216,10 +216,10 @@ jobs:
216216
- name: Install library
217217
run: poetry install --no-interaction
218218
#----------------------------------------------
219-
# black the code
219+
# Run Ruff format check
220220
#----------------------------------------------
221-
- name: Black
222-
run: poetry run black --check src
221+
- name: Ruff format check
222+
run: poetry run ruff format --check
223223

224224
check-types:
225225
runs-on: ubuntu-latest

examples/custom_cred_provider.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
http_path=os.getenv("DATABRICKS_HTTP_PATH"),
2222
credentials_provider=creds,
2323
) as connection:
24-
2524
for x in range(1, 5):
2625
cursor = connection.cursor()
2726
cursor.execute("SELECT 1+1")

examples/experimental/tests/test_sea_async_query.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Test for SEA asynchronous query execution functionality.
33
"""
4+
45
import os
56
import sys
67
import logging

examples/experimental/tests/test_sea_metadata.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Test for SEA metadata functionality.
33
"""
4+
45
import os
56
import sys
67
import logging

examples/experimental/tests/test_sea_session.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Test for SEA session management functionality.
33
"""
4+
45
import os
56
import sys
67
import logging

examples/experimental/tests/test_sea_sync_query.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Test for SEA synchronous query execution functionality.
33
"""
4+
45
import os
56
import sys
67
import logging

examples/insert_data.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
http_path=os.getenv("DATABRICKS_HTTP_PATH"),
77
access_token=os.getenv("DATABRICKS_TOKEN"),
88
) as connection:
9-
109
with connection.cursor() as cursor:
1110
cursor.execute("CREATE TABLE IF NOT EXISTS squares (x int, x_squared int)")
1211

examples/interactive_oauth.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
server_hostname=os.getenv("DATABRICKS_SERVER_HOSTNAME"),
1818
http_path=os.getenv("DATABRICKS_HTTP_PATH"),
1919
) as connection:
20-
2120
for x in range(1, 100):
2221
cursor = connection.cursor()
2322
cursor.execute("SELECT 1+1")

examples/persistent_oauth.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def read(self, hostname: str) -> Optional[OAuthToken]:
5151
auth_type="databricks-oauth",
5252
experimental_oauth_persistence=DevOnlyFilePersistence("./sample.json"),
5353
) as connection:
54-
5554
for x in range(1, 100):
5655
cursor = connection.cursor()
5756
cursor.execute("SELECT 1+1")

examples/proxy_authentication.py

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,122 +20,128 @@
2020

2121
# Configure logging to see proxy activity
2222
logging.basicConfig(
23-
level=logging.INFO,
24-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
23+
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
2524
)
2625

2726
# Uncomment for detailed debugging (shows HTTP requests/responses)
2827
# logging.getLogger("urllib3").setLevel(logging.DEBUG)
2928
# logging.getLogger("urllib3.connectionpool").setLevel(logging.DEBUG)
3029

30+
3131
def check_proxy_environment():
3232
"""Check if proxy environment variables are configured."""
33-
proxy_vars = ['HTTP_PROXY', 'HTTPS_PROXY', 'http_proxy', 'https_proxy']
34-
configured_proxies = {var: os.environ.get(var) for var in proxy_vars if os.environ.get(var)}
35-
33+
proxy_vars = ["HTTP_PROXY", "HTTPS_PROXY", "http_proxy", "https_proxy"]
34+
configured_proxies = {
35+
var: os.environ.get(var) for var in proxy_vars if os.environ.get(var)
36+
}
37+
3638
if configured_proxies:
3739
print("✓ Proxy environment variables found:")
3840
for var, value in configured_proxies.items():
3941
# Hide credentials in output for security
40-
safe_value = value.split('@')[-1] if '@' in value else value
42+
safe_value = value.split("@")[-1] if "@" in value else value
4143
print(f" {var}: {safe_value}")
4244
return True
4345
else:
4446
print("⚠ No proxy environment variables found")
4547
print(" Set HTTP_PROXY and/or HTTPS_PROXY if using a proxy")
4648
return False
4749

50+
4851
def test_connection(connection_params, test_name):
4952
"""Test a database connection with given parameters."""
5053
print(f"\n--- Testing {test_name} ---")
51-
54+
5255
try:
5356
with sql.connect(**connection_params) as connection:
5457
print("✓ Successfully connected!")
55-
58+
5659
with connection.cursor() as cursor:
5760
# Test basic query
58-
cursor.execute("SELECT current_user() as user, current_database() as database")
61+
cursor.execute(
62+
"SELECT current_user() as user, current_database() as database"
63+
)
5964
result = cursor.fetchone()
6065
print(f"✓ Connected as user: {result.user}")
6166
print(f"✓ Default database: {result.database}")
62-
67+
6368
# Test a simple computation
6469
cursor.execute("SELECT 1 + 1 as result")
6570
result = cursor.fetchone()
6671
print(f"✓ Query result: 1 + 1 = {result.result}")
67-
72+
6873
return True
69-
74+
7075
except Exception as e:
7176
print(f"✗ Connection failed: {e}")
7277
return False
7378

79+
7480
def main():
7581
print("Databricks SQL Connector - Proxy Authentication Examples")
7682
print("=" * 60)
77-
83+
7884
# Check proxy configuration
7985
has_proxy = check_proxy_environment()
80-
86+
8187
# Get Databricks connection parameters
82-
server_hostname = os.environ.get('DATABRICKS_SERVER_HOSTNAME')
83-
http_path = os.environ.get('DATABRICKS_HTTP_PATH')
84-
access_token = os.environ.get('DATABRICKS_TOKEN')
85-
88+
server_hostname = os.environ.get("DATABRICKS_SERVER_HOSTNAME")
89+
http_path = os.environ.get("DATABRICKS_HTTP_PATH")
90+
access_token = os.environ.get("DATABRICKS_TOKEN")
91+
8692
if not all([server_hostname, http_path, access_token]):
8793
print("\n✗ Missing required environment variables:")
8894
print(" DATABRICKS_SERVER_HOSTNAME")
89-
print(" DATABRICKS_HTTP_PATH")
95+
print(" DATABRICKS_HTTP_PATH")
9096
print(" DATABRICKS_TOKEN")
9197
return 1
92-
98+
9399
print(f"\nConnecting to: {server_hostname}")
94-
100+
95101
# Base connection parameters
96102
base_params = {
97-
'server_hostname': server_hostname,
98-
'http_path': http_path,
99-
'access_token': access_token
103+
"server_hostname": server_hostname,
104+
"http_path": http_path,
105+
"access_token": access_token,
100106
}
101-
107+
102108
success_count = 0
103109
total_tests = 0
104-
110+
105111
# Test 1: Default proxy behavior (no _proxy_auth_method specified)
106112
# This uses basic auth if credentials are in proxy URL, otherwise no auth
107-
print("\n" + "="*60)
113+
print("\n" + "=" * 60)
108114
print("Test 1: Default Proxy Behavior")
109115
print("Uses basic authentication if credentials are in proxy URL")
110116
total_tests += 1
111117
if test_connection(base_params, "Default Proxy Behavior"):
112118
success_count += 1
113-
119+
114120
# Test 2: Explicit basic authentication
115-
print("\n" + "="*60)
121+
print("\n" + "=" * 60)
116122
print("Test 2: Explicit Basic Authentication")
117123
print("Explicitly requests basic authentication (same as default)")
118124
total_tests += 1
119125
basic_params = base_params.copy()
120-
basic_params['_proxy_auth_method'] = 'basic'
126+
basic_params["_proxy_auth_method"] = "basic"
121127
if test_connection(basic_params, "Basic Proxy Authentication"):
122128
success_count += 1
123-
129+
124130
# Test 3: Kerberos/Negotiate authentication
125-
print("\n" + "="*60)
131+
print("\n" + "=" * 60)
126132
print("Test 3: Kerberos/Negotiate Authentication")
127133
print("Uses Kerberos tickets for proxy authentication")
128134
print("Note: Requires valid Kerberos tickets (run 'kinit' first)")
129135
total_tests += 1
130136
kerberos_params = base_params.copy()
131-
kerberos_params['_proxy_auth_method'] = 'negotiate'
137+
kerberos_params["_proxy_auth_method"] = "negotiate"
132138
if test_connection(kerberos_params, "Kerberos Proxy Authentication"):
133139
success_count += 1
134-
140+
135141
# Summary
136-
print(f"\n{'='*60}")
142+
print(f"\n{'=' * 60}")
137143
print(f"Summary: {success_count}/{total_tests} tests passed")
138-
144+
139145
if success_count == total_tests:
140146
print("✓ All proxy authentication methods working!")
141147
return 0
@@ -149,5 +155,6 @@ def main():
149155
print("Consider checking your proxy configuration")
150156
return 1
151157

158+
152159
if __name__ == "__main__":
153160
exit(main())

0 commit comments

Comments
 (0)