Skip to content

Commit a8ee100

Browse files
authored
Merge pull request #248 from DHI-GRAS/sqlalchemy-compositional
Sqlalchemy compositional
2 parents da2bc5b + b2ebcba commit a8ee100

22 files changed

+1493
-1220
lines changed

.github/workflows/test.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ jobs:
7272
7373
- name: Initialize mypy
7474
run: |
75-
mypy . > /dev/null || true
76-
mypy --install-types --non-interactive
75+
mypy --install-types --non-interactive . || true
7776
7877
- name: Run tests
7978
run: |

docs/api.rst

+18-21
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,27 @@ Get a driver instance
1515

1616
.. autofunction:: terracotta.get_driver
1717

18-
SQLite driver
19-
-------------
18+
TerracottaDriver
19+
----------------
2020

21-
.. autoclass:: terracotta.drivers.sqlite.SQLiteDriver
21+
.. autoclass:: terracotta.drivers.TerracottaDriver
2222
:members:
23-
:undoc-members:
24-
:special-members: __init__
25-
:inherited-members:
2623

27-
Remote SQLite driver
28-
--------------------
2924

30-
.. autoclass:: terracotta.drivers.sqlite_remote.RemoteSQLiteDriver
31-
:members:
32-
:undoc-members:
33-
:special-members: __init__
34-
:inherited-members:
35-
:exclude-members: delete, insert, create
25+
Supported metadata stores
26+
-------------------------
3627

37-
MySQL driver
38-
------------
28+
SQLite metadata store
29+
+++++++++++++++++++++
3930

40-
.. autoclass:: terracotta.drivers.mysql.MySQLDriver
41-
:members:
42-
:undoc-members:
43-
:special-members: __init__
44-
:inherited-members:
31+
.. autoclass:: terracotta.drivers.sqlite_meta_store.SQLiteMetaStore
32+
33+
Remote SQLite metadata store
34+
++++++++++++++++++++++++++++
35+
36+
.. autoclass:: terracotta.drivers.sqlite_remote_meta_store.RemoteSQLiteMetaStore
37+
38+
MySQL metadata store
39+
++++++++++++++++++++
40+
41+
.. autoclass:: terracotta.drivers.mysql_meta_store.MySQLMetaStore

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
],
7979
extras_require={
8080
'test': [
81-
'pytest',
81+
'pytest<7.0',
8282
'pytest-cov',
8383
'pytest-mypy',
8484
'pytest-flake8',

terracotta/drivers/__init__.py

+33-19
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,31 @@
88
import urllib.parse as urlparse
99
from pathlib import Path
1010

11-
from terracotta.drivers.base import Driver
11+
from terracotta.drivers.base_classes import MetaStore
12+
from terracotta.drivers.terracotta_driver import TerracottaDriver
13+
from terracotta.drivers.geotiff_raster_store import GeoTiffRasterStore
1214

1315
URLOrPathType = Union[str, Path]
1416

1517

16-
def load_driver(provider: str) -> Type[Driver]:
18+
def load_driver(provider: str) -> Type[MetaStore]:
1719
if provider == 'sqlite-remote':
18-
from terracotta.drivers.sqlite_remote import RemoteSQLiteDriver
19-
return RemoteSQLiteDriver
20+
from terracotta.drivers.sqlite_remote_meta_store import RemoteSQLiteMetaStore
21+
return RemoteSQLiteMetaStore
2022

2123
if provider == 'mysql':
22-
from terracotta.drivers.mysql import MySQLDriver
23-
return MySQLDriver
24+
from terracotta.drivers.mysql_meta_store import MySQLMetaStore
25+
return MySQLMetaStore
2426

2527
if provider == 'sqlite':
26-
from terracotta.drivers.sqlite import SQLiteDriver
27-
return SQLiteDriver
28+
from terracotta.drivers.sqlite_meta_store import SQLiteMetaStore
29+
return SQLiteMetaStore
2830

2931
raise ValueError(f'Unknown database provider {provider}')
3032

3133

32-
def auto_detect_provider(url_or_path: Union[str, Path]) -> str:
33-
parsed_path = urlparse.urlparse(str(url_or_path))
34+
def auto_detect_provider(url_or_path: str) -> str:
35+
parsed_path = urlparse.urlparse(url_or_path)
3436

3537
scheme = parsed_path.scheme
3638
if scheme == 's3':
@@ -42,10 +44,10 @@ def auto_detect_provider(url_or_path: Union[str, Path]) -> str:
4244
return 'sqlite'
4345

4446

45-
_DRIVER_CACHE: Dict[Tuple[URLOrPathType, str, int], Driver] = {}
47+
_DRIVER_CACHE: Dict[Tuple[URLOrPathType, str, int], TerracottaDriver] = {}
4648

4749

48-
def get_driver(url_or_path: URLOrPathType, provider: str = None) -> Driver:
50+
def get_driver(url_or_path: URLOrPathType, provider: str = None) -> TerracottaDriver:
4951
"""Retrieve Terracotta driver instance for the given path.
5052
5153
This function always returns the same instance for identical inputs.
@@ -66,25 +68,37 @@ def get_driver(url_or_path: URLOrPathType, provider: str = None) -> Driver:
6668
6769
>>> import terracotta as tc
6870
>>> tc.get_driver('tc.sqlite')
69-
SQLiteDriver('/home/terracotta/tc.sqlite')
71+
TerracottaDriver(
72+
meta_store=SQLiteDriver('/home/terracotta/tc.sqlite'),
73+
raster_store=GeoTiffRasterStore()
74+
)
7075
>>> tc.get_driver('mysql://root@localhost/tc')
71-
MySQLDriver('mysql://root@localhost:3306/tc')
76+
TerracottaDriver(
77+
meta_store=MySQLDriver('mysql+pymysql://localhost:3306/tc'),
78+
raster_store=GeoTiffRasterStore()
79+
)
7280
>>> # pass provider if path is given in a non-standard way
7381
>>> tc.get_driver('root@localhost/tc', provider='mysql')
74-
MySQLDriver('mysql://root@localhost:3306/tc')
82+
TerracottaDriver(
83+
meta_store=MySQLDriver('mysql+pymysql://localhost:3306/tc'),
84+
raster_store=GeoTiffRasterStore()
85+
)
7586
7687
"""
88+
url_or_path = str(url_or_path)
89+
7790
if provider is None: # try and auto-detect
7891
provider = auto_detect_provider(url_or_path)
7992

80-
if isinstance(url_or_path, Path):
81-
url_or_path = str(url_or_path)
82-
8393
DriverClass = load_driver(provider)
8494
normalized_path = DriverClass._normalize_path(url_or_path)
8595
cache_key = (normalized_path, provider, os.getpid())
8696

8797
if cache_key not in _DRIVER_CACHE:
88-
_DRIVER_CACHE[cache_key] = DriverClass(url_or_path)
98+
driver = TerracottaDriver(
99+
meta_store=DriverClass(url_or_path),
100+
raster_store=GeoTiffRasterStore()
101+
)
102+
_DRIVER_CACHE[cache_key] = driver
89103

90104
return _DRIVER_CACHE[cache_key]

terracotta/drivers/base.py

-206
This file was deleted.

0 commit comments

Comments
 (0)