Skip to content

Commit

Permalink
Removed prints (#5367)
Browse files Browse the repository at this point in the history
* Removed prints

* FIxed typing

* FIxed typing

* Fixed typing

* Fixed typing

* Fixed typing

* Fixed typing

* Fixed typing

* Fix

* Reverted stuff
  • Loading branch information
colin99d authored and IgorWounds committed Aug 24, 2023
1 parent 9d70bc7 commit 0846cc8
Show file tree
Hide file tree
Showing 48 changed files with 170 additions and 150 deletions.
4 changes: 2 additions & 2 deletions custom_pre_commit/check_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ def main(ignore_files: Optional[str], ignore_commands: Optional[str]):
if not undocumented:
sys.exit(0)
else:
print("The following commands do not have documentation:")
print("The following commands do not have documentation:") # noqa: T201

undocumented = list(undocumented)
undocumented.sort()
for item in undocumented:
print(item)
print(item) # noqa: T201
sys.exit(1)


Expand Down
2 changes: 1 addition & 1 deletion custom_pre_commit/check_reserved_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def process_file(file_path: str, exp: str):
if long_arg is not None:
long_arg = long_arg.group()
if long_arg not in ("HistoryManager.hist_file", RESERVED_ARGS[short_arg]):
print(
print( # noqa: T201
f"{file_path}: "
f"'-{short_arg}' argument expected '{RESERVED_ARGS[short_arg]}'"
f" but assigned to '{long_arg}'"
Expand Down
4 changes: 1 addition & 3 deletions openbb_terminal/account/account_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def display_personal_routines(df: pd.DataFrame, page: int, pages: int):
show_index=True,
index_name="#",
)
except Exception as exc:
print(exc)
except Exception:
console.print("Failed to display personal routines.")


Expand All @@ -72,7 +71,6 @@ def display_default_routines(df: pd.DataFrame):
"""
try:
df = df.rename(columns={"date_updated": "updated_date"})
print(df)
df = clean_df(df)
print_rich_table(
df=df,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def display_sentiment_stats(
Format to export data
"""
d_stats = finnhub_model.get_sentiment_stats(ticker)
print(d_stats)

if d_stats.empty:
return
Expand Down
31 changes: 17 additions & 14 deletions openbb_terminal/common/technical_analysis/volatility_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from openbb_terminal.common.technical_analysis import ta_helpers
from openbb_terminal.decorators import log_start_end
from openbb_terminal.rich_config import console

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -216,11 +217,11 @@ def standard_deviation(
"""

if window < 2:
print("Error: Window must be at least 2, defaulting to 30.")
console.print("Error: Window must be at least 2, defaulting to 30.")
window = 30

if trading_periods and is_crypto:
print("is_crypto is overridden by trading_periods.")
console.print("is_crypto is overridden by trading_periods.")

if not trading_periods:
trading_periods = 365 if is_crypto else 252
Expand Down Expand Up @@ -273,11 +274,11 @@ def parkinson(
"""

if window < 1:
print("Error: Window must be at least 1, defaulting to 30.")
console.print("Error: Window must be at least 1, defaulting to 30.")
window = 30

if trading_periods and is_crypto:
print("is_crypto is overridden by trading_periods.")
console.print("is_crypto is overridden by trading_periods.")

if not trading_periods:
trading_periods = 365 if is_crypto else 252
Expand Down Expand Up @@ -334,11 +335,11 @@ def garman_klass(
"""

if window < 1:
print("Error: Window must be at least 1, defaulting to 30.")
console.print("Error: Window must be at least 1, defaulting to 30.")
window = 30

if trading_periods and is_crypto:
print("is_crypto is overridden by trading_periods.")
console.print("is_crypto is overridden by trading_periods.")

if not trading_periods:
trading_periods = 365 if is_crypto else 252
Expand Down Expand Up @@ -395,11 +396,11 @@ def hodges_tompkins(
"""

if window < 2:
print("Error: Window must be at least 2, defaulting to 30.")
console.print("Error: Window must be at least 2, defaulting to 30.")
window = 30

if trading_periods and is_crypto:
print("is_crypto is overridden by trading_periods.")
console.print("is_crypto is overridden by trading_periods.")

if not trading_periods:
trading_periods = 365 if is_crypto else 252
Expand Down Expand Up @@ -460,11 +461,11 @@ def rogers_satchell(
"""

if window < 1:
print("Error: Window must be at least 1, defaulting to 30.")
console.print("Error: Window must be at least 1, defaulting to 30.")
window = 30

if trading_periods and is_crypto:
print("is_crypto is overridden by trading_periods.")
console.print("is_crypto is overridden by trading_periods.")

if not trading_periods:
trading_periods = 365 if is_crypto else 252
Expand Down Expand Up @@ -521,11 +522,11 @@ def yang_zhang(
"""

if window < 2:
print("Error: Window must be at least 2, defaulting to 30.")
console.print("Error: Window must be at least 2, defaulting to 30.")
window = 30

if trading_periods and is_crypto:
print("is_crypto is overridden by trading_periods.")
console.print("is_crypto is overridden by trading_periods.")

if not trading_periods:
trading_periods = 365 if is_crypto else 252
Expand Down Expand Up @@ -624,7 +625,7 @@ def cones(
lower_q, upper_q = upper_q, lower_q

if (lower_q >= 1) or (upper_q >= 1):
print("Error: lower_q and upper_q must be between 0 and 1")
console.print("Error: lower_q and upper_q must be between 0 and 1")
cones_df = pd.DataFrame()
return cones_df

Expand All @@ -644,7 +645,9 @@ def cones(
for window in windows:
# Looping to build a dataframe with realized volatility over each window.
if model not in VOLATILITY_MODELS:
print("Model not available. Available models: ", VOLATILITY_MODELS)
console.print(
"Model not available. Available models: ", VOLATILITY_MODELS
)
elif model == "STD":
estimator = standard_deviation(
window=window, data=data, is_crypto=is_crypto
Expand Down
2 changes: 1 addition & 1 deletion openbb_terminal/core/models/sources_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def read_default_sources() -> Dict:
with open(DATA_SOURCES_DEFAULT_FILE) as file:
return flatten(json.load(file))
except Exception as e:
print(
print( # noqa: T201
f"\nFailed to read data sources file: "
f"{DATA_SOURCES_DEFAULT_FILE}\n{e}\n"
)
Expand Down
6 changes: 3 additions & 3 deletions openbb_terminal/core/plots/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
try:
from pywry import PyWry
except ImportError as e:
print(f"\033[91m{e}\033[0m")
print(f"\033[91m{e}\033[0m") # noqa: T201
# pylint: disable=C0412
from openbb_terminal.core.plots.no_import import DummyBackend

Expand Down Expand Up @@ -54,7 +54,7 @@ class PyWry(DummyBackend): # type: ignore
JUPYTER_NOTEBOOK = True

PLOTS_CORE_PATH = Path(__file__).parent.resolve()
PLOTLYJS_PATH = PLOTS_CORE_PATH / "assets" / "plotly-2.24.2.min.js"
PLOTLYJS_PATH: Path = PLOTS_CORE_PATH / "assets" / "plotly-2.24.2.min.js"
BACKEND = None


Expand Down Expand Up @@ -496,7 +496,7 @@ async def download_plotly_js():
file.unlink(missing_ok=True)

except Exception as err: # pylint: disable=W0703
print(f"Error downloading plotly.js: {err}")
console.print(f"Error downloading plotly.js: {err}")


def plots_backend() -> Backend:
Expand Down
6 changes: 2 additions & 4 deletions openbb_terminal/core/plots/plotly_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@

from openbb_terminal import config_terminal
from openbb_terminal.base_helpers import console, strtobool
from openbb_terminal.core.config.paths import (
STYLES_DIRECTORY_REPO,
)
from openbb_terminal.core.config.paths import STYLES_DIRECTORY_REPO
from openbb_terminal.core.plots.backend import PLOTLYJS_PATH, plots_backend
from openbb_terminal.core.plots.config.openbb_styles import (
PLT_COLORWAY,
Expand Down Expand Up @@ -59,7 +57,7 @@ class TerminalStyle:
"""

STYLES_REPO = STYLES_DIRECTORY_REPO
USER_STYLES_DIRECTORY = get_current_user().preferences.USER_STYLES_DIRECTORY
USER_STYLES_DIRECTORY: Path = get_current_user().preferences.USER_STYLES_DIRECTORY

plt_styles_available: Dict[str, Path] = {}
plt_style: str = "dark"
Expand Down
25 changes: 15 additions & 10 deletions openbb_terminal/core/scripts/sdk_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pandas as pd

from openbb_terminal.core.config.paths import MAP_PATH
from openbb_terminal.rich_config import console

try:
import darts # pylint: disable=W0611 # noqa: F401
Expand Down Expand Up @@ -84,8 +85,10 @@ def get_sdk(file_path: Path = MAP_PATH) -> pd.DataFrame:
df = pd.read_csv(base_path / file_path)
df_dups = len(df["trail"]) - len(df["trail"].drop_duplicates())
if df_dups > 0:
print(f"Number of duplicate sdk paths: {df_dups}")
print("This indicates that the same SDK trail is being used multiple times\n")
console.print(f"Number of duplicate sdk paths: {df_dups}")
console.print(
"This indicates that the same SDK trail is being used multiple times\n"
)
views = list(df[["view", "trail"]].itertuples(index=False, name=None))
models = list(df[["model", "trail"]].itertuples(index=False, name=None))
# Add in whether it is a view or a model in pandas
Expand Down Expand Up @@ -146,8 +149,8 @@ def functions_df() -> pd.DataFrame:
func_df["docstring"] = [x[1] for x in all_formatted]
func_dups = len(func_df["name"]) - len(func_df["name"].drop_duplicates())
if func_dups > 0:
print(f"Number of duplicate functions found: {func_dups}")
print(
console.print(f"Number of duplicate functions found: {func_dups}")
console.print(
"This may indicate that functions are defined several times in the terminal.\n"
)
func_df = func_df.set_index("name")
Expand All @@ -159,7 +162,7 @@ def save_df(data: pd.DataFrame) -> None:
time_str = (str(timestamp)).replace(".", "")
output_path = f"{time_str}_sdk_audit.csv"
data.to_csv(output_path)
print(f"File saved to {output_path}")
console.print(f"File saved to {output_path}")


def get_nonconforming_functions(data: pd.DataFrame) -> pd.DataFrame:
Expand Down Expand Up @@ -192,7 +195,7 @@ def get_nonconforming_functions(data: pd.DataFrame) -> pd.DataFrame:


def main():
print(
console.print(
"This tool checks all functions in a file with a name including 'view' or 'model'against\n"
"all functions in the sdk, which is gathered from 'trail_map.csv'. If the generated csv\n"
"has an entry for 'trail' that means it is in the SDK, and if it has an entry for\n"
Expand All @@ -209,15 +212,17 @@ def main():
# Get further stats on bad data
no_doc_count = len(final_df[final_df["docstring"].isnull()].index)
if no_doc_count > 0:
print(f"The number of rows with blank docstrings is: {no_doc_count}")
print(
console.print(f"The number of rows with blank docstrings is: {no_doc_count}")
console.print(
"This indicates a matching function does not exist, is not in a 'model' or 'view'\n"
"file, or that the trailmap does not import it from the place it is defined.\n"
)
dup_name_count = len(final_df[final_df.duplicated(keep=False)].index)
if dup_name_count > 0:
print(f"The number of duplicate functions after merge is: {dup_name_count}")
print(
console.print(
f"The number of duplicate functions after merge is: {dup_name_count}"
)
console.print(
"This most likely indicates that the same function is being used at "
"different SDK endpoints.\n"
)
Expand Down
6 changes: 3 additions & 3 deletions openbb_terminal/core/session/sources_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def read_sources(path: Path) -> Dict:
return flatten(json.load(file))
return {}
except Exception as e:
print(f"\nFailed to read data sources file: {path}\n{e}\n")
print("Falling back to OpenBB default sources.")
print(f"\nFailed to read data sources file: {path}\n{e}\n") # noqa: T201
print("Falling back to OpenBB default sources.") # noqa: T201
return {}


Expand All @@ -45,7 +45,7 @@ def write_sources(sources: Dict, path: Path):
with open(path, "w") as f:
json.dump(extend(sources), f, indent=4)
except Exception as e:
print(f"\nFailed to write data sources file: {path}\n{e}\n")
print(f"\nFailed to write data sources file: {path}\n{e}\n") # noqa: T201


def merge_sources(incoming: Dict, allowed: Dict):
Expand Down
8 changes: 5 additions & 3 deletions openbb_terminal/core/session/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def load_dict_to_model(dictionary: dict, model: Type[T]) -> T:
try:
return model(**dictionary) # type: ignore
except ValidationError as error:
print(f"Error loading {model_name}:")
print(f"Error loading {model_name}:") # noqa: T201
for err in error.errors():
loc = err.get("loc", None)
var_name = str(loc[0]) if loc else ""
Expand All @@ -36,11 +36,13 @@ def load_dict_to_model(dictionary: dict, model: Type[T]) -> T:
fields: dict[str, Any] = model.get_fields()
if var and var_name in fields:
default = fields[var_name].default
print(f" {var_name}: {msg}, using default -> {default}")
print( # noqa: T201
f" {var_name}: {msg}, using default -> {default}"
)

return model(**dictionary) # type: ignore
except Exception:
print(f"Error loading {model_name}, using defaults.")
print(f"Error loading {model_name}, using defaults.") # noqa: T201
return model() # type: ignore


Expand Down
2 changes: 1 addition & 1 deletion openbb_terminal/cryptocurrency/cryptocurrency_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ def plot_order_book(
def check_cg_id(symbol: str):
cg_id = get_coingecko_id(symbol)
if not cg_id:
print(f"\n{symbol} not found on CoinGecko")
console.print(f"\n{symbol} not found on CoinGecko")
return ""
return symbol

Expand Down
3 changes: 2 additions & 1 deletion openbb_terminal/cryptocurrency/defi/coindix_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from openbb_terminal.cryptocurrency.defi import coindix_model
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import export_data, print_rich_table
from openbb_terminal.rich_config import console

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -62,7 +63,7 @@ def display_defi_vaults(
chain=chain, protocol=protocol, kind=kind, sortby=sortby, ascend=ascend
)
if df.empty:
print(
console.print(
f"Couldn't find any vaults for "
f"{'' if not chain else 'chain: ' + chain}"
f"{'' if not protocol else ', protocol: ' + protocol}"
Expand Down
3 changes: 2 additions & 1 deletion openbb_terminal/cryptocurrency/defi/llama_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
lambda_long_number_format,
print_rich_table,
)
from openbb_terminal.rich_config import console

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -166,7 +167,7 @@ def display_historical_tvl(
name=available_protocols[dapp],
)
else:
print(f"{dapp} not found\n")
console.print(f"{dapp} not found\n")
if export and export != "":
export_data(
export,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
def check_cg_id(symbol: str):
cg_id = cryptocurrency_helpers.get_coingecko_id(symbol)
if not cg_id:
print(f"\n{symbol} not found on CoinGecko")
console.print(f"\n{symbol} not found on CoinGecko")
return ""
return symbol

Expand Down
2 changes: 1 addition & 1 deletion openbb_terminal/cryptocurrency/pyth_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ def display_price(symbol: str) -> None:
end="\r",
)
except KeyboardInterrupt:
print(f"\n\nStopped watching {symbol} price and confidence interval\n")
console.print(f"\n\nStopped watching {symbol} price and confidence interval\n")
Loading

0 comments on commit 0846cc8

Please sign in to comment.