Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/load export name to include ticker #3996

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions build/pyinstaller/terminal.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import pathlib
import subprocess
import shutil

from dotenv import set_key

Expand All @@ -10,9 +11,6 @@ from PyInstaller.building.api import PYZ, EXE, COLLECT
from PyInstaller.building.splash import Splash
from PyInstaller.building.build_main import Analysis


# import subprocess

from openbb_terminal.loggers import get_commit_hash

NAME = "OpenBBTerminal"
Expand All @@ -24,6 +22,9 @@ build_type = (
# Local python environment packages folder
pathex = os.path.join(os.path.dirname(os.__file__), "site-packages")

# Getting the "voila.exe" path
voila_path = shutil.which("voila")

# Removing unused ARM64 binary
binary_to_remove = pathlib.Path(
os.path.join(pathex, "_scs_direct.cpython-39-darwin.so")
Expand Down Expand Up @@ -73,6 +74,8 @@ added_files = [
(".env", "."),
(os.path.join(pathex, "blib2to3", "Grammar.txt"), "blib2to3"),
(os.path.join(pathex, "blib2to3", "PatternGrammar.txt"), "blib2to3"),
(os.path.join(pathex, "scipy.libs"), "scipy.libs"),
(voila_path, "."),
]

# Python libraries that are explicitly pulled into the bundle
Expand Down
59 changes: 47 additions & 12 deletions openbb_terminal/dashboards/dashboards_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import os
import subprocess # nosec
import sys
from typing import List

import openbb_terminal.config_terminal as cfg
Expand Down Expand Up @@ -149,7 +150,7 @@ def create_call_voila(
ns_parser = cls.parse_simple_args(parser, other_args)

if ns_parser:
cmd = "jupyter-lab" if ns_parser.jupyter else "voila"
cmd = "jupyter-lab" if ns_parser.jupyter else cls.__get_voila_cmd()
base_path = os.path.join(
os.path.abspath(os.path.dirname(__file__)), "voila"
)
Expand All @@ -165,10 +166,8 @@ def create_call_voila(
if ns_parser.input or response.lower() == "y":
cfg.LOGGING_SUPPRESS = True
subprocess.Popen(
f"{cmd} {file} {args}",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True, # nosec
[cmd, file] if not args else [cmd, file, args],
**cls.__subprocess_args(),
)
cfg.LOGGING_SUPPRESS = False
else:
Expand Down Expand Up @@ -207,13 +206,49 @@ def create_call_streamlit(
f"Warning: opens a port on your computer to run a {cmd} server."
)
response = input("Would you like us to run the server for you [yn]? ")
args = ""
if ns_parser.input or response.lower() == "y":
subprocess.Popen(
f"{cmd} {file} {args}",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True,
)
cfg.LOGGING_SUPPRESS = True
subprocess.Popen([cmd, file], **cls.__subprocess_args())
cfg.LOGGING_SUPPRESS = False
else:
console.print(f"Type: {cmd} stream/{file}\ninto a terminal to run.")

@staticmethod
def __subprocess_args(cwd=None, **options):
"""
Create appropriate kwargs for subprocess calls.
Based on: https://github.com/pyinstaller/pyinstaller/wiki/Recipe-subprocess
"""
if hasattr(subprocess, "STARTUPINFO"):
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
else:
si = None

ret = {
"stdin": subprocess.PIPE,
"stderr": subprocess.PIPE,
"stdout": subprocess.PIPE,
"startupinfo": si,
"env": os.environ,
"cwd": cwd,
}

ret.update(options)

return ret

@staticmethod
def __get_voila_cmd() -> str:
"""
This function returns the command to run Voila.
If the application is frozen using a tool like pyinstaller,
the command will return the path to the Voila executable in the frozen app's directory.
This assumes that the "voila.exe" file (that can be found using "which voila" on a command line)
was properly bundled into the dist folder.
Otherwise, the command will simply return "voila", which assumes the Voila package is installed and
available in the system's PATH or in the conda environment.
Returns:
str: The command to run Voila.
"""
return f"{sys._MEIPASS}/voila.exe" if getattr(sys, "frozen", False) else "voila"
2 changes: 1 addition & 1 deletion openbb_terminal/parent_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ def call_load(self, other_args: List[str]):
export_data(
ns_parser.export,
os.path.dirname(os.path.abspath(__file__)),
"load",
f"load_{self.ticker}",
self.stock.copy(),
)

Expand Down
14 changes: 4 additions & 10 deletions openbb_terminal/terminal_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,17 +410,11 @@ def call_reports(self, _):

def call_dashboards(self, _):
"""Process dashboards command."""
if not is_packaged_application():
from openbb_terminal.dashboards.dashboards_controller import (
DashboardsController,
)
from openbb_terminal.dashboards.dashboards_controller import (
DashboardsController,
)

self.queue = self.load_class(DashboardsController, self.queue)
else:
console.print("This feature is coming soon.")
console.print(
"Use the source code and an Anaconda environment if you are familiar with Python."
)
self.queue = self.load_class(DashboardsController, self.queue)

def call_alternative(self, _):
"""Process alternative command."""
Expand Down
16 changes: 8 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading