general: deprecate my.core.dataset and simplify tox file
This commit is contained in:
parent
fb8e9909a4
commit
074e24c309
4 changed files with 16 additions and 34 deletions
12
my/core/_deprecated/dataset.py
Normal file
12
my/core/_deprecated/dataset.py
Normal file
|
@ -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})
|
|
@ -1,31 +1,5 @@
|
||||||
from __future__ import annotations
|
from . import warnings
|
||||||
from .common import assert_subpackage; assert_subpackage(__name__)
|
|
||||||
|
|
||||||
from .common import PathIsh
|
warnings.high(f"{__name__} is deprecated, please use dataset directly if you need or switch to my.core.sqlite")
|
||||||
from .sqlite import sqlite_connect_immutable
|
|
||||||
|
|
||||||
## sadly dataset doesn't have any type definitions
|
from ._deprecated.dataset import *
|
||||||
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})
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import datetime
|
||||||
from dataclasses import is_dataclass, asdict
|
from dataclasses import is_dataclass, asdict
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from decimal import Decimal
|
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 functools import lru_cache
|
||||||
|
|
||||||
from .common import is_namedtuple
|
from .common import is_namedtuple
|
||||||
|
@ -250,7 +250,6 @@ def test_dumps(factory: str) -> None:
|
||||||
@parametrize('factory', ['orjson', 'simplejson'])
|
@parametrize('factory', ['orjson', 'simplejson'])
|
||||||
def test_dumps_namedtuple(factory: str) -> None:
|
def test_dumps_namedtuple(factory: str) -> None:
|
||||||
import json as json_builtin # dont cause possible conflicts with module code
|
import json as json_builtin # dont cause possible conflicts with module code
|
||||||
import orjson # import to make sure this is installed
|
|
||||||
|
|
||||||
class _A(NamedTuple):
|
class _A(NamedTuple):
|
||||||
x: int
|
x: int
|
||||||
|
|
3
tox.ini
3
tox.ini
|
@ -43,9 +43,6 @@ commands =
|
||||||
# tbh not sure if it even belongs to core, maybe move somewhere else..
|
# tbh not sure if it even belongs to core, maybe move somewhere else..
|
||||||
# same with pandas?
|
# same with pandas?
|
||||||
--ignore my/core/orgmode.py \
|
--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}
|
{posargs}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue