Hotfix/weird logs (#5439)

* allow None on credentials model

* encapsulating var inside a function

* removing existing default handlers

* ruff

* filter empty credentials
This commit is contained in:
Henrique Joaquim
2023-09-15 14:34:00 +01:00
committed by GitHub
parent 3a341f9527
commit 41eb6de87b
5 changed files with 22 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
import json
from dataclasses import make_dataclass
from typing import Any, List, Tuple
from pydantic.dataclasses import dataclass as pydanticdataclass
@@ -13,11 +14,13 @@ with open(MISCELLANEOUS_DIRECTORY / "models" / "local_credentials.json") as f:
LOCAL_CREDENTIALS = json.load(f)
fields: List[Tuple[str, type, Any]] = [
(k, str, "REPLACE_ME") for k in list(HUB_CREDENTIALS) + list(LOCAL_CREDENTIALS)
]
dc = make_dataclass(
cls_name="CredentialsModel",
fields=[
(k, str, "REPLACE_ME") for k in list(HUB_CREDENTIALS) + list(LOCAL_CREDENTIALS)
],
fields=fields,
bases=(BaseModel,),
)
dc.__repr__ = dc.__base__.__repr__ # type: ignore

View File

@@ -128,6 +128,7 @@ def set_credentials_from_hub(configs: dict):
"""
if configs:
credentials = configs.get("features_keys", {}) or {}
credentials = {k: v for k, v in credentials.items() if v}
for k, v in credentials.items():
set_credential(k, v)

View File

@@ -816,4 +816,7 @@ def get_spread_for_crypto_pair(
return df
POSSIBLE_CRYPTOS = list(get_erc20_tokens()["symbol"].unique())
@log_start_end(log=logger)
def get_possible_crypto_symbols():
"""Get possible crypto symbols."""
return list(get_erc20_tokens()["symbol"].unique())

View File

@@ -1395,7 +1395,7 @@ class OnchainController(BaseController):
dest="coin",
type=str,
help="ERC20 token symbol or address.",
choices=bitquery_model.POSSIBLE_CRYPTOS,
choices=bitquery_model.get_possible_crypto_symbols(),
metavar="COIN",
)
parser.add_argument(
@@ -1444,7 +1444,8 @@ class OnchainController(BaseController):
)
if ns_parser:
if ns_parser.coin:
if ns_parser.coin in bitquery_model.POSSIBLE_CRYPTOS:
possible_cryptos = bitquery_model.get_possible_crypto_symbols()
if ns_parser.coin in possible_cryptos:
bitquery_view.display_spread_for_crypto_pair(
symbol=ns_parser.coin,
to_symbol=ns_parser.vs,
@@ -1464,7 +1465,7 @@ class OnchainController(BaseController):
else:
similar_cmd = difflib.get_close_matches(
ns_parser.coin,
bitquery_model.POSSIBLE_CRYPTOS,
possible_cryptos,
n=1,
cutoff=0.75,
)
@@ -1486,7 +1487,7 @@ class OnchainController(BaseController):
except Exception:
similar_cmd = difflib.get_close_matches(
ns_parser.coin,
bitquery_model.POSSIBLE_CRYPTOS,
possible_cryptos,
n=1,
cutoff=0.5,
)

View File

@@ -283,6 +283,12 @@ def setup_handlers(settings: Settings):
handler_list = logging_settings.handler_list
verbosity = logging_settings.verbosity
# Remove any existing log handlers
# Notebooks have a root logging handler by default, see https://github.com/ipython/ipython/issues/8282
root_logger = logging.getLogger()
if root_logger.hasHandlers():
root_logger.handlers.clear()
logging.basicConfig(
level=verbosity,
format=FormatterWithExceptions.LOGFORMAT,