From f762f012abc66af509ec485d3c12a7d58af40348 Mon Sep 17 00:00:00 2001 From: Bane Sullivan Date: Sat, 20 Jul 2024 15:00:34 -0700 Subject: [PATCH] Place open function in dedicated module --- localtileserver/__init__.py | 3 ++- localtileserver/client.py | 26 -------------------------- localtileserver/io.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 27 deletions(-) create mode 100644 localtileserver/io.py diff --git a/localtileserver/__init__.py b/localtileserver/__init__.py index da4261c1..2d6f04c2 100644 --- a/localtileserver/__init__.py +++ b/localtileserver/__init__.py @@ -1,7 +1,8 @@ # flake8: noqa: F401 from localtileserver._version import __version__ -from localtileserver.client import TileClient, get_or_create_tile_client, open +from localtileserver.client import TileClient, get_or_create_tile_client from localtileserver.helpers import hillshade, parse_shapely, polygon_to_geojson, save_new_raster +from localtileserver.io import open from localtileserver.report import Report from localtileserver.tiler import get_cache_dir, make_vsi, purge_cache from localtileserver.validate import validate_cog diff --git a/localtileserver/client.py b/localtileserver/client.py index 901779a1..f9725f32 100644 --- a/localtileserver/client.py +++ b/localtileserver/client.py @@ -589,29 +589,3 @@ def get_or_create_tile_client( del source raise e return source, _internally_created - - -def open( - source: Union[ - pathlib.Path, - str, - TileClient, - rasterio.io.DatasetReaderBase, - ], - port: Union[int, str] = "default", - debug: bool = False, -): - """Open a raster file as a TileClient. - - Parameters - ---------- - source : pathlib.Path, str, TileClient, rasterio.io.DatasetReaderBase - The source dataset to use for the tile client. - port : int - The port on your host machine to use for the tile server. This defaults - to getting an available port. - debug : bool - Run the tile server in debug mode. - - """ - return get_or_create_tile_client(source, port=port, debug=debug)[0] diff --git a/localtileserver/io.py b/localtileserver/io.py new file mode 100644 index 00000000..8c8f1eca --- /dev/null +++ b/localtileserver/io.py @@ -0,0 +1,32 @@ +import pathlib +from typing import Union + +import rasterio + +from localtileserver.client import TileClient, get_or_create_tile_client + + +def open( + source: Union[ + pathlib.Path, + str, + TileClient, + rasterio.io.DatasetReaderBase, + ], + port: Union[int, str] = "default", + debug: bool = False, +): + """Open a raster file as a TileClient. + + Parameters + ---------- + source : pathlib.Path, str, TileClient, rasterio.io.DatasetReaderBase + The source dataset to use for the tile client. + port : int + The port on your host machine to use for the tile server. This defaults + to getting an available port. + debug : bool + Run the tile server in debug mode. + + """ + return get_or_create_tile_client(source, port=port, debug=debug)[0]