From 82e9bdb84951019fb444f5e85b9f1ebb430ff758 Mon Sep 17 00:00:00 2001 From: gabriel-milan Date: Tue, 11 Jul 2023 14:04:09 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20prefeitu?= =?UTF-8?q?ra-rio/fhir-utils@94606fde95de93b30e69219fff37d41c7dd4e23a=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf.html | 233 +++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 73 ++++++++++++++++ version.html | 62 ++++++++++++++ 3 files changed, 368 insertions(+) create mode 100644 conf.html create mode 100644 index.html create mode 100644 version.html diff --git a/conf.html b/conf.html new file mode 100644 index 0000000..c87ca1f --- /dev/null +++ b/conf.html @@ -0,0 +1,233 @@ + + + + + + +fhir_utils.conf API documentation + + + + + + + + + + + +
+
+
+

Module fhir_utils.conf

+
+
+
+ +Expand source code + +
# -*- coding: utf-8 -*-
+from os import getenv
+from typing import Callable, Union
+
+from loguru import logger
+
+
+def getenv_or_action(
+    key: str, action: Union[Callable[[str], str], str], default: str = None
+) -> str:
+    """
+    Get an environment variable or execute an action.
+
+    Args:
+        key (str): The name of the environment variable.
+        action (Union[Callable[[str], str], str]): The action to execute if the
+            environment variable is not set. Can be a callable or a string. If a
+            callable is provided, it will be called with the key as the only
+            argument. If a string is provided, it will check if this callback
+            is implemented here and call it. If not, it will raise an exception.
+        default (str, optional): The default value to return if the environment
+            variable is not set and no action is provided. Defaults to None.
+
+    Returns:
+        str: The value of the environment variable or the result of the action.
+    """
+
+    def _raise(key: str) -> str:
+        raise Exception(
+            f"Environment variable {key} is not set and no action is provided."
+        )
+
+    def _warn(key: str) -> str:
+        logger.warning(f"Environment variable {key} is not set. Using default value.")
+        return default
+
+    def _pass(key: str) -> str:
+        return default
+
+    _val = getenv(key)
+    if _val is None:
+        if action in [None, "pass"]:
+            return _pass(key)
+        elif callable(action):
+            return action(key)
+        elif isinstance(action, str):
+            if action == "raise":
+                return _raise(key)
+            elif action == "warn":
+                return _warn(key)
+            else:
+                raise ValueError(
+                    f'Action "{action}" is not implemented in getenv_or_action.'
+                )
+        else:
+            return default
+    return _val
+
+
+class Settings:
+    __slots__ = ()
+
+
+settings = Settings()
+
+
+
+
+
+
+
+

Functions

+
+
+def getenv_or_action(key: str, action: Union[Callable[[str], str], str], default: str = None) ‑> str +
+
+

Get an environment variable or execute an action.

+

Args

+
+
key : str
+
The name of the environment variable.
+
action : Union[Callable[[str], str], str]
+
The action to execute if the +environment variable is not set. Can be a callable or a string. If a +callable is provided, it will be called with the key as the only +argument. If a string is provided, it will check if this callback +is implemented here and call it. If not, it will raise an exception.
+
default : str, optional
+
The default value to return if the environment +variable is not set and no action is provided. Defaults to None.
+
+

Returns

+
+
str
+
The value of the environment variable or the result of the action.
+
+
+ +Expand source code + +
def getenv_or_action(
+    key: str, action: Union[Callable[[str], str], str], default: str = None
+) -> str:
+    """
+    Get an environment variable or execute an action.
+
+    Args:
+        key (str): The name of the environment variable.
+        action (Union[Callable[[str], str], str]): The action to execute if the
+            environment variable is not set. Can be a callable or a string. If a
+            callable is provided, it will be called with the key as the only
+            argument. If a string is provided, it will check if this callback
+            is implemented here and call it. If not, it will raise an exception.
+        default (str, optional): The default value to return if the environment
+            variable is not set and no action is provided. Defaults to None.
+
+    Returns:
+        str: The value of the environment variable or the result of the action.
+    """
+
+    def _raise(key: str) -> str:
+        raise Exception(
+            f"Environment variable {key} is not set and no action is provided."
+        )
+
+    def _warn(key: str) -> str:
+        logger.warning(f"Environment variable {key} is not set. Using default value.")
+        return default
+
+    def _pass(key: str) -> str:
+        return default
+
+    _val = getenv(key)
+    if _val is None:
+        if action in [None, "pass"]:
+            return _pass(key)
+        elif callable(action):
+            return action(key)
+        elif isinstance(action, str):
+            if action == "raise":
+                return _raise(key)
+            elif action == "warn":
+                return _warn(key)
+            else:
+                raise ValueError(
+                    f'Action "{action}" is not implemented in getenv_or_action.'
+                )
+        else:
+            return default
+    return _val
+
+
+
+
+
+

Classes

+
+
+class Settings +
+
+
+
+ +Expand source code + +
class Settings:
+    __slots__ = ()
+
+
+
+
+
+ +
+ + + \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..3b5bb4b --- /dev/null +++ b/index.html @@ -0,0 +1,73 @@ + + + + + + +fhir_utils API documentation + + + + + + + + + + + +
+
+
+

Package fhir_utils

+
+
+
+ +Expand source code + +
# -*- coding: utf-8 -*-
+from .conf import settings  # noqa
+from .version import __version__  # noqa
+
+
+
+

Sub-modules

+
+
fhir_utils.conf
+
+
+
+
fhir_utils.version
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+ + + \ No newline at end of file diff --git a/version.html b/version.html new file mode 100644 index 0000000..ab34354 --- /dev/null +++ b/version.html @@ -0,0 +1,62 @@ + + + + + + +fhir_utils.version API documentation + + + + + + + + + + + +
+
+
+

Module fhir_utils.version

+
+
+
+ +Expand source code + +
# -*- coding: utf-8 -*-
+import importlib.metadata
+
+__version__ = importlib.metadata.version("fhir_utils")
+
+
+
+
+
+
+
+
+
+
+
+ +
+ + + \ No newline at end of file