Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlalchemy compositional #248

Merged
merged 58 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
c1b7bb0
Split Driver
nickeopti Jan 31, 2022
d587759
Create TerracottaDriver
nickeopti Jan 31, 2022
959ecbf
Move functionality up into Driver
nickeopti Jan 31, 2022
e4fff5d
Split Driver
nickeopti Jan 31, 2022
c936905
Rename accordingly to Driver refactor
nickeopti Jan 31, 2022
230d081
Update tests according to Driver refactor
nickeopti Jan 31, 2022
8447a12
Merge branch 'sqlalchemy' into sqlalchemy-compositional
nickeopti Jan 31, 2022
19b84dc
Remove leftover debugging prints
nickeopti Jan 31, 2022
5161aec
move most logic from raster driver to raster.py module
dionhaefner Jan 31, 2022
9477bf7
go straight to :walrus: jail
dionhaefner Jan 31, 2022
56256ac
... and to py3.6 jail
dionhaefner Jan 31, 2022
afd865a
Add test for key standardization
nickeopti Jan 31, 2022
ac19a83
Merge branch 'sqlalchemy-compositional' of https://github.com/DHI-GRA…
nickeopti Jan 31, 2022
6e5b95a
Test raster retrieval with all resampling methods
nickeopti Jan 31, 2022
37cb0d0
Add test for raster.get_raster_tile
nickeopti Jan 31, 2022
76185e3
Test unknown resampling method
nickeopti Jan 31, 2022
0d1096f
Test raster.get_metadata with large_raster_threshold exceeded
nickeopti Jan 31, 2022
551ae7c
bump coverage
dionhaefner Feb 1, 2022
a2ab041
resolve merge conflicts
dionhaefner Feb 1, 2022
8d7ad06
replace type ignore with assertion
dionhaefner Feb 1, 2022
33373e1
:lipstick:
dionhaefner Feb 1, 2022
36eaf1d
Rename driver files and make key standardization a method
nickeopti Feb 1, 2022
046720d
Remember the new/renamed files!
nickeopti Feb 1, 2022
bd45e00
Use underscores in meta_store and raster_store
nickeopti Feb 1, 2022
d5d1b09
Also standardize the where/keys for get_datasets()
nickeopti Feb 1, 2022
3fdd90a
Rename to squeeze
nickeopti Feb 1, 2022
84a5219
Improve repr
nickeopti Feb 1, 2022
1086d52
Rename to GeoTiffRasterStore
nickeopti Feb 1, 2022
65cd29a
Rename to RelationalMetaStore
nickeopti Feb 1, 2022
fed5a66
Don't use too implicit hacks
nickeopti Feb 1, 2022
ab6449f
Update test to new repr
nickeopti Feb 1, 2022
9ad93b4
Merge branch 'sqlalchemy-compositional' of https://github.com/DHI-GRA…
nickeopti Feb 1, 2022
4ab4bdd
Rename filepath to handle
nickeopti Feb 1, 2022
f89052e
Don't print anything
nickeopti Feb 1, 2022
ca15c4a
Rename *_stores
nickeopti Feb 1, 2022
401728a
Re-rename keys to where
nickeopti Feb 1, 2022
62be08d
Check for missing dataset in get_metadata, not in squeeze
nickeopti Feb 4, 2022
236f677
Define keystype explicitly
nickeopti Feb 4, 2022
c8d93ee
Make keys standardization type check
nickeopti Feb 4, 2022
f523ebe
Improve descriptiveness of metadata reload comment
nickeopti Feb 4, 2022
0cce1b7
Re-rename handle to path
nickeopti Feb 4, 2022
8aad626
update docstrings
mrpgraae Feb 20, 2022
0c1c94c
pin pytest<7.0
mrpgraae Feb 20, 2022
06a6d1a
do not assemble rio env in driver
dionhaefner Feb 21, 2022
da9f20f
Update filename in module docstring
mrpgraae Feb 21, 2022
891185a
docstring polish :memo:
mrpgraae Feb 21, 2022
dc835a6
Improve reprs and satisfy flake8
nickeopti Feb 21, 2022
7e75ff4
Improve normalised path from sqlite metastores and update relevant docs
nickeopti Feb 21, 2022
69b7876
Update filenames in first line of files to reflect their actual filen…
nickeopti Feb 21, 2022
06d6d49
Always stringify url_or_path
nickeopti Feb 21, 2022
722e7df
Rename *Driver classes to *MetaStore
nickeopti Feb 21, 2022
41a26e7
Remove references to rasters in meta stores's documentation
nickeopti Feb 21, 2022
3b65c8f
Simplify docstrings in internal base_classes.py
nickeopti Feb 21, 2022
5a9969e
Fix bug (on Windows paths) in sqlite metastore _normalize_path
nickeopti Feb 21, 2022
d8b1ea2
Specify arguments to MetaStore.insert
nickeopti Feb 21, 2022
cd0fe1d
Specify path in meta stores to be of type str
nickeopti Feb 21, 2022
1556dce
Use SQLAlchemy dialect+driver terminology
nickeopti Feb 21, 2022
b2ebcba
fix API docs
dionhaefner Feb 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ jobs:

- name: Initialize mypy
run: |
mypy . > /dev/null || true
mypy --install-types --non-interactive
mypy --install-types --non-interactive . || true

