Skip to content

Commit 2bd81e6

Browse files
committed
fix: Add optional-dependencies to pyproject.toml for CI, update type annotations for Python 3.9+
- Add [project.optional-dependencies] for test and params extras in pyproject.toml - Update type annotations to use modern syntax (list[X] instead of List[X]) - Update setup.py python_requires to >=3.9, add Python 3.12 classifier - Update ruff target-version to py39 - Remove deprecated ANN101/ANN102 rules from ignore list - Add mypy exclude for .venv, build, dist directories
1 parent d160bcd commit 2bd81e6

5 files changed

Lines changed: 43 additions & 18 deletions

File tree

pyproject.toml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ Documentation = "https://docs.spice.ai/sdks/python-sdk"
3131
Repository = "https://github.com/spiceai/spicepy"
3232
Issues = "https://github.com/spiceai/spicepy/issues"
3333

34+
[project.optional-dependencies]
35+
test = [
36+
"pylint>=3.3.1",
37+
"flake8>=7.1.1",
38+
"ruff>=0.4.0",
39+
"mypy>=1.10.0",
40+
"pytest>=8.3.3",
41+
"pytest-cov>=5.0.0",
42+
"pytest-xdist>=3.5.0",
43+
"pytest-timeout>=2.3.1",
44+
"pytest_httpserver==1.1.3",
45+
"types-requests>=2.31.0",
46+
"pandas-stubs>=2.0.0",
47+
"bandit>=1.7.8",
48+
]
49+
params = [
50+
"adbc-driver-flightsql>=1.0.0",
51+
"adbc-driver-manager>=1.0.0",
52+
]
53+
3454
# ============== Tool Configuration ==============
3555

3656
[tool.mypy]
@@ -49,6 +69,11 @@ warn_unreachable = false
4969
show_error_codes = true
5070
show_column_numbers = true
5171
pretty = true
72+
exclude = [
73+
"^\\.venv/",
74+
"^build/",
75+
"^dist/",
76+
]
5277

5378
[[tool.mypy.overrides]]
5479
module = [
@@ -57,11 +82,13 @@ module = [
5782
"adbc_driver_manager.*",
5883
"certifi",
5984
"pandas",
85+
"_pytest.*",
86+
"pytest.*",
6087
]
6188
ignore_missing_imports = true
6289

6390
[tool.ruff]
64-
target-version = "py38"
91+
target-version = "py39"
6592
line-length = 120
6693
exclude = [
6794
".git",
@@ -105,8 +132,6 @@ ignore = [
105132
"D107", # Missing docstring in __init__
106133
"D203", # 1 blank line required before class docstring (conflicts with D211)
107134
"D213", # Multi-line docstring summary should start at the second line (conflicts with D212)
108-
"ANN101", # Missing type annotation for self
109-
"ANN102", # Missing type annotation for cls
110135
"ANN401", # Dynamically typed expressions (Any) are disallowed
111136
"ANN001", # Missing type annotation for function argument (too strict for legacy code)
112137
"ANN002", # Missing type annotation for *args

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ def setup_package():
3939
"Development Status :: 4 - Beta",
4040
"Intended Audience :: Developers",
4141
"License :: OSI Approved :: Apache Software License",
42-
"Programming Language :: Python :: 3.8",
4342
"Programming Language :: Python :: 3.9",
4443
"Programming Language :: Python :: 3.10",
4544
"Programming Language :: Python :: 3.11",
45+
"Programming Language :: Python :: 3.12",
4646
"Topic :: Software Development :: Libraries",
4747
],
4848
keywords="spice, AI, web3, data, ML",
@@ -57,7 +57,7 @@ def setup_package():
5757
"adbc-driver-manager>=1.0.0",
5858
],
5959
},
60-
python_requires=">=3.8",
60+
python_requires=">=3.9",
6161
platforms=["Any"],
6262
)
6363

spicepy/_client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import platform
44
import threading
55
from pathlib import Path
6-
from typing import Any, Dict, List, Optional, Union
6+
from typing import Any, Optional, Union
77

