-
Notifications
You must be signed in to change notification settings - Fork 203
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 #56 from scale-vector/rfix/streamlit-pandas-helpers
streamlit and pandas helpers * allows setting `project_id` via config file/env when default GCP credentials are used. `project_id` if present overrides the one in default credentials * experimental Streamlit helpers to: backup and restore pipeline state into `secrets.toml` and to write explore streamlit page to explore the schema * experimental Pandas helper to read data from a destination into Panda frames using credentials already present in pipeline * bumps to version `0.1.0rc11`
- Loading branch information
Showing
41 changed files
with
1,260 additions
and
176 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
from .run_configuration import RunConfiguration, BaseConfiguration # noqa: F401 | ||
from .run_configuration import RunConfiguration, BaseConfiguration, CredentialsConfiguration # noqa: F401 | ||
from .normalize_volume_configuration import NormalizeVolumeConfiguration, ProductionNormalizeVolumeConfiguration # noqa: F401 | ||
from .load_volume_configuration import LoadVolumeConfiguration, ProductionLoadVolumeConfiguration # noqa: F401 | ||
from .schema_volume_configuration import SchemaVolumeConfiguration, ProductionSchemaVolumeConfiguration # noqa: F401 | ||
from .pool_runner_configuration import PoolRunnerConfiguration, TPoolType # noqa: F401 | ||
from .gcp_client_credentials import GcpClientCredentials # noqa: F401 | ||
from .postgres_credentials import PostgresCredentials # noqa: F401 | ||
from .utils import make_configuration, TSecretValue # noqa: F401 | ||
from .utils import make_configuration # noqa: F401 | ||
|
||
from .exceptions import ( # noqa: F401 | ||
ConfigEntryMissingException, ConfigEnvValueCannotBeCoercedException, ConfigIntegrityException, ConfigFileNotFoundException) |
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
Empty file.
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,40 @@ | ||
from os import environ | ||
from os.path import isdir | ||
from typing import Any, Optional, Type | ||
|
||
from dlt.common.typing import TSecretValue | ||
|
||
SECRET_STORAGE_PATH: str = "/run/secrets/%s" | ||
|
||
|
||
def get_key_name(key: str, namespace: str = None) -> str: | ||
if namespace: | ||
return namespace + "__" + key | ||
else: | ||
return key | ||
|
||
|
||
def get_key(key: str, hint: Type[Any], namespace: str = None) -> Optional[str]: | ||
# apply namespace to the key | ||
key = get_key_name(key, namespace) | ||
if hint is TSecretValue: | ||
# try secret storage | ||
try: | ||
# must conform to RFC1123 | ||
secret_name = key.lower().replace("_", "-") | ||
secret_path = SECRET_STORAGE_PATH % secret_name | ||
# kubernetes stores secrets as files in a dir, docker compose plainly | ||
if isdir(secret_path): | ||
secret_path += "/" + secret_name | ||
with open(secret_path, "r", encoding="utf-8") as f: | ||
secret = f.read() | ||
# add secret to environ so forks have access | ||
# TODO: removing new lines is not always good. for password OK for PEMs not | ||
# TODO: in regular secrets that is dealt with in particular configuration logic | ||
environ[key] = secret.strip() | ||
# do not strip returned secret | ||
return secret | ||
# includes FileNotFound | ||
except OSError: | ||
pass | ||
return environ.get(key, None) |
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import functools | ||
import hexbytes | ||
from typing import Any | ||
|
||
from dlt.common import Decimal | ||
from dlt.common.arithmetics import Context, default_context, decimal | ||
from dlt.common.typing import StrAny | ||
|
||
# default scale of platform contracts | ||
WEI_SCALE = 18 | ||
# log(2^256) + 1 | ||
EVM_DECIMAL_PRECISION = 78 | ||
# value of one at wei scale | ||
WEI_SCALE_POW = 10**18 | ||
|
||
|
||
# class WeiDecimal(Decimal): | ||
# ctx = default_context(decimal.getcontext().copy(), EVM_DECIMAL_PRECISION) | ||
# def __new__(cls, *args: Any, **kwargs: Any) -> "Wei": | ||
# c = default_context(decimal.getcontext().copy(), EVM_DECIMAL_PRECISION) | ||
# d = super(WeiDecimal, cls).__new__(cls, *args, **kwargs, context=c) | ||
# d.c = c | ||
# # d.c = default_context(decimal.getcontext().copy(), EVM_DECIMAL_PRECISION) | ||
# return d | ||
|
||
# def __getattribute__(self, __name: str) -> Any: | ||
# rv = super().__getattribute__(__name) | ||
# if callable(rv) and not __name.startswith("_"): | ||
# if "context" in rv.func_code.co_varnames: | ||
# return functools.partialmethod(rv, context=self.c) | ||
# return rv | ||
|
||
# def __repr__(self) -> str: | ||
# return super().__repr__().replace("Decimal", "Wei") | ||
|
||
|
||
class Wei(Decimal): | ||
|
||
ctx = default_context(decimal.getcontext().copy(), EVM_DECIMAL_PRECISION) | ||
|
||
# def __slots__hints__(self) -> None: | ||
# self._scale: int = 0 | ||
|
||
# def __new__(cls, value: int, scale: int = 0) -> "Wei": | ||
# self = super(Wei, cls).__new__(cls, value) | ||
# self._scale = scale | ||
# return self | ||
|
||
# def __init__(self, value: int, scale: int = 0) -> None: | ||
# self._c = default_context(decimal.getcontext().copy(), EVM_DECIMAL_PRECISION) | ||
# self.value = value | ||
# self.scale = scale | ||
|
||
|
||
# def to_decimal(): | ||
# pass | ||
|
||
# def __get__(self, obj, type=None) -> object: | ||
# print("GET!") | ||
# if self.normalize(self.ctx) > 100: | ||
# return "STR" | ||
# else: | ||
# return self | ||
|
||
def __new__(cls, value: int, scale: int = 0) -> "Wei": | ||
d: "Wei" = None | ||
if scale == 0: | ||
d = super(Wei, cls).__new__(cls, value) | ||
else: | ||
d = super(Wei, cls).__new__(cls, Decimal(value, context=cls.ctx) / 10**scale) | ||
|
||
return d | ||
|
||
# def from_uint256(value: int, scale: int = 0): | ||
# pass | ||
|
||
# # def __repr__(self) -> str: | ||
# # return f"{self.scale},{self.value}" |
Oops, something went wrong.