From e5fbc4de706a495992f4da0c6f57464f26f082d4 Mon Sep 17 00:00:00 2001 From: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Date: Thu, 27 Jan 2022 21:43:01 -0500 Subject: [PATCH] Improve Jupyter and API (#1274) * Added no-input option * Added test for gst * Removed export * Added options URL --- .../dashboards/dashboards_controller.py | 26 ++++++++++++------- .../stocks/options/op_helpers.py | 3 ++- tests/gamestonk_terminal/api/test_api.py | 11 ++++++++ .../jupyter/dashboards/chains/_index.md | 3 ++- .../jupyter/dashboards/correlations/_index.md | 3 ++- .../jupyter/dashboards/shortdata/_index.md | 12 ++++----- .../jupyter/dashboards/stocks/_index.md | 4 ++- .../jupyter/dashboards/vsurf/_index.md | 3 ++- 8 files changed, 44 insertions(+), 21 deletions(-) create mode 100644 tests/gamestonk_terminal/api/test_api.py diff --git a/gamestonk_terminal/jupyter/dashboards/dashboards_controller.py b/gamestonk_terminal/jupyter/dashboards/dashboards_controller.py index 07c6736fcdf..e1eb7ae4d00 100644 --- a/gamestonk_terminal/jupyter/dashboards/dashboards_controller.py +++ b/gamestonk_terminal/jupyter/dashboards/dashboards_controller.py @@ -10,10 +10,7 @@ from prompt_toolkit.completion import NestedCompleter from gamestonk_terminal.rich_config import console from gamestonk_terminal.parent_classes import BaseController from gamestonk_terminal import feature_flags as gtff -from gamestonk_terminal.helper_funcs import ( - EXPORT_ONLY_RAW_DATA_ALLOWED, - parse_known_args_and_warn, -) +from gamestonk_terminal.helper_funcs import parse_known_args_and_warn from gamestonk_terminal.menu import session # pylint: disable=consider-using-with @@ -82,19 +79,28 @@ def create_call(other_args: List[str], name: str, filename: str = None) -> None: dest="jupyter", help="Shows dashboard in jupyter-lab.", ) - - ns_parser = parse_known_args_and_warn( - parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED + parser.add_argument( + "-n", + "--no-input", + action="store_true", + default=False, + dest="input", + help="Skips confirmation to run server.", ) + ns_parser = parse_known_args_and_warn(parser, other_args) + if ns_parser: cmd = "jupyter-lab" if ns_parser.jupyter else "voila" file = os.path.join( os.path.abspath(os.path.dirname(__file__)), f"{filename}.ipynb" ) - console.print(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? y/n\n") - if response.lower() == "y": + if not ns_parser.input: + console.print( + 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? y/n\n") + if ns_parser.input or response.lower() == "y": subprocess.Popen( f"{cmd} {file}", stdout=subprocess.PIPE, diff --git a/gamestonk_terminal/stocks/options/op_helpers.py b/gamestonk_terminal/stocks/options/op_helpers.py index 01f0e0f3fde..2869d3ff435 100644 --- a/gamestonk_terminal/stocks/options/op_helpers.py +++ b/gamestonk_terminal/stocks/options/op_helpers.py @@ -141,7 +141,8 @@ class Option: opt_type: int = 1, ): """ - Class for getting the greeks of options + Class for getting the greeks of options. Inspiration from: + http://www.smileofthales.com/computation/option-pricing-python-inheritance/ Parameters ---------- diff --git a/tests/gamestonk_terminal/api/test_api.py b/tests/gamestonk_terminal/api/test_api.py new file mode 100644 index 00000000000..893aaf9598b --- /dev/null +++ b/tests/gamestonk_terminal/api/test_api.py @@ -0,0 +1,11 @@ +# IMPORTATION STANDARD + +# IMPORTATION THIRDPARTY + +# IMPORTATION INTERNAL + + +def test_import_api(): + # pylint: disable=import-outside-toplevel, unused-import + # flake8: noqa + from gamestonk_terminal import api diff --git a/website/content/jupyter/dashboards/chains/_index.md b/website/content/jupyter/dashboards/chains/_index.md index 16dbcbf3ff6..a95a3b4b5c1 100644 --- a/website/content/jupyter/dashboards/chains/_index.md +++ b/website/content/jupyter/dashboards/chains/_index.md @@ -6,6 +6,7 @@ Opens a voila dashboard showing option chain information for a given ticker and ``` optional arguments: - -j opens in jupyterlab instead of voila (default: False) + -j, --jupyter opens in jupyterlab instead of voila (default: False) + -n, --no-input does not ask the user if it can open a server (default: False) -h, --help show this help message ``` diff --git a/website/content/jupyter/dashboards/correlations/_index.md b/website/content/jupyter/dashboards/correlations/_index.md index d09cc3affbf..6727c6aa277 100644 --- a/website/content/jupyter/dashboards/correlations/_index.md +++ b/website/content/jupyter/dashboards/correlations/_index.md @@ -6,6 +6,7 @@ Opens a voila dashboard showing the correlations between stocks ``` optional arguments: - -j opens in jupyterlab instead of voila (default: False) + -j, --jupyter opens in jupyterlab instead of voila (default: False) + -n, --no-input does not ask the user if it can open a server (default: False) -h, --help show this help message ``` diff --git a/website/content/jupyter/dashboards/shortdata/_index.md b/website/content/jupyter/dashboards/shortdata/_index.md index dbd9fee48e4..9ffdb420cd7 100644 --- a/website/content/jupyter/dashboards/shortdata/_index.md +++ b/website/content/jupyter/dashboards/shortdata/_index.md @@ -4,9 +4,9 @@ usage: shortdata [-j] [-h] [--export {csv,json,xlsx}] Shows shortdata dashboard -```optional arguments: - -j, --jupyter Shows dashboard in jupyter-lab. (default: False) - -h, --help show this help message (default: False) - --export {csv,json,xlsx} - Export raw data into csv, json, xlsx (default: ) -``` \ No newline at end of file +``` +optional arguments: + -j, --jupyter opens in jupyterlab instead of voila (default: False) + -n, --no-input does not ask the user if it can open a server (default: False) + -h, --help show this help message +``` diff --git a/website/content/jupyter/dashboards/stocks/_index.md b/website/content/jupyter/dashboards/stocks/_index.md index 95c5be95c47..26a590c86fb 100644 --- a/website/content/jupyter/dashboards/stocks/_index.md +++ b/website/content/jupyter/dashboards/stocks/_index.md @@ -6,6 +6,8 @@ Opens a voila dashboard showing historical data for stocks ``` optional arguments: - -j opens in jupyterlab instead of voila (default: False) + -j, --jupyter opens in jupyterlab instead of voila (default: False) + -n, --no-input does not ask the user if it can open a server (default: False) -h, --help show this help message ``` + diff --git a/website/content/jupyter/dashboards/vsurf/_index.md b/website/content/jupyter/dashboards/vsurf/_index.md index e9cfe935cc6..68f50cc4584 100644 --- a/website/content/jupyter/dashboards/vsurf/_index.md +++ b/website/content/jupyter/dashboards/vsurf/_index.md @@ -6,6 +6,7 @@ Shows the volatility surface for options ``` optional arguments: - -j opens in jupyterlab instead of voila (default: False) + -j, --jupyter opens in jupyterlab instead of voila (default: False) + -n, --no-input does not ask the user if it can open a server (default: False) -h, --help show this help message ```