-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #592 from ungarj/pydantic_basesettings
Pydantic basesettings
- Loading branch information
Showing
8 changed files
with
38 additions
and
39 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
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
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,40 +1,38 @@ | ||
import logging | ||
import os | ||
""" | ||
Combine default values with environment variable values. | ||
""" | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def _merge_gdal_defaults_with_env(): | ||
return {k: os.environ.get(k, v) for k, v in GDAL_HTTP_DEFAULTS.items()} | ||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
|
||
|
||
# defaults sets according to the recommendations given at | ||
# https://developmentseed.org/titiler/advanced/performance_tuning/ | ||
GDAL_HTTP_DEFAULTS = dict( | ||
class GDALHTTPOptions(BaseSettings): | ||
# this will be set later on depending on the opened file | ||
CPL_VSIL_CURL_ALLOWED_EXTENSIONS="", | ||
CPL_VSIL_CURL_ALLOWED_EXTENSIONS: str = "" | ||
# 200MB | ||
CPL_VSIL_CURL_CACHE_SIZE=200_000_000, | ||
CPL_VSIL_CURL_CACHE_SIZE: int = 200_000_000 | ||
# alternative: ARRAY | ||
GDAL_BAND_BLOCK_CACHE="HASHSET", | ||
GDAL_BAND_BLOCK_CACHE: str = "HASHSET" | ||
# # 200MB | ||
# GDAL_CACHEMAX=200, --> activating this seems to let the tests stall at some point | ||
# don't make LIST request | ||
GDAL_DISABLE_READDIR_ON_OPEN="EMPTY_DIR", | ||
GDAL_HTTP_TIMEOUT=30, | ||
GDAL_HTTP_MAX_RETRY=3, | ||
GDAL_HTTP_MERGE_CONSECUTIVE_RANGES=True, | ||
GDAL_HTTP_MULTIPLEX=True, | ||
GDAL_HTTP_RETRY_DELAY=5, | ||
GDAL_HTTP_VERSION=2, | ||
GDAL_DISABLE_READDIR_ON_OPEN: str = "EMPTY_DIR" | ||
GDAL_HTTP_TIMEOUT: int = 30 | ||
GDAL_HTTP_MAX_RETRY: int = 3 | ||
GDAL_HTTP_MERGE_CONSECUTIVE_RANGES: bool = True | ||
GDAL_HTTP_MULTIPLEX: bool = True | ||
GDAL_HTTP_RETRY_DELAY: int = 5 | ||
GDAL_HTTP_VERSION: int = 2 | ||
# let GDAL cache internally | ||
VSI_CACHE=True, | ||
VSI_CACHE: bool = True | ||
# 5MB cache per file | ||
VSI_CACHE_SIZE=5_000_000, | ||
) | ||
GDAL_HTTP_OPTS = _merge_gdal_defaults_with_env() | ||
MAPCHETE_IO_RETRY_SETTINGS = { | ||
"tries": int(os.environ.get("MAPCHETE_IO_RETRY_TRIES", "3")), | ||
"delay": float(os.environ.get("MAPCHETE_IO_RETRY_DELAY", "1")), | ||
"backoff": float(os.environ.get("MAPCHETE_IO_RETRY_BACKOFF", "1")), | ||
} | ||
VSI_CACHE_SIZE: int = 5_000_000 | ||
model_config = SettingsConfigDict() | ||
|
||
|
||
class IORetrySettings(BaseSettings): | ||
tries: int = 3 | ||
delay: float = 1.0 | ||
backoff: float = 1.0 | ||
model_config = SettingsConfigDict(env_prefix="MAPCHETE_IO_RETRY_") |
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
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