Skip to content

Commit

Permalink
chore(improvement): error handling and typehinting (#856)
Browse files Browse the repository at this point in the history
* chore(improvement): error handling and typehinting

Signed-off-by: slowy07 <[email protected]>

* fix(typos): ocurred -> occurred

Signed-off-by: slowy07 <[email protected]>

---------

Signed-off-by: slowy07 <[email protected]>
Signed-off-by: slowy07 <[email protected]>
  • Loading branch information
slowy07 authored Jul 28, 2024
1 parent e0af0a3 commit f1b72e0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
31 changes: 18 additions & 13 deletions leafmap/bokehmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(
self.output_notebook = output_notebook
self.output_notebook_done = False

def _repr_mimebundle_(self, **kwargs):
def _repr_mimebundle_(self, **kwargs) -> None:
"""Display the bokeh map. Reference: https://ipython.readthedocs.io/en/stable/config/integrating.html#MyObject._repr_mimebundle_"""
if self.output_notebook and (os.environ["OUTPUT_NOTEBOOK"] == "False"):
output_notebook()
Expand All @@ -73,7 +73,7 @@ def add_basemap(
basemap: Optional[str] = "OpenStreetMap",
retina: Optional[bool] = True,
**kwargs,
):
) -> None:
"""Adds a basemap to the map.
Args:
Expand Down Expand Up @@ -113,7 +113,7 @@ def add_basemap(
elif basemap is None:
raise ValueError("Please specify a valid basemap")

def add_tile(self, tile: str, **kwargs):
def add_tile(self, tile: str, **kwargs) -> None:
"""Adds a tile to the map.
Args:
Expand All @@ -136,7 +136,7 @@ def add_cog_layer(
cog_args: Dict = {},
fit_bounds: bool = True,
**kwargs,
):
) -> None:
"""Adds a COG TileLayer to the map.
Args:
Expand Down Expand Up @@ -174,7 +174,7 @@ def add_raster(
layer_name="Local COG",
open_args={},
**kwargs,
):
) -> None:
"""Add a local raster dataset to the map.
If you are using this function in JupyterHub on a remote server (e.g., Binder, Microsoft Planetary Computer) and
if the raster does not render properly, try running the following code before calling this function:
Expand Down Expand Up @@ -236,7 +236,7 @@ def add_stac_layer(
fit_bounds: Optional[bool] = True,
open_args={},
**kwargs,
):
) -> None:
"""Adds a STAC TileLayer to the map.
Args:
Expand Down Expand Up @@ -266,8 +266,13 @@ def add_stac_layer(
self.fit_bounds(stac_bounds(url, collection, item, titiler_endpoint))

def add_gdf(
self, gdf, to_crs="epsg:3857", tooltips=None, fit_bounds=True, **kwargs
):
self,
gdf,
to_crs: Optional[str] = "epsg:3857",
tooltips: Optional[list] = None,
fit_bounds: bool = True,
**kwargs,
) -> None:
"""Adds a GeoDataFrame to the map.
Args:
Expand Down Expand Up @@ -319,7 +324,7 @@ def add_geojson(
tooltips: Optional[List] = None,
fit_bounds: bool = True,
**kwargs,
):
) -> None:
"""Adds a GeoJSON file to the map.
Args:
Expand Down Expand Up @@ -351,7 +356,7 @@ def add_shp(
tooltips: Optional[List] = None,
fit_bounds: bool = True,
**kwargs,
):
) -> None:
"""Adds a shapefile to the map.
Args:
Expand Down Expand Up @@ -404,7 +409,7 @@ def add_vector(
tooltips: Optional[List] = None,
fit_bounds: bool = True,
**kwargs,
):
) -> None:
"""Adds a vector dataset to the map.
Args:
Expand Down Expand Up @@ -433,7 +438,7 @@ def add_vector(

def to_html(
self, filename: Optional[str] = None, title: Optional[str] = None, **kwargs
):
) -> None:
"""Converts the map to HTML.
Args:
Expand Down Expand Up @@ -463,7 +468,7 @@ def to_streamlit(
height: Optional[int] = 600,
use_container_width: bool = True,
**kwargs,
):
) -> None:
"""Displays the map in a Streamlit app.
Args:
Expand Down
10 changes: 9 additions & 1 deletion leafmap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,15 @@ def _clone_repo(out_dir: Optional[str] = ".", unzip: Optional[bool] = True) -> N
"""
url = "https://github.com/opengeos/leafmap/archive/master.zip"
filename = "leafmap-master.zip"
download_from_url(url, out_file_name=filename, out_dir=out_dir, unzip=unzip)

try:
if not isinstance(out_dir, str):
raise ValueError(
f"The out_dir parametermust be string. Provided: {type(out_dir).__name__}"
)
download_from_url(url, out_file_name=filename, out_dir=out_dir, unzip=unzip)
except Exception as error:
print(f"An error occurred while clone the repository: {str(error)}")


def __install_from_github(url: str) -> None:
Expand Down

0 comments on commit f1b72e0

Please sign in to comment.