From 0573a583be6ba2f99a2ad5bcc9c8bd19942ebf4a Mon Sep 17 00:00:00 2001 From: clothespin Date: Mon, 15 Mar 2021 20:49:52 -0700 Subject: [PATCH 01/14] Registers pyplot.draw as inputhook for prompt_toolkit --- gamestonk_terminal/menu.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gamestonk_terminal/menu.py b/gamestonk_terminal/menu.py index 8fb14e0e4a3..d41aabf7244 100644 --- a/gamestonk_terminal/menu.py +++ b/gamestonk_terminal/menu.py @@ -1,11 +1,13 @@ import os +from matplotlib import pyplot + from prompt_toolkit import PromptSession from prompt_toolkit.history import FileHistory history_file = os.path.join(os.path.expanduser("~"), ".gamestonk_terminal.his") try: - session = PromptSession(history=FileHistory(history_file)) + session = PromptSession(history=FileHistory(history_file), inputhook=pyplot.draw()) except Exception as e: # noqa: F841 session = None From 6807c00226bae5e152418097b4b7df9825dc14bc Mon Sep 17 00:00:00 2001 From: clothespin Date: Mon, 15 Mar 2021 21:00:04 -0700 Subject: [PATCH 02/14] whoops pass the function don't call it --- gamestonk_terminal/menu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gamestonk_terminal/menu.py b/gamestonk_terminal/menu.py index d41aabf7244..c6455b7cc2e 100644 --- a/gamestonk_terminal/menu.py +++ b/gamestonk_terminal/menu.py @@ -8,6 +8,6 @@ from prompt_toolkit.history import FileHistory history_file = os.path.join(os.path.expanduser("~"), ".gamestonk_terminal.his") try: - session = PromptSession(history=FileHistory(history_file), inputhook=pyplot.draw()) + session = PromptSession(history=FileHistory(history_file), inputhook=pyplot.draw) except Exception as e: # noqa: F841 session = None From 132e890ca7a34558114378d2ea451bc58184348a Mon Sep 17 00:00:00 2001 From: clothespin Date: Tue, 16 Mar 2021 17:44:14 -0700 Subject: [PATCH 03/14] Adds prompt_toolkit inputhook using helper func since kwarg was removed --- gamestonk_terminal/menu.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gamestonk_terminal/menu.py b/gamestonk_terminal/menu.py index c6455b7cc2e..8f616138a72 100644 --- a/gamestonk_terminal/menu.py +++ b/gamestonk_terminal/menu.py @@ -3,11 +3,18 @@ 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 +def inputhook(inputhook_context): + while not inputhook_context.input_is_ready(): + pyplot.pause(0.1) + return False + history_file = os.path.join(os.path.expanduser("~"), ".gamestonk_terminal.his") try: - session = PromptSession(history=FileHistory(history_file), inputhook=pyplot.draw) + session = PromptSession(history=FileHistory(history_file)) + set_eventloop_with_inputhook(inputhook) except Exception as e: # noqa: F841 - session = None + raise e From 2b045329ce380d6e19cc7c8310064834d9fcc051 Mon Sep 17 00:00:00 2001 From: clothespin Date: Tue, 16 Mar 2021 17:46:44 -0700 Subject: [PATCH 04/14] the linter always goes up --- gamestonk_terminal/menu.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gamestonk_terminal/menu.py b/gamestonk_terminal/menu.py index 8f616138a72..d6cb17b5f96 100644 --- a/gamestonk_terminal/menu.py +++ b/gamestonk_terminal/menu.py @@ -6,11 +6,13 @@ from prompt_toolkit import PromptSession from prompt_toolkit.eventloop.inputhook import set_eventloop_with_inputhook from prompt_toolkit.history import FileHistory + def inputhook(inputhook_context): while not inputhook_context.input_is_ready(): pyplot.pause(0.1) return False + history_file = os.path.join(os.path.expanduser("~"), ".gamestonk_terminal.his") try: From f74612567412261494f4a044fc5857a6d5e94080 Mon Sep 17 00:00:00 2001 From: clothespin Date: Tue, 16 Mar 2021 20:49:29 -0700 Subject: [PATCH 05/14] Disable prompt_toolkit and plt.ion in test suite --- .github/workflows/Mac.yml | 3 +++ .github/workflows/test.yml | 3 +++ .github/workflows/windows.yml | 3 +++ 3 files changed, 9 insertions(+) diff --git a/.github/workflows/Mac.yml b/.github/workflows/Mac.yml index 0636f0aea05..996a29b56f8 100644 --- a/.github/workflows/Mac.yml +++ b/.github/workflows/Mac.yml @@ -1,4 +1,7 @@ name: Mac OS X Full Clean Build with ML +env: + GTFF_USE_PROMPT_TOOLKIT: false + GTFF_USE_ION: false on: push: branches: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 860ceb1ca81..014bd992e6b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,7 @@ name: Tests +env: + GTFF_USE_PROMPT_TOOLKIT: false + GTFF_USE_ION: false on: [pull_request, push] jobs: linting: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 940138e40df..3e469e6fddf 100755 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -1,4 +1,7 @@ name: Windows 10 Full Clean Build with ML +env: + GTFF_USE_PROMPT_TOOLKIT: false + GTFF_USE_ION: false on: push: branches: From d9924a8a3c72e995c02f75e12d661e2ff1435174 Mon Sep 17 00:00:00 2001 From: clothespin Date: Tue, 16 Mar 2021 20:55:17 -0700 Subject: [PATCH 06/14] fix case on workflow env spec? --- .github/workflows/Mac.yml | 4 ++-- .github/workflows/test.yml | 4 ++-- .github/workflows/windows.yml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/Mac.yml b/.github/workflows/Mac.yml index 996a29b56f8..6abdc80c85b 100644 --- a/.github/workflows/Mac.yml +++ b/.github/workflows/Mac.yml @@ -1,7 +1,7 @@ name: Mac OS X Full Clean Build with ML env: - GTFF_USE_PROMPT_TOOLKIT: false - GTFF_USE_ION: false + GTFF_USE_PROMPT_TOOLKIT: False + GTFF_USE_ION: False on: push: branches: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 014bd992e6b..e7f64030943 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,7 @@ name: Tests env: - GTFF_USE_PROMPT_TOOLKIT: false - GTFF_USE_ION: false + GTFF_USE_PROMPT_TOOLKIT: False + GTFF_USE_ION: False on: [pull_request, push] jobs: linting: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 3e469e6fddf..54ce4738fcf 100755 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -1,7 +1,7 @@ name: Windows 10 Full Clean Build with ML env: - GTFF_USE_PROMPT_TOOLKIT: false - GTFF_USE_ION: false + GTFF_USE_PROMPT_TOOLKIT: False + GTFF_USE_ION: False on: push: branches: From d13a6963bdf3ee574f73472e8ecf1919f841ab5d Mon Sep 17 00:00:00 2001 From: clothespin Date: Tue, 16 Mar 2021 21:01:21 -0700 Subject: [PATCH 07/14] python treats all nonempty strings as truthy so let's try empty env --- .github/workflows/Mac.yml | 4 ++-- .github/workflows/test.yml | 4 ++-- .github/workflows/windows.yml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/Mac.yml b/.github/workflows/Mac.yml index 6abdc80c85b..6e53446908f 100644 --- a/.github/workflows/Mac.yml +++ b/.github/workflows/Mac.yml @@ -1,7 +1,7 @@ name: Mac OS X Full Clean Build with ML env: - GTFF_USE_PROMPT_TOOLKIT: False - GTFF_USE_ION: False + GTFF_USE_PROMPT_TOOLKIT: + GTFF_USE_ION: on: push: branches: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e7f64030943..bc6b8d48358 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,7 @@ name: Tests env: - GTFF_USE_PROMPT_TOOLKIT: False - GTFF_USE_ION: False + GTFF_USE_PROMPT_TOOLKIT: + GTFF_USE_ION: on: [pull_request, push] jobs: linting: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 54ce4738fcf..4a5608f55f6 100755 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -1,7 +1,7 @@ name: Windows 10 Full Clean Build with ML env: - GTFF_USE_PROMPT_TOOLKIT: False - GTFF_USE_ION: False + GTFF_USE_PROMPT_TOOLKIT: + GTFF_USE_ION: on: push: branches: From 0a3b91a49462a2d8dd74f92928ce53afb7d88fda Mon Sep 17 00:00:00 2001 From: clothespin Date: Tue, 16 Mar 2021 21:23:18 -0700 Subject: [PATCH 08/14] Tests string-valued env variables for truthiness in feature_flags.py --- .github/workflows/Mac.yml | 4 ++-- .github/workflows/test.yml | 4 ++-- .github/workflows/windows.yml | 4 ++-- gamestonk_terminal/feature_flags.py | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/Mac.yml b/.github/workflows/Mac.yml index 6e53446908f..996a29b56f8 100644 --- a/.github/workflows/Mac.yml +++ b/.github/workflows/Mac.yml @@ -1,7 +1,7 @@ name: Mac OS X Full Clean Build with ML env: - GTFF_USE_PROMPT_TOOLKIT: - GTFF_USE_ION: + GTFF_USE_PROMPT_TOOLKIT: false + GTFF_USE_ION: false on: push: branches: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bc6b8d48358..014bd992e6b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,7 @@ name: Tests env: - GTFF_USE_PROMPT_TOOLKIT: - GTFF_USE_ION: + GTFF_USE_PROMPT_TOOLKIT: false + GTFF_USE_ION: false on: [pull_request, push] jobs: linting: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 4a5608f55f6..3e469e6fddf 100755 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -1,7 +1,7 @@ name: Windows 10 Full Clean Build with ML env: - GTFF_USE_PROMPT_TOOLKIT: - GTFF_USE_ION: + GTFF_USE_PROMPT_TOOLKIT: false + GTFF_USE_ION: false on: push: branches: diff --git a/gamestonk_terminal/feature_flags.py b/gamestonk_terminal/feature_flags.py index cb7481d9127..45b7071bba2 100755 --- a/gamestonk_terminal/feature_flags.py +++ b/gamestonk_terminal/feature_flags.py @@ -1,12 +1,12 @@ import os -USE_COLOR = os.getenv("GTFF_USE_COLOR") or True +USE_COLOR = os.getenv("GTFF_USE_COLOR").lower() not in ['false', '0'] or True USE_FLAIR = os.getenv("GTFF_USE_FLAIR") or "stars" -USE_ION = os.getenv("GTFF_USE_ION") or True -USE_PROMPT_TOOLKIT = os.getenv("GTFF_USE_PROMPT_TOOLKIT") or False +USE_ION = os.getenv("GTFF_USE_ION").lower() not in ['false', '0'] or True +USE_PROMPT_TOOLKIT = os.getenv("GTFF_USE_PROMPT_TOOLKIT").lower() not in ['false', '0'] or False # Enable Prediction features -ENABLE_PREDICT = os.getenv("GTFF_ENABLE_PREDICT") or False +ENABLE_PREDICT = os.getenv("GTFF_ENABLE_PREDICT").lower() not in ['false', '0'] or False # Enable plot autoscaling -USE_PLOT_AUTOSCALING = os.getenv("GTFF_USE_PLOT_AUTOSCALING") or False +USE_PLOT_AUTOSCALING = os.getenv("GTFF_USE_PLOT_AUTOSCALING").lower() not in ['false', '0'] or False From 9a2ee39a1016c98cab56a19820e9bcd6e919869e Mon Sep 17 00:00:00 2001 From: clothespin Date: Tue, 16 Mar 2021 21:25:53 -0700 Subject: [PATCH 09/14] Thank you linter, very cool! --- gamestonk_terminal/feature_flags.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/gamestonk_terminal/feature_flags.py b/gamestonk_terminal/feature_flags.py index 45b7071bba2..6aafa2a0ffb 100755 --- a/gamestonk_terminal/feature_flags.py +++ b/gamestonk_terminal/feature_flags.py @@ -1,12 +1,16 @@ import os -USE_COLOR = os.getenv("GTFF_USE_COLOR").lower() not in ['false', '0'] or True +USE_COLOR = os.getenv("GTFF_USE_COLOR").lower() not in ["false", "0"] or True USE_FLAIR = os.getenv("GTFF_USE_FLAIR") or "stars" -USE_ION = os.getenv("GTFF_USE_ION").lower() not in ['false', '0'] or True -USE_PROMPT_TOOLKIT = os.getenv("GTFF_USE_PROMPT_TOOLKIT").lower() not in ['false', '0'] or False +USE_ION = os.getenv("GTFF_USE_ION").lower() not in ["false", "0"] or True +USE_PROMPT_TOOLKIT = ( + os.getenv("GTFF_USE_PROMPT_TOOLKIT").lower() not in ["false", "0"] or False +) # Enable Prediction features -ENABLE_PREDICT = os.getenv("GTFF_ENABLE_PREDICT").lower() not in ['false', '0'] or False +ENABLE_PREDICT = os.getenv("GTFF_ENABLE_PREDICT").lower() not in ["false", "0"] or False # Enable plot autoscaling -USE_PLOT_AUTOSCALING = os.getenv("GTFF_USE_PLOT_AUTOSCALING").lower() not in ['false', '0'] or False +USE_PLOT_AUTOSCALING = ( + os.getenv("GTFF_USE_PLOT_AUTOSCALING").lower() not in ["false", "0"] or False +) From 7d2d7a4db8b81aa166d3f74924ab01c48c9f5dd8 Mon Sep 17 00:00:00 2001 From: clothespin Date: Tue, 16 Mar 2021 21:35:21 -0700 Subject: [PATCH 10/14] rework feature_flags.py to supply defaults to os.getenv() --- gamestonk_terminal/feature_flags.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/gamestonk_terminal/feature_flags.py b/gamestonk_terminal/feature_flags.py index 6aafa2a0ffb..c96db4a1e7c 100755 --- a/gamestonk_terminal/feature_flags.py +++ b/gamestonk_terminal/feature_flags.py @@ -1,16 +1,23 @@ import os -USE_COLOR = os.getenv("GTFF_USE_COLOR").lower() not in ["false", "0"] or True -USE_FLAIR = os.getenv("GTFF_USE_FLAIR") or "stars" -USE_ION = os.getenv("GTFF_USE_ION").lower() not in ["false", "0"] or True -USE_PROMPT_TOOLKIT = ( - os.getenv("GTFF_USE_PROMPT_TOOLKIT").lower() not in ["false", "0"] or False -) +# env vars are strings not booleans +# check for "false" or "0" +# any other value is true (including empty string) + +USE_COLOR = os.getenv("GTFF_USE_COLOR", "true").lower() not in ["false", "0"] +USE_FLAIR = os.getenv("GTFF_USE_FLAIR", "stars") +USE_ION = os.getenv("GTFF_USE_ION", "true").lower() not in ["false", "0"] +USE_PROMPT_TOOLKIT = os.getenv("GTFF_USE_PROMPT_TOOLKIT", "false").lower() not in [ + "false", + "0", +] + # Enable Prediction features -ENABLE_PREDICT = os.getenv("GTFF_ENABLE_PREDICT").lower() not in ["false", "0"] or False +ENABLE_PREDICT = os.getenv("GTFF_ENABLE_PREDICT", "false").lower() not in ["false", "0"] # Enable plot autoscaling -USE_PLOT_AUTOSCALING = ( - os.getenv("GTFF_USE_PLOT_AUTOSCALING").lower() not in ["false", "0"] or False -) +USE_PLOT_AUTOSCALING = os.getenv("GTFF_USE_PLOT_AUTOSCALING", "false").lower() not in [ + "false", + "0", +] From 081ea2818af6b73931e67f116048e8fa2264d34d Mon Sep 17 00:00:00 2001 From: clothespin Date: Wed, 17 Mar 2021 18:49:23 -0700 Subject: [PATCH 11/14] Adds warning message and fallback for exception handling in menu.py --- gamestonk_terminal/menu.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gamestonk_terminal/menu.py b/gamestonk_terminal/menu.py index d6cb17b5f96..51d76cbab33 100644 --- a/gamestonk_terminal/menu.py +++ b/gamestonk_terminal/menu.py @@ -19,4 +19,5 @@ try: session = PromptSession(history=FileHistory(history_file)) set_eventloop_with_inputhook(inputhook) except Exception as e: # noqa: F841 - raise e + print("WARNING: Prompt toolkit is turned on but did not initialize succesfully. Falling back to input()...") + session = None From 83cfb5b0939df8c2b2efc68f59a814d66cfd148d Mon Sep 17 00:00:00 2001 From: clothespin Date: Wed, 17 Mar 2021 18:51:23 -0700 Subject: [PATCH 12/14] Guess who's back? Back again? Linter's back! Tell a friend --- gamestonk_terminal/menu.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gamestonk_terminal/menu.py b/gamestonk_terminal/menu.py index 51d76cbab33..685eb20c74f 100644 --- a/gamestonk_terminal/menu.py +++ b/gamestonk_terminal/menu.py @@ -19,5 +19,7 @@ try: session = PromptSession(history=FileHistory(history_file)) set_eventloop_with_inputhook(inputhook) except Exception as e: # noqa: F841 - print("WARNING: Prompt toolkit is turned on but did not initialize succesfully. Falling back to input()...") + print( + "WARNING: Prompt toolkit is turned on but did not initialize succesfully. Falling back to input()..." + ) session = None From d58264eb35f60d230224734a0e3773a3fb78293a Mon Sep 17 00:00:00 2001 From: clothespin Date: Wed, 17 Mar 2021 18:55:47 -0700 Subject: [PATCH 13/14] devry: we're serious about success --- gamestonk_terminal/menu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gamestonk_terminal/menu.py b/gamestonk_terminal/menu.py index 685eb20c74f..00e818a0f0d 100644 --- a/gamestonk_terminal/menu.py +++ b/gamestonk_terminal/menu.py @@ -20,6 +20,6 @@ try: set_eventloop_with_inputhook(inputhook) except Exception as e: # noqa: F841 print( - "WARNING: Prompt toolkit is turned on but did not initialize succesfully. Falling back to input()..." + "WARNING: Prompt toolkit is turned on but did not initialize successfully. Falling back to input()..." ) session = None From 7745867d5df6def9fdf1cc92938cd4d23c799160 Mon Sep 17 00:00:00 2001 From: clothespin Date: Thu, 18 Mar 2021 17:30:58 -0700 Subject: [PATCH 14/14] Reworks feature_flags.py to use strtobool from distutils --- gamestonk_terminal/feature_flags.py | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/gamestonk_terminal/feature_flags.py b/gamestonk_terminal/feature_flags.py index c96db4a1e7c..f8360c1872b 100755 --- a/gamestonk_terminal/feature_flags.py +++ b/gamestonk_terminal/feature_flags.py @@ -1,23 +1,13 @@ +from distutils.util import strtobool import os -# env vars are strings not booleans -# check for "false" or "0" -# any other value is true (including empty string) - -USE_COLOR = os.getenv("GTFF_USE_COLOR", "true").lower() not in ["false", "0"] -USE_FLAIR = os.getenv("GTFF_USE_FLAIR", "stars") -USE_ION = os.getenv("GTFF_USE_ION", "true").lower() not in ["false", "0"] -USE_PROMPT_TOOLKIT = os.getenv("GTFF_USE_PROMPT_TOOLKIT", "false").lower() not in [ - "false", - "0", -] - +USE_COLOR = strtobool(os.getenv("GTFF_USE_COLOR", "True")) +USE_FLAIR = os.getenv("GTFF_USE_FLAIR") or "stars" +USE_ION = strtobool(os.getenv("GTFF_USE_ION", "True")) +USE_PROMPT_TOOLKIT = strtobool(os.getenv("GTFF_USE_PROMPT_TOOLKIT", "False")) # Enable Prediction features -ENABLE_PREDICT = os.getenv("GTFF_ENABLE_PREDICT", "false").lower() not in ["false", "0"] +ENABLE_PREDICT = strtobool(os.getenv("GTFF_ENABLE_PREDICT", "False")) # Enable plot autoscaling -USE_PLOT_AUTOSCALING = os.getenv("GTFF_USE_PLOT_AUTOSCALING", "false").lower() not in [ - "false", - "0", -] +USE_PLOT_AUTOSCALING = strtobool(os.getenv("GTFF_USE_PLOT_AUTOSCALING", "False"))