Files
OpenBB/openbb_terminal/menu.py
montezdesousa a9787dd2d1 Refactor reports menu and make it work on installer (#2878)
* start papermill rollback

* move reports to templates folder

* comment some stuff

* refactor reports controller

* change var names

* clean ctrl class vars

* small refactoring on metadata search

* relocate some func

* breaking changes

* revert some changes

* destroying changes

* change menu appearance

* change menu appeaerance again

* update choices

* change some assets locations

* remove unused vars

* change some docstrings

* rename vars

* its working

* forgot one dash

* omg its working

* clean some code and doc

* change func name

* fix a bug and add some comments

* fix economy report startup

* add custom reports

* allow custom reports

* forgot to delete this

* unused import

* make somestuff more explicit, 5 min rule

* add helper func

* supress errors--no-verify

* add some type checks

* fix check ipynb func

* check inputs in run

* rewrite some integration tests

* remove unused import

* add some docs to website

* add auto completion

* warn if no forecast

* add to do

* add arg name if 1 arg

* add papermill pointing to github main

* add notebooks

* fix terminal spec

* relocated choices files

* merge main

* relocate website docs for reports

* limit user choices

* fix portfolio auto completion

* limit choices fix

* clean som edocstrings

* limit user choices in run command

* improve run parser

* fix msg

* add reports controller tests

* relax crypto choices limit

* contain commands

* pass pre commit

* flake8

* flake8

* ignore mypy

* pylint

* website

* move docs to jupyter tab

* add installer dep

* remove etf

* remove reports

* update reports to main

* handle events erros

* rever reports to previous commits before main merge

* add papermill installer strategies

* add flags to terminal

* avoid sdk crash

* execute notebook in thread

* remove unused sys

* execute report in a child process

* fix some notebook stuff

* fix portfolio report

* fix reports controller volatility

* change api to sdk

* move images

* remove som unucessary installer imports

* remove debugger warning

* move ipykernel launcher

* supress notebook crash

* remove portfolio decorator

* fix run command

* forgot to change this

* add images

* fix portfolio report

* fix crypto report

* linting and tests

* add run integration test

* pylint

* hide reports module args

* try at supressing args

* try at supreccing warning

* solve some os issues

* handle pm errors

* fix warning unrecognized arguments

* change comment

* avoid crash when parameters not found

* fix etf commands

* minor cleanup

* update forecasting check

* fix some linting

* fix futures test

* pylint

* limit user choices to prompt

* limit user choices to prompt

* supress warnings

* revert poetry lock back to main

* papermill pointing to main

* flake8

* forgot requirements

* Update helper_funcs.py

* Update reports_model.py

* choices

Co-authored-by: hjoaquim <h.joaquim@campus.fct.unl.pt>
Co-authored-by: James Simmons <53658028+simmonsj330@users.noreply.github.com>
2022-10-26 21:27:30 +01:00

68 lines
1.7 KiB
Python

import sys
from typing import Optional
import logging
import os
from matplotlib import pyplot
from prompt_toolkit import PromptSession
from prompt_toolkit.eventloop.inputhook import set_eventloop_with_inputhook
from prompt_toolkit.history import FileHistory
logger = logging.getLogger(__name__)
# pylint: disable=W0104
def is_jupyter() -> bool:
try:
__IPYTHON__ # type: ignore
return True
except NameError:
return False
def is_papermill() -> bool:
"""Check if session is being launched with args '-m ipykernel_launcher',
thus coming from papermill Popen. See 'ipykernel_launcher' in reports_model
for more detail.
"""
return all(
i in sys.argv
for i in [
"-m",
"ipykernel_launcher",
"-f",
"--HistoryManager.hist_file=:memory:",
]
)
def inputhook(inputhook_context):
while not inputhook_context.input_is_ready():
try:
pyplot.pause(0.1)
except Exception as exp:
logger.exception("%s", type(exp).__name__)
continue
return False
history_file = os.path.join(os.path.expanduser("~"), ".openbb_terminal.his")
try:
if not is_jupyter() and not is_papermill():
session: Optional[PromptSession] = PromptSession(
history=FileHistory(history_file)
)
set_eventloop_with_inputhook(inputhook)
else:
session = None
# pylint: disable=unused-variable
except Exception as e: # noqa: F841
logger.exception("%s", type(e).__name__)
print(
"WARNING: Prompt toolkit is turned on but did not initialize successfully."
" Falling back to input()..."
)
session = None # type: ignore