-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
128 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,11 @@ | ||
from ._version import __version__ | ||
from .layer import ( | ||
MapType, | ||
CartoConnection, | ||
GeoColumnType, | ||
register_carto_layer, | ||
get_layer_credentials, | ||
) | ||
from .layer import register_layers | ||
from . import sources | ||
from . import styles | ||
|
||
__all__ = [ | ||
"__version__", | ||
"MapType", | ||
"CartoConnection", | ||
"GeoColumnType", | ||
"register_carto_layer", | ||
"get_layer_credentials", | ||
"register_layers", | ||
"sources", | ||
"styles", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.1.0" | ||
__version__ = "0.2.0b0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import pydeck as pdk | ||
|
||
|
||
def base_source(connection_name: str, access_token: str, api_base_url: str): | ||
return { | ||
"connectionName": connection_name, | ||
"accessToken": access_token, | ||
"apiBaseUrl": api_base_url, | ||
"clientId": "pydeck-carto", | ||
} | ||
|
||
|
||
def vector_table_source(table_name: str, spatial_data_column: str, **kwargs): | ||
return pdk.types.Function( | ||
"vectorTableSource", | ||
**{ | ||
"tableName": table_name, | ||
"spatialDataColumn": spatial_data_column, | ||
**base_source(**kwargs), | ||
} | ||
) | ||
|
||
|
||
def vector_query_source(sql_query: str, spatial_data_column: str, **kwargs): | ||
return pdk.types.Function( | ||
"vectorQuerySource", | ||
**{ | ||
"sqlQuery": sql_query, | ||
"spatialDataColumn": spatial_data_column, | ||
**base_source(**kwargs), | ||
} | ||
) | ||
|
||
|
||
def vector_tileset_source(table_name: str, **kwargs): | ||
return pdk.types.Function( | ||
"vectorTilesetSource", **{"tableName": table_name, **base_source(**kwargs)} | ||
) | ||
|
||
|
||
# TODO: Implement all the source functions and parameters | ||
# https://felixpalmer.github.io/deck.gl/docs/api-reference/carto/data-sources | ||
# h3_table_source | ||
# h3_query_source | ||
# h3_tileset_source | ||
# quadbin_table_source | ||
# quadbin_query_source | ||
# quadbin_tileset_source | ||
# raster_tileset_source (experimental) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,16 @@ | ||
import json | ||
import pydeck as pdk | ||
|
||
from carto_auth import CartoAuth | ||
from pydeck_carto import register_carto_layer, get_layer_credentials | ||
from pydeck_carto.layer import MapType, CartoConnection | ||
from pydeck_carto import register_layers | ||
|
||
|
||
def test_register_carto_layer(): | ||
def test_register_layers(): | ||
pdk.settings.configuration = None | ||
pdk.settings.default_layer_attributes = None | ||
pdk.settings.custom_libraries == [] | ||
register_carto_layer() | ||
register_layers() | ||
assert "notifyError" in pdk.settings.configuration | ||
assert "CartoLayer" in pdk.settings.default_layer_attributes | ||
assert pdk.settings.custom_libraries[0]["libraryName"] == "CartoLayerLibrary" | ||
|
||
|
||
def test_get_layer_credentials(): | ||
carto_auth = CartoAuth( | ||
mode="oauth", | ||
api_base_url="https://api.carto.com", | ||
access_token="1234567890", | ||
expiration=10000000000, | ||
) | ||
assert get_layer_credentials(carto_auth) == { | ||
"apiVersion": "v3", | ||
"apiBaseUrl": "https://api.carto.com", | ||
"accessToken": "1234567890", | ||
} | ||
|
||
|
||
def test_carto_layer_json(): | ||
layer = pdk.Layer( | ||
"CartoLayer", | ||
data="carto-demo-data.demo_tables.wrong_table", | ||
type_=MapType.TABLE, | ||
connection=CartoConnection.CARTO_DW, | ||
credentials={}, | ||
) | ||
json_input = json.loads(layer.to_json()) | ||
|
||
assert json_input["@@type"] == "CartoLayer" | ||
assert json_input["data"] == "carto-demo-data.demo_tables.wrong_table" | ||
assert json_input["type"] == "table" | ||
assert json_input["connection"] == "carto_dw" | ||
assert json_input["credentials"] == {} | ||
# Default attributes | ||
assert json_input["clientId"] == "pydeck-carto" | ||
assert json_input["onDataError"] == {"@@function": "notifyError"} | ||
assert "VectorTileLayer" in pdk.settings.default_layer_attributes | ||
assert "H3TileLayer" in pdk.settings.default_layer_attributes | ||
assert "QuadbinTileLayer" in pdk.settings.default_layer_attributes | ||
assert "RasterTileLayer" in pdk.settings.default_layer_attributes | ||
assert pdk.settings.custom_libraries[0]["libraryName"] == "CartoLibrary" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from pydeck_carto.sources import ( | ||
vector_table_source, | ||
vector_query_source, | ||
vector_tileset_source, | ||
) | ||
|
||
|
||
def test_vector_table_source(): | ||
assert vector_table_source( | ||
table_name="project.database.table", | ||
spatial_data_column="geom", | ||
connection_name="carto_dw", | ||
access_token="1234", | ||
api_base_url="https://carto.com", | ||
).serialize() == { | ||
"@@function": "vectorTableSource", | ||
"tableName": "project.database.table", | ||
"spatialDataColumn": "geom", | ||
"connectionName": "carto_dw", | ||
"accessToken": "1234", | ||
"apiBaseUrl": "https://carto.com", | ||
"clientId": "pydeck-carto", | ||
} | ||
|
||
|
||
def test_vector_query_source(): | ||
assert vector_query_source( | ||
sql_query="select * from project.database.table", | ||
spatial_data_column="geom", | ||
connection_name="carto_dw", | ||
access_token="1234", | ||
api_base_url="https://carto.com", | ||
).serialize() == { | ||
"@@function": "vectorQuerySource", | ||
"sqlQuery": "select * from project.database.table", | ||
"spatialDataColumn": "geom", | ||
"connectionName": "carto_dw", | ||
"accessToken": "1234", | ||
"apiBaseUrl": "https://carto.com", | ||
"clientId": "pydeck-carto", | ||
} | ||
|
||
|
||
def test_vector_tileset_source(): | ||
assert vector_tileset_source( | ||
table_name="project.database.table", | ||
connection_name="carto_dw", | ||
access_token="1234", | ||
api_base_url="https://carto.com", | ||
).serialize() == { | ||
"@@function": "vectorTilesetSource", | ||
"tableName": "project.database.table", | ||
"connectionName": "carto_dw", | ||
"accessToken": "1234", | ||
"apiBaseUrl": "https://carto.com", | ||
"clientId": "pydeck-carto", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
DECKGL_SEMVER = "~8.8.*" | ||
DECKGL_SEMVER = "~9.0.*" |