general: deprecate my.core.dataset and simplify tox file

This commit is contained in:
Dima Gerasimov 2024-08-06 23:44:01 +01:00 committed by karlicoss
parent fb8e9909a4
commit 074e24c309
4 changed files with 16 additions and 34 deletions

View 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})

View file

@ -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 *

View file

@ -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

View file

@ -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}