diff --git a/my/core/_deprecated/dataset.py b/my/core/_deprecated/dataset.py new file mode 100644 index 0000000..9cca2fd --- /dev/null +++ b/my/core/_deprecated/dataset.py @@ -0,0 +1,12 @@ +from ..common import PathIsh +from ..sqlite import sqlite_connect_immutable + + +def connect_readonly(db: PathIsh): + import dataset # type: ignore + + # see https://github.com/pudo/dataset/issues/136#issuecomment-128693122 + # todo not sure if mode=ro has any benefit, but it doesn't work on read-only filesystems + # maybe it should autodetect readonly filesystems and apply this? not sure + creator = lambda: sqlite_connect_immutable(db) + return dataset.connect('sqlite:///', engine_kwargs={'creator': creator}) diff --git a/my/core/dataset.py b/my/core/dataset.py index 31de4f4..40237a0 100644 --- a/my/core/dataset.py +++ b/my/core/dataset.py @@ -1,31 +1,5 @@ -from __future__ import annotations -from .common import assert_subpackage; assert_subpackage(__name__) +from . import warnings -from .common import PathIsh -from .sqlite import sqlite_connect_immutable +warnings.high(f"{__name__} is deprecated, please use dataset directly if you need or switch to my.core.sqlite") -## sadly dataset doesn't have any type definitions -from typing import Iterable, Iterator, Dict, Optional, Any, Protocol -from contextlib import AbstractContextManager - - -# NOTE: may not be true in general, but will be in the vast majority of cases -row_type_T = Dict[str, Any] - - -class TableT(Iterable, Protocol): - def find(self, *, order_by: Optional[str]=None) -> Iterator[row_type_T]: ... - - -class DatabaseT(AbstractContextManager['DatabaseT'], Protocol): - def __getitem__(self, table: str) -> TableT: ... -## - -# TODO wonder if also need to open without WAL.. test this on read-only directory/db file -def connect_readonly(db: PathIsh) -> DatabaseT: - import dataset # type: ignore - # see https://github.com/pudo/dataset/issues/136#issuecomment-128693122 - # todo not sure if mode=ro has any benefit, but it doesn't work on read-only filesystems - # maybe it should autodetect readonly filesystems and apply this? not sure - creator = lambda: sqlite_connect_immutable(db) - return dataset.connect('sqlite:///', engine_kwargs={'creator': creator}) +from ._deprecated.dataset import * diff --git a/my/core/serialize.py b/my/core/serialize.py index 563e114..b5b1b3a 100644 --- a/my/core/serialize.py +++ b/my/core/serialize.py @@ -2,7 +2,7 @@ import datetime from dataclasses import is_dataclass, asdict from pathlib import Path from decimal import Decimal -from typing import Any, Optional, Callable, NamedTuple, Protocol +from typing import Any, Optional, Callable, NamedTuple from functools import lru_cache from .common import is_namedtuple @@ -250,7 +250,6 @@ def test_dumps(factory: str) -> None: @parametrize('factory', ['orjson', 'simplejson']) def test_dumps_namedtuple(factory: str) -> None: import json as json_builtin # dont cause possible conflicts with module code - import orjson # import to make sure this is installed class _A(NamedTuple): x: int diff --git a/tox.ini b/tox.ini index 0b75b44..02acdfc 100644 --- a/tox.ini +++ b/tox.ini @@ -43,9 +43,6 @@ commands = # tbh not sure if it even belongs to core, maybe move somewhere else.. # same with pandas? --ignore my/core/orgmode.py \ - # causes error during test collection on 3.8 - # dataset is deprecated anyway so whatever - --ignore my/core/dataset.py \ {posargs}