Skip to content

Commit

Permalink
[BugFix] - Remove unused old code (#6395)
Browse files Browse the repository at this point in the history
* Remove unused old code

* Remvove  from settings choices

* Fix CLI exit when FileNotFound error on routine

---------

Co-authored-by: Henrique Joaquim <henriquecjoaquim@gmail.com>
  • Loading branch information
IgorWounds and hjoaquim authored May 13, 2024
1 parent 0139dbf commit b99655a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 102 deletions.
20 changes: 9 additions & 11 deletions cli/openbb_cli/controllers/cli_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from types import MethodType
from typing import Any, Dict, List, Optional

import certifi
import pandas as pd
import requests
from openbb import obb
Expand All @@ -37,7 +36,6 @@
bootup,
first_time_user,
get_flair_and_username,
is_installer,
parse_and_split_input,
print_goodbye,
print_rich_table,
Expand Down Expand Up @@ -66,13 +64,6 @@
env_file = str(ENV_FILE_SETTINGS)
session = Session()

if is_installer():
# Necessary for installer so that it can locate the correct certificates for
# API calls and https
# https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error/73270162#73270162
os.environ["REQUESTS_CA_BUNDLE"] = certifi.where()
os.environ["SSL_CERT_FILE"] = certifi.where()


class CLIController(BaseController):
"""CLI Controller class."""
Expand Down Expand Up @@ -432,8 +423,9 @@ def call_exe(self, other_args: List[str]):
else:
return

with open(routine_path) as fp:
raw_lines = list(fp)
try:
with open(routine_path) as fp:
raw_lines = list(fp)

# Capture ARGV either as list if args separated by commas or as single value
if ns_parser.routine_args:
Expand Down Expand Up @@ -487,6 +479,12 @@ def call_exe(self, other_args: List[str]):
)
self.queue = self.queue[1:]

except FileNotFoundError:
session.console.print(
f"[red]File '{routine_path}' doesn't exist.[/red]\n"
)
return


def handle_job_cmds(jobs_cmds: Optional[List[str]]) -> Optional[List[str]]:
"""Handle job commands."""
Expand Down
1 change: 0 additions & 1 deletion cli/openbb_cli/controllers/settings_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class SettingsController(BaseController):
"""Settings Controller class."""

CHOICES_COMMANDS: List[str] = [
"tab",
"interactive",
"cls",
"watermark",
Expand Down
90 changes: 0 additions & 90 deletions cli/openbb_cli/controllers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from openbb_cli.config.constants import AVAILABLE_FLAIRS, ENV_FILE_SETTINGS
from openbb_cli.session import Session
from openbb_core.app.model.charts.charting_settings import ChartingSettings
from packaging import version
from pytz import all_timezones, timezone
from rich.table import Table

Expand Down Expand Up @@ -91,24 +90,6 @@ def print_goodbye():
Session().console.print(text)


def hide_splashscreen():
"""Hide the splashscreen on Windows bundles.
`pyi_splash` is a PyInstaller "fake-package" that's used to communicate
with the splashscreen on Windows.
Sending the `close` signal to the splash screen is required.
The splash screen remains open until this function is called or the Python
program is terminated.
"""
try:
import pyi_splash # type: ignore # pylint: disable=import-outside-toplevel

pyi_splash.update_text("CLI Loaded!")
pyi_splash.close()
except Exception as e:
Session().console.print(f"Error: Unable to hide splashscreen: {e}")


def print_guest_block_msg():
"""Block guest users from using the cli."""
if Session().is_local():
Expand All @@ -120,19 +101,11 @@ def print_guest_block_msg():
)


def is_installer() -> bool:
"""Check whether or not it is a packaged version (Windows or Mac installer."""
return getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS")


def bootup():
"""Bootup the cli."""
if sys.platform == "win32":
# Enable VT100 Escape Sequence for WINDOWS 10 Ver. 1607
os.system("") # nosec # noqa: S605,S607
# Hide splashscreen loader of the packaged app
if is_installer():
hide_splashscreen()

try:
if os.name == "nt":
Expand All @@ -144,69 +117,6 @@ def bootup():
Session().console.print(e, "\n")


def check_for_updates() -> None:
"""Check if the latest version is running.
Checks github for the latest release version and compares it to cfg.VERSION.
"""
# The commit has was commented out because the terminal was crashing due to git import for multiple users
# ({str(git.Repo('.').head.commit)[:7]})
try:
r = request(
"https://api.github.com/repos/openbb-finance/openbbterminal/releases/latest"
)
except Exception:
r = None

if r and r.status_code == 200:
latest_tag_name = r.json()["tag_name"]
latest_version = version.parse(latest_tag_name)
current_version = version.parse(Session().settings.VERSION)

if check_valid_versions(latest_version, current_version):
if current_version == latest_version:
Session().console.print(
"[green]You are using the latest stable version[/green]"
)
else:
Session().console.print(
"[yellow]You are not using the latest stable version[/yellow]"
)
if current_version < latest_version:
Session().console.print(
"[yellow]Check for updates at https://my.openbb.co/app/terminal/download[/yellow]"
)

else:
Session().console.print(
"[yellow]You are using an unreleased version[/yellow]"
)

else:
Session().console.print("[red]You are using an unrecognized version.[/red]")
else:
Session().console.print(
"[yellow]Unable to check for updates... "
+ "Check your internet connection and try again...[/yellow]"
)
Session().console.print("\n")


def check_valid_versions(
latest_version: version.Version,
current_version: version.Version,
) -> bool:
"""Check if the versions are valid."""
if (
not latest_version
or not current_version
or not isinstance(latest_version, version.Version)
or not isinstance(current_version, version.Version)
):
return False
return True


def welcome_message():
"""Print the welcome message.
Expand Down

0 comments on commit b99655a

Please sign in to comment.