- name: Run tests
run: |
Expand Down
39 changes: 18 additions & 21 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,27 @@ Get a driver instance

.. autofunction:: terracotta.get_driver

SQLite driver
-------------
TerracottaDriver
----------------

.. autoclass:: terracotta.drivers.sqlite.SQLiteDriver
.. autoclass:: terracotta.drivers.TerracottaDriver
:members:
:undoc-members:
:special-members: __init__
:inherited-members:

Remote SQLite driver
--------------------

.. autoclass:: terracotta.drivers.sqlite_remote.RemoteSQLiteDriver
:members:
:undoc-members:
:special-members: __init__
:inherited-members:
:exclude-members: delete, insert, create
Supported metadata stores
-------------------------

MySQL driver
------------
SQLite metadata store
+++++++++++++++++++++

.. autoclass:: terracotta.drivers.mysql.MySQLDriver
:members:
:undoc-members:
:special-members: __init__
:inherited-members:
.. autoclass:: terracotta.drivers.sqlite_meta_store.SQLiteMetaStore

Remote SQLite metadata store
++++++++++++++++++++++++++++

.. autoclass:: terracotta.drivers.sqlite_remote_meta_store.RemoteSQLiteMetaStore

MySQL metadata store
++++++++++++++++++++

.. autoclass:: terracotta.drivers.mysql_meta_store.MySQLMetaStore
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
],
extras_require={
'test': [
'pytest',
'pytest<7.0',
'pytest-cov',
'pytest-mypy',
'pytest-flake8',
Expand Down
52 changes: 33 additions & 19 deletions terracotta/drivers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,31 @@
import urllib.parse as urlparse
from pathlib import Path

from terracotta.drivers.base import Driver
from terracotta.drivers.base_classes import MetaStore
from terracotta.drivers.terracotta_driver import TerracottaDriver
from terracotta.drivers.geotiff_raster_store import GeoTiffRasterStore

URLOrPathType = Union[str, Path]


def load_driver(provider: str) -> Type[Driver]:
def load_driver(provider: str) -> Type[MetaStore]:
if provider == 'sqlite-remote':
from terracotta.drivers.sqlite_remote import RemoteSQLiteDriver
return RemoteSQLiteDriver
from terracotta.drivers.sqlite_remote_meta_store import RemoteSQLiteMetaStore
return RemoteSQLiteMetaStore

if provider == 'mysql':
from terracotta.drivers.mysql import MySQLDriver
return MySQLDriver
from terracotta.drivers.mysql_meta_store import MySQLMetaStore
return MySQLMetaStore

if provider == 'sqlite':
from terracotta.drivers.sqlite import SQLiteDriver
return SQLiteDriver
from terracotta.drivers.sqlite_meta_store import SQLiteMetaStore
return SQLiteMetaStore

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


def auto_detect_provider(url_or_path: Union[str, Path]) -> str:
parsed_path = urlparse.urlparse(str(url_or_path))
def auto_detect_provider(url_or_path: str) -> str:
parsed_path = urlparse.urlparse(url_or_path)

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


_DRIVER_CACHE: Dict[Tuple[URLOrPathType, str, int], Driver] = {}
_DRIVER_CACHE: Dict[Tuple[URLOrPathType, str, int], TerracottaDriver] = {}


def get_driver(url_or_path: URLOrPathType, provider: str = None) -> Driver:
def get_driver(url_or_path: URLOrPathType, provider: str = None) -> TerracottaDriver:
"""Retrieve Terracotta driver instance for the given path.

This function always returns the same instance for identical inputs.
Expand All @@ -66,25 +68,37 @@ def get_driver(url_or_path: URLOrPathType, provider: str = None) -> Driver:

>>> import terracotta as tc
>>> tc.get_driver('tc.sqlite')
SQLiteDriver('/home/terracotta/tc.sqlite')
TerracottaDriver(
meta_store=SQLiteDriver('/home/terracotta/tc.sqlite'),
raster_store=GeoTiffRasterStore()
)
>>> tc.get_driver('mysql://root@localhost/tc')
MySQLDriver('mysql://root@localhost:3306/tc')
TerracottaDriver(
meta_store=MySQLDriver('mysql+pymysql://localhost:3306/tc'),
raster_store=GeoTiffRasterStore()
)
>>> # pass provider if path is given in a non-standard way
>>> tc.get_driver('root@localhost/tc', provider='mysql')
MySQLDriver('mysql://root@localhost:3306/tc')
TerracottaDriver(
meta_store=MySQLDriver('mysql+pymysql://localhost:3306/tc'),
raster_store=GeoTiffRasterStore()
)

"""
url_or_path = str(url_or_path)

if provider is None: # try and auto-detect
provider = auto_detect_provider(url_or_path)

if isinstance(url_or_path, Path):
url_or_path = str(url_or_path)

DriverClass = load_driver(provider)
normalized_path = DriverClass._normalize_path(url_or_path)
cache_key = (normalized_path, provider, os.getpid())

if cache_key not in _DRIVER_CACHE:
_DRIVER_CACHE[cache_key] = DriverClass(url_or_path)
driver = TerracottaDriver(
meta_store=DriverClass(url_or_path),
raster_store=GeoTiffRasterStore()
)
_DRIVER_CACHE[cache_key] = driver

return _DRIVER_CACHE[cache_key]
206 changes: 0 additions & 206 deletions terracotta/drivers/base.py

This file was deleted.

Loading