Skip to content

Commit 6b54081

Browse files
Migrate project to python 3.7 (#26)
* migrate to python3.7 * fix mypy issues * fix python37 compatibility * update github job * remove annotated usage * isort fixes
1 parent 5081d58 commit 6b54081

File tree

14 files changed

+59
-43
lines changed

14 files changed

+59
-43
lines changed

.github/workflows/python-app.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ jobs:
1818
- name: Check out code
1919
uses: actions/checkout@v2
2020

21-
- name: Set up Python 3.9
21+
- name: Set up Python 3.7
2222
uses: actions/setup-python@v2
2323
with:
24-
python-version: 3.9
24+
python-version: 3.7
2525

2626
- name: Install dependencies
2727
run: |

setup.cfg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ classifiers =
1414
Operating System :: OS Independent
1515
Programming Language :: Python :: 3
1616
Programming Language :: Python :: 3 :: Only
17+
Programming Language :: Python :: 3.7
18+
Programming Language :: Python :: 3.8
1719
Programming Language :: Python :: 3.9
1820
project_urls =
1921
Bug Tracker = https://github.com/firebolt-db/firebolt-sdk/issues
@@ -25,7 +27,7 @@ install_requires =
2527
httpx[http2]==0.19.0
2628
pydantic[dotenv]==1.8.2
2729
readerwriterlock==1.0.9
28-
python_requires = >=3.9
30+
python_requires = >=3.7
2931
package_dir =
3032
= src
3133

src/firebolt/client/client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import time
22
import typing
3-
from functools import cached_property, wraps
3+
from functools import wraps
44
from inspect import cleandoc
55
from json import JSONDecodeError
6-
from typing import Any, Optional, Tuple
6+
from typing import Any, Optional, Tuple, Type
77

88
import httpx
99
from httpx._types import AuthTypes
1010

1111
from firebolt.common.exception import AuthenticationError
12+
from firebolt.common.utils import cached_property
1213

1314
DEFAULT_API_URL: str = "api.app.firebolt.io"
1415
API_REQUEST_TIMEOUT_SECONDS: Optional[int] = 60
15-
_REQUEST_ERRORS: Tuple[type[Exception], ...] = (
16+
_REQUEST_ERRORS: Tuple[Type, ...] = (
1617
httpx.HTTPError,
1718
httpx.InvalidURL,
1819
httpx.CookieConflict,

src/firebolt/common/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from functools import lru_cache
2+
from typing import Callable, TypeVar
3+
4+
T = TypeVar("T")
5+
6+
7+
def cached_property(func: Callable[..., T]) -> T:
8+
return property(lru_cache()(func)) # type: ignore

src/firebolt/db/_types.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
from datetime import date, datetime
44
from enum import Enum
5-
from functools import cached_property
6-
from typing import Union, get_args
5+
from typing import Union
76

87
from ciso8601 import parse_datetime
98

109
from firebolt.common.exception import DataError, NotSupportedError
10+
from firebolt.common.utils import cached_property
1111

1212
_NoneType = type(None)
13+
_col_types = (int, float, str, datetime, date, bool, list, _NoneType)
14+
# duplicating this since 3.7 can't unpack Union
1315
ColType = Union[int, float, str, datetime, date, bool, list, _NoneType]
1416
RawColType = Union[int, float, str, bool, list, _NoneType]
1517

@@ -53,7 +55,7 @@ class ARRAY:
5355
_prefix = "Array("
5456

5557
def __init__(self, subtype: Union[type, ARRAY]):
56-
assert (subtype in get_args(ColType) and subtype is not list) or isinstance(
58+
assert (subtype in _col_types and subtype is not list) or isinstance(
5759
subtype, ARRAY
5860
), f"Invalid array subtype: {str(subtype)}"
5961
self.subtype = subtype

src/firebolt/model/database.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from datetime import datetime
4-
from typing import TYPE_CHECKING, Annotated, Any, Optional
4+
from typing import TYPE_CHECKING, Any, List, Optional
55

66
from pydantic import Field, PrivateAttr
77

@@ -33,13 +33,13 @@ class Database(FireboltBaseModel):
3333
_service: DatabaseService = PrivateAttr()
3434

3535
# required
36-
name: Annotated[str, Field(min_length=1, max_length=255, regex=r"^[0-9a-zA-Z_]+$")]
36+
name: str = Field(min_length=1, max_length=255, regex=r"^[0-9a-zA-Z_]+$")
3737
compute_region_key: RegionKey = Field(alias="compute_region_id")
3838

3939
# optional
4040
database_key: Optional[DatabaseKey] = Field(alias="id")
41-
description: Optional[Annotated[str, Field(max_length=255)]]
42-
emoji: Optional[Annotated[str, Field(max_length=255)]]
41+
description: Optional[str] = Field(max_length=255)
42+
emoji: Optional[str] = Field(max_length=255)
4343
current_status: Optional[str]
4444
health_status: Optional[str]
4545
data_size_full: Optional[int]
@@ -66,7 +66,7 @@ def database_id(self) -> Optional[str]:
6666
return None
6767
return self.database_key.database_id
6868

69-
def get_attached_engines(self) -> list[Engine]:
69+
def get_attached_engines(self) -> List[Engine]:
7070
"""Get a list of engines that are attached to this database."""
7171
return self._service.resource_manager.bindings.get_engines_bound_to_database( # noqa: E501
7272
database=self

src/firebolt/model/engine.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
import time
66
from datetime import datetime
7-
from typing import TYPE_CHECKING, Annotated, Any, Callable, Optional
7+
from typing import TYPE_CHECKING, Any, Callable, Optional
88

99
from pydantic import Field, PrivateAttr
1010

@@ -40,7 +40,7 @@ class EngineSettings(FireboltBaseModel):
4040
"""
4141

4242
preset: str
43-
auto_stop_delay_duration: Annotated[str, Field(regex=r"^[0-9]+[sm]$|^0$")]
43+
auto_stop_delay_duration: str = Field(regex=r"^[0-9]+[sm]$|^0$")
4444
minimum_logging_level: str
4545
is_read_only: bool
4646
warm_up: str
@@ -91,7 +91,7 @@ class Engine(FireboltBaseModel):
9191
_service: EngineService = PrivateAttr()
9292

9393
# required
94-
name: Annotated[str, Field(min_length=1, max_length=255, regex=r"^[0-9a-zA-Z_]+$")]
94+
name: str = Field(min_length=1, max_length=255, regex=r"^[0-9a-zA-Z_]+$")
9595
compute_region_key: RegionKey = Field(alias="compute_region_id")
9696
settings: EngineSettings
9797

src/firebolt/service/binding.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
from typing import List, Optional
22

33
from firebolt.common.exception import AlreadyBoundError
44
from firebolt.common.util import prune_dict
@@ -24,7 +24,7 @@ def get_many(
2424
database_id: Optional[str] = None,
2525
engine_id: Optional[str] = None,
2626
is_system_database: Optional[bool] = None,
27-
) -> list[Binding]:
27+
) -> List[Binding]:
2828
"""
2929
List bindings on Firebolt, optionally filtering by database and engine.
3030
@@ -64,7 +64,7 @@ def get_database_bound_to_engine(self, engine: Engine) -> Optional[Database]:
6464
except IndexError:
6565
return None
6666

67-
def get_engines_bound_to_database(self, database: Database) -> list[Engine]:
67+
def get_engines_bound_to_database(self, database: Database) -> List[Engine]:
6868
"""Get a list of engines that are bound to a database."""
6969
bindings = self.get_many(database_id=database.database_id)
7070
return self.resource_manager.engines.get_by_ids(

src/firebolt/service/database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional, Union
1+
from typing import List, Optional, Union
22

33
from firebolt.model import FireboltBaseModel
44
from firebolt.model.database import Database
@@ -36,7 +36,7 @@ def get_many(
3636
attached_engine_name_eq: str,
3737
attached_engine_name_contains: str,
3838
order_by: Union[str, DatabaseOrder],
39-
) -> list[Database]:
39+
) -> List[Database]:
4040
"""
4141
Get a list of databases on Firebolt.
4242

src/firebolt/service/engine.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import logging
2-
from typing import Optional, Union
1+
from logging import getLogger
2+
from typing import List, Optional, Union
33

44
from firebolt.common.util import prune_dict
55
from firebolt.model import FireboltBaseModel
@@ -12,7 +12,7 @@
1212
from firebolt.service.base import BaseService
1313
from firebolt.service.types import EngineOrder, EngineType, WarmupMethod
1414

15-
logger = logging.getLogger(__name__)
15+
logger = getLogger(__name__)
1616

1717

1818
class EngineService(BaseService):
@@ -24,10 +24,10 @@ def get(self, id_: str) -> Engine:
2424
engine_entry: dict = response.json()["engine"]
2525
return Engine.parse_obj_with_service(obj=engine_entry, engine_service=self)
2626

27-
def get_by_ids(self, ids: list[str]) -> list[Engine]:
27+
def get_by_ids(self, ids: List[str]) -> List[Engine]:
2828
"""Get multiple Engines from Firebolt by their ids."""
2929
response = self.client.post(
30-
url=f"/core/v1/engines:getByIds",
30+
url="/core/v1/engines:getByIds",
3131
json={
3232
"engine_ids": [
3333
{"account_id": self.account_id, "engine_id": engine_id}
@@ -56,7 +56,7 @@ def get_many(
5656
current_status_not_eq: str,
5757
region_eq: str,
5858
order_by: Union[str, EngineOrder],
59-
) -> list[Engine]:
59+
) -> List[Engine]:
6060
"""
6161
Get a list of engines on Firebolt.
6262
@@ -73,7 +73,7 @@ def get_many(
7373
if isinstance(order_by, str):
7474
order_by = EngineOrder[order_by]
7575
response = self.client.get(
76-
url=f"/core/v1/account/engines",
76+
url="/core/v1/account/engines",
7777
params=prune_dict(
7878
{
7979
"page.first": 5000, # FUTURE: pagination support w/ generator

0 commit comments

Comments
 (0)