Skip to content

Commit 9077a5c

Browse files
fix: address Ruff and Vercel dependency issues
Agent-Logs-Url: https://github.com/quantumdynamics927-dotcom/QPyth/sessions/ed476ffc-1ea5-43ae-9624-0d3544d77b41 Co-authored-by: quantumdynamics927-dotcom <247722560+quantumdynamics927-dotcom@users.noreply.github.com>
1 parent a58738d commit 9077a5c

5 files changed

Lines changed: 50 additions & 45 deletions

File tree

migrate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def main():
130130
config = DatabaseConfig(database_url=database_url)
131131
db = NeonDatabase(config)
132132

133-
print(f"✅ Connected to database")
133+
print("✅ Connected to database")
134134

135135
# Run appropriate command
136136
if args.rollback:

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ web = [
6262
"uvicorn[standard]>=0.32.0,<1.0.0",
6363
"slowapi>=0.1.9",
6464
]
65+
docs = [
66+
"mkdocs>=1.5.0,<2.0.0",
67+
"mkdocs-material>=9.0.0,<10.0.0",
68+
"pymdown-extensions>=10.0.0",
69+
]
6570
database = [
6671
"psycopg2-binary>=2.9.9",
6772
]
@@ -72,6 +77,9 @@ all = [
7277
"fastapi>=0.115.0,<1.0.0",
7378
"uvicorn[standard]>=0.32.0,<1.0.0",
7479
"slowapi>=0.1.9",
80+
"mkdocs>=1.5.0,<2.0.0",
81+
"mkdocs-material>=9.0.0,<10.0.0",
82+
"pymdown-extensions>=10.0.0",
7583
"psycopg2-binary>=2.9.9",
7684
]
7785

quantumpytho/modules/database.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
"""
1515

1616
import os
17+
from collections.abc import Generator
1718
from contextlib import contextmanager
1819
from dataclasses import dataclass, field
19-
from datetime import datetime
20-
from typing import Any, Generator, Optional
20+
from typing import Any
2121

2222
# Optional import - database support is optional
2323
try:
@@ -71,7 +71,7 @@ class NeonDatabase:
7171
results = db.fetch_all("SELECT * FROM jobs WHERE user_id = %s", (user_id,))
7272
"""
7373

74-
def __init__(self, config: Optional[DatabaseConfig] = None):
74+
def __init__(self, config: DatabaseConfig | None = None):
7575
"""
7676
Initialize database connection.
7777
@@ -85,7 +85,7 @@ def __init__(self, config: Optional[DatabaseConfig] = None):
8585
)
8686

8787
self.config = config or DatabaseConfig()
88-
self._connection_pool: Optional[pool.SimpleConnectionPool] = None
88+
self._connection_pool: pool.SimpleConnectionPool | None = None
8989

9090
if self.config.is_configured:
9191
self._initialize_pool()
@@ -159,7 +159,7 @@ def get_cursor(self, commit: bool = False) -> Generator[Any, None, None]:
159159
finally:
160160
cur.close()
161161

162-
def execute(self, query: str, params: Optional[tuple] = None) -> None:
162+
def execute(self, query: str, params: tuple | None = None) -> None:
163163
"""
164164
Execute a database query (no return value).
165165
@@ -176,7 +176,7 @@ def execute(self, query: str, params: Optional[tuple] = None) -> None:
176176
with self.get_cursor(commit=True) as cur:
177177
cur.execute(query, params or ())
178178

179-
def fetch_one(self, query: str, params: Optional[tuple] = None) -> Optional[dict]:
179+
def fetch_one(self, query: str, params: tuple | None = None) -> dict | None:
180180
"""
181181
Fetch a single row from the database.
182182
@@ -192,7 +192,7 @@ def fetch_one(self, query: str, params: Optional[tuple] = None) -> Optional[dict
192192
result = cur.fetchone()
193193
return dict(result) if result else None
194194

195-
def fetch_all(self, query: str, params: Optional[tuple] = None) -> list[dict]:
195+
def fetch_all(self, query: str, params: tuple | None = None) -> list[dict]:
196196
"""
197197
Fetch all rows from the database.
198198
@@ -230,7 +230,7 @@ def is_healthy(self) -> bool:
230230