88
import certifi
99
import pyarrow as pa
@@ -93,7 +93,7 @@ def _init_connection(self):
9393

9494
def _create_param_batch(
9595
self,
96-
params: List[Any],
96+
params: list[Any],
9797
) -> pa.RecordBatch:
9898
"""Create a parameter record batch for binding to a prepared statement.
9999
@@ -131,7 +131,7 @@ def _create_param_batch(
131131
def query_with_params(
132132
self,
133133
sql: str,
134-
params: List[Any],
134+
params: list[Any],
135135
) -> pa.RecordBatchReader:
136136
"""Execute a parameterized SQL query using prepared statements.
137137
@@ -271,7 +271,7 @@ def __init__(
271271
self._adbc_client: Optional[_ADBCClient] = None
272272
self.http = HttpRequests(http_url, self._headers(user_agent))
273273

274-
def _headers(self, user_agent=None) -> Dict[str, str]:
274+
def _headers(self, user_agent=None) -> dict[str, str]:
275275
headers = {
276276
"X-API-Key": self._api_key(),
277277
"Accept": "application/json",
@@ -324,7 +324,7 @@ def query(self, query: str, **kwargs) -> flight.FlightStreamReader:
324324
def query_with_params(
325325
self,
326326
sql: str,
327-
params: List[Any],
327+
params: list[Any],
328328
) -> pa.RecordBatchReader:
329329
"""Execute a parameterized SQL query using ADBC.
330330

spicepy/_http.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import datetime
22
from dataclasses import dataclass
3-
from typing import Any, Callable, Dict, Literal, Optional
3+
from typing import Any, Callable, Literal, Optional
44

55
from requests import Response, Session
66
from requests.adapters import HTTPAdapter, Retry
@@ -15,7 +15,7 @@ class RefreshOpts:
1515
refresh_mode: Optional[str] = None
1616
refresh_jitter_max: Optional[str] = None
1717

18-
def to_dict(self) -> Dict[str, Any]:
18+
def to_dict(self) -> dict[str, Any]:
1919
return {
2020
"refresh_sql": self.refresh_sql,
2121
"refresh_mode": self.refresh_mode,
@@ -27,7 +27,7 @@ def to_dict(self) -> Dict[str, Any]:
2727

2828

2929
class HttpRequests:
30-
def __init__(self, base_url: str, headers: Dict[str, str]) -> None:
30+
def __init__(self, base_url: str, headers: dict[str, str]) -> None:
3131
self.session = self._create_session(headers)
3232

3333
# set the user-agent header
@@ -42,8 +42,8 @@ def send_request(
4242
self,
4343
method: HttpMethod,
4444
path: str,
45-
param: Optional[Dict[str, Any]] = None,
46-
headers: Optional[Dict[str, Any]] = None,
45+
param: Optional[dict[str, Any]] = None,
46+
headers: Optional[dict[str, Any]] = None,
4747
body: Optional[str] = None,
4848
) -> Any:
4949
if headers is None:
@@ -61,7 +61,7 @@ def send_request(
6161
response.raise_for_status()
6262
return response.json()
6363

64-
def prepare_param(self, params: Dict[str, Any]) -> Dict[str, Any]:
64+
def prepare_param(self, params: dict[str, Any]) -> dict[str, Any]:
6565
for k, val in params.items():
6666
if isinstance(val, datetime.timedelta):
6767
params[k] = timedelta_to_duration_str(val)
@@ -84,7 +84,7 @@ def _operation(self, method: HttpMethod) -> Callable[..., Response]:
8484
raise SpiceAIError(f"{method} is not a valid HTTP operation")
8585
return _call
8686

87-
def _create_session(self, headers: Dict[str, str]) -> Session:
87+
def _create_session(self, headers: dict[str, str]) -> Session:
8888
sess = Session()
8989
sess.headers = headers # type: ignore[assignment]
9090
sess.mount(

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import os
6-
from typing import Generator
6+
from collections.abc import Generator
77
from unittest.mock import MagicMock, patch
88

99
import pytest

0 commit comments

Comments
 (0)