231231

232232
# Global database instance (lazy initialization)
233-
_db_instance: Optional[NeonDatabase] = None
233+
_db_instance: NeonDatabase | None = None
234234

235235

236236
def get_database() -> NeonDatabase:
@@ -383,12 +383,12 @@ def init_schema(db: NeonDatabase) -> None:
383383
# Convenience functions for common operations
384384
def log_quantum_job(
385385
job_type: str,
386-
circuit_json: Optional[dict] = None,
386+
circuit_json: dict | None = None,
387387
shots: int = 1024,
388388
backend: str = "simulator",
389-
user_id: Optional[str] = None,
390-
session_id: Optional[str] = None,
391-
) -> Optional[int]:
389+
user_id: str | None = None,
390+
session_id: str | None = None,
391+
) -> int | None:
392392
"""
393393
Log a quantum job execution.
394394
@@ -435,16 +435,16 @@ def log_quantum_job(
435435
def save_vqe_result(
436436
molecule: str,
437437
final_energy: float,
438-
geometry: Optional[str] = None,
438+
geometry: str | None = None,
439439
basis: str = "STO-3G",
440440
optimizer: str = "COBYLA",
441-
initial_energy: Optional[float] = None,
442-
convergence_iterations: Optional[int] = None,
443-
parameters: Optional[dict] = None,
441+
initial_energy: float | None = None,
442+
convergence_iterations: int | None = None,
443+
parameters: dict | None = None,
444444
backend_type: str = "simulator",
445-
noise_profile: Optional[str] = None,
446-
user_id: Optional[str] = None,
447-
) -> Optional[int]:
445+
noise_profile: str | None = None,
446+
user_id: str | None = None,
447+
) -> int | None:
448448
"""
449449
Save VQE computation result.
450450
@@ -505,12 +505,12 @@ def log_api_request(
505505
method: str,
506506
status_code: int,
507507
response_time_ms: int,
508-
user_id: Optional[str] = None,
509-
session_id: Optional[str] = None,
510-
ip_address: Optional[str] = None,
511-
request_data: Optional[dict] = None,
512-
response_data: Optional[dict] = None,
513-
error_message: Optional[str] = None,
508+
user_id: str | None = None,
509+
session_id: str | None = None,
510+
ip_address: str | None = None,
511+
request_data: dict | None = None,
512+
response_data: dict | None = None,
513+
error_message: str | None = None,
514514
) -> None:
515515
"""
516516
Log an API request.

test_neon_integration.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import os
1616
import sys
17-
from datetime import datetime
1817

1918
# Add project root to path
2019
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
@@ -37,13 +36,13 @@ def test_neon_integration():
3736
print(" ℹ️ Set environment variable: export DATABASE_URL='postgresql://...'")
3837
return False
3938
else:
40-
print(f" ✅ DATABASE_URL is set")
39+
print(" ✅ DATABASE_URL is set")
4140
print(f" Host: {database_url.split('@')[1].split('/')[0] if '@' in database_url else 'N/A'}")
4241

4342
if database_url_unpooled:
44-
print(f" ✅ DATABASE_URL_UNPOOLED is set")
43+
print(" ✅ DATABASE_URL_UNPOOLED is set")
4544
else:
46-
print(f" ⚠️ DATABASE_URL_UNPOOLED not set (optional)")
45+
print(" ⚠️ DATABASE_URL_UNPOOLED not set (optional)")
4746

4847
print()
4948

@@ -53,11 +52,9 @@ def test_neon_integration():
5352
from quantumpytho.modules.database import (
5453
DatabaseConfig,
5554
NeonDatabase,
56-
get_database,
5755
init_schema,
5856
log_quantum_job,
5957
save_vqe_result,
60-
get_database,
6158
)
6259
print(" ✅ Database module imported successfully")
6360
except ImportError as e:
@@ -71,21 +68,21 @@ def test_neon_integration():
7168
print("3. Testing database connection...")
7269
try:
7370
config = DatabaseConfig()
74-
print(f" ✅ Database configuration loaded")
71+
print(" ✅ Database configuration loaded")
7572
print(f" Configured: {config.is_configured}")
7673

7774
if not config.is_configured:
7875
print(" ⚠️ Database not configured, skipping connection tests")
7976
return True
8077

8178
db = NeonDatabase(config)
82-
print(f" ✅ Database instance created")
79+
print(" ✅ Database instance created")
8380

8481
if db._connection_pool:
85-
print(f" ✅ Connection pool initialized")
82+
print(" ✅ Connection pool initialized")
8683
print(f" Pool size: {config.pool_min}-{config.pool_max}")
8784
else:
88-
print(f" ❌ Connection pool failed to initialize")
85+
print(" ❌ Connection pool failed to initialize")
8986
return False
9087

9188
except Exception as e:
@@ -99,9 +96,9 @@ def test_neon_integration():
9996
try:
10097
is_healthy = db.is_healthy()
10198
if is_healthy:
102-
print(f" ✅ Database connection is healthy")
99+
print(" ✅ Database connection is healthy")
103100
else:
104-
print(f" ❌ Database connection is unhealthy")
101+
print(" ❌ Database connection is unhealthy")
105102
return False
106103
except Exception as e:
107104
print(f" ❌ Health check failed: {e}")
@@ -113,7 +110,7 @@ def test_neon_integration():
113110
print("5. Testing schema initialization...")
114111
try:
115112
init_schema(db)
116-
print(f" ✅ Schema initialized successfully")
113+
print(" ✅ Schema initialized successfully")
117114
except Exception as e:
118115
print(f" ❌ Schema initialization failed: {e}")
119116
return False
@@ -133,7 +130,7 @@ def test_neon_integration():
133130
if job_id:
134131
print(f" ✅ Quantum job logged (ID: {job_id})")
135132
else:
136-
print(f" ❌ Failed to log quantum job")
133+
print(" ❌ Failed to log quantum job")
137134
return False
138135

139136
# Test VQE result saving
@@ -148,7 +145,7 @@ def test_neon_integration():
148145
if result_id:
149146
print(f" ✅ VQE result saved (ID: {result_id})")
150147
else:
151-
print(f" ❌ Failed to save VQE result")
148+
print(" ❌ Failed to save VQE result")
152149
return False
153150

154151
except Exception as e:
@@ -174,7 +171,7 @@ def test_neon_integration():
174171

175172
# Display sample data
176173
if jobs:
177-
print(f" Sample job data:")
174+
print(" Sample job data:")
178175
print(f" - Job ID: {jobs[0]['id']}")
179176
print(f" - Type: {jobs[0]['job_type']}")
180177
print(f" - Backend: {jobs[0]['backend']}")
@@ -191,7 +188,7 @@ def test_neon_integration():
191188
try:
192189
db.execute("DELETE FROM quantum_jobs WHERE job_type = 'test'")
193190
db.execute("DELETE FROM vqe_results WHERE molecule = 'H2_test'")
194-
print(f" ✅ Test data cleaned up")
191+
print(" ✅ Test data cleaned up")
195192
except Exception as e:
196193
print(f" ⚠️ Cleanup failed (non-critical): {e}")
197194

@@ -201,7 +198,7 @@ def test_neon_integration():
201198
print("9. Checking connection pool status...")
202199
try:
203200
if db._connection_pool:
204-
print(f" ✅ Connection pool active")
201+
print(" ✅ Connection pool active")
205202
print(f" Min connections: {config.pool_min}")
206203
print(f" Max connections: {config.pool_max}")
207204
except Exception as e:

vercel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"framework": null,
3-
"installCommand": "python3 -m venv .vercel-venv && ./.vercel-venv/bin/python -m pip install --upgrade pip setuptools wheel && ./.vercel-venv/bin/python -m pip install -e .[web,database]",
3+
"installCommand": "python3 -m venv .vercel-venv && ./.vercel-venv/bin/python -m pip install --upgrade pip setuptools wheel && ./.vercel-venv/bin/python -m pip install -e .[web,database,docs]",
44
"buildCommand": "./.vercel-venv/bin/python -m mkdocs build --clean",
55
"outputDirectory": "site"
66
}

0 commit comments

Comments
 (0)