From 2c56c6f597cd0e3ac4b9955a0c35c544924ff8f4 Mon Sep 17 00:00:00 2001 From: Michael Fekadu Date: Mon, 2 Mar 2020 13:26:07 -0800 Subject: [PATCH 1/2] emphasizes helpful err msg with color && memory-profiler used to debug memory usage --- Pipfile | 4 +++- Pipfile.lock | 24 +++++++++++++++++++++++- requirements.txt | 2 ++ setup_special_files_from_env.py | 17 +++++++++++++++-- 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Pipfile b/Pipfile index 6069200..32a37d7 100644 --- a/Pipfile +++ b/Pipfile @@ -22,7 +22,7 @@ pytest = "==5.3.4" pyre-check = "==0.0.41" ## like the Unix `make` but better invoke = "==1.4.1" - +memory-profiler = "*" [packages] # REST API @@ -61,6 +61,8 @@ six = "==1.11.0" idna = "==2.6" ## because google-auth 1.11.2 wants setuptools>=40.3.0 setuptools = ">=40.3.0" +colorama = "*" +termcolor = "*" [requires] python_version = "3.6" diff --git a/Pipfile.lock b/Pipfile.lock index 6575e89..a2ac4ea 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "fb30d39142d3cc83d8909d9f4f4648a60ac33d4ec3a5a94d8dac7b90ef727a24" + "sha256": "41204f6690fe07c38c1bae8b4faf75cd22d21404e06ea4e5ff8d7876baae06a3" }, "pipfile-spec": 6, "requires": { @@ -72,6 +72,14 @@ ], "version": "==7.0" }, + "colorama": { + "hashes": [ + "sha256:7d73d2a99753107a36ac6b455ee49046802e59d9d076ef8e47b61499fa29afff", + "sha256:e96da0d330793e2cb9485e9ddfd918d456036c7149416295932478192f4436a1" + ], + "index": "pypi", + "version": "==0.4.3" + }, "cymem": { "hashes": [ "sha256:5083b2ab5fe13ced094a82e0df465e2dbbd9b1c013288888035e24fd6eb4ed01", @@ -651,6 +659,13 @@ ], "version": "==1.0.1" }, + "termcolor": { + "hashes": [ + "sha256:1d6d69ce66211143803fbc56652b41d73b4a400a2891d7bf7a1cdf4c02de613b" + ], + "index": "pypi", + "version": "==1.1.0" + }, "thinc": { "hashes": [ "sha256:1dbaec0628040a1f8d66147fadbf7775ad6dfe4c681424b2e20479c1e54dc3c1", @@ -826,6 +841,13 @@ ], "version": "==0.6.1" }, + "memory-profiler": { + "hashes": [ + "sha256:23b196f91ea9ac9996e30bfab1e82fecc30a4a1d24870e81d1e81625f786a2c3" + ], + "index": "pypi", + "version": "==0.57.0" + }, "more-itertools": { "hashes": [ "sha256:5dd8bcf33e5f9513ffa06d5ad33d78f31e1931ac9a18f33d37e77a180d393a7c", diff --git a/requirements.txt b/requirements.txt index 0aaba5b..1a30c3c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,7 @@ catalogue==1.0.0 certifi==2019.11.28 chardet==3.0.4 Click==7.0 +colorama==0.4.3 cymem==2.0.3 Flask==1.1.1 Flask-Cors==3.0.8 @@ -48,6 +49,7 @@ six==1.11.0 spacy==2.2.3 SQLAlchemy==1.3.13 srsly==1.0.1 +termcolor==1.1.0 thinc==7.3.1 tqdm==4.43.0 uritemplate==3.0.1 diff --git a/setup_special_files_from_env.py b/setup_special_files_from_env.py index a98d1b5..2593da7 100755 --- a/setup_special_files_from_env.py +++ b/setup_special_files_from_env.py @@ -2,6 +2,12 @@ from os import environ import json from utilities import yaml_utils # noqa +from colorama import init +from termcolor import colored + +# initialize colorama +init() + # NimbusDatabase stuff SAMPLE_CONFIG_FILE = "config.json_SAMPLE" @@ -22,7 +28,9 @@ GOOGLE_CLOUD_NLP_CREDENTIALS_FILE = "auth.json" GOOGLE_CLOUD_NLP_CREDENTIALS_KEY = "GOOGLE_CLOUD_NLP_CREDENTIALS" -BAD_CONFIG_MSG = "uh oh, config vars not set, check heroku settings" +BAD_CONFIG_MSG = "uh oh, config vars not set,\n\tmake sure to\n\t" + colored( + "source .export_env_vars", "white", "on_cyan", attrs=["bold"] +) assert environ.get("DATABASE_HOSTNAME", None) is not None, BAD_CONFIG_MSG assert environ.get("DATABASE_PASSWORD", None) is not None, BAD_CONFIG_MSG assert environ.get("DATABASE_USERNAME", None) is not None, BAD_CONFIG_MSG @@ -36,7 +44,12 @@ assert environ.get("GOOGLE_CLOUD_NLP_MODEL_NAME", None) is not None, BAD_CONFIG_MSG # noqa # fmt: on -BAD_CONFIG_MSG_2 = "uh oh, config var is empty string, check docker" +BAD_CONFIG_MSG_2 = "uh oh, config var , check docker" + +BAD_CONFIG_MSG_2 = "uh oh, config var is empty string,\n\tcheck docker OR make sure to\n\t" + colored( + "source .export_env_vars", "white", "on_cyan", attrs=["bold"] +) + assert environ.get("DATABASE_HOSTNAME", None) != "", BAD_CONFIG_MSG_2 assert environ.get("DATABASE_PASSWORD", None) != "", BAD_CONFIG_MSG_2 assert environ.get("DATABASE_USERNAME", None) != "", BAD_CONFIG_MSG_2 From 1c79250cfd1f9d7b6819567eb7fa39a109079c25 Mon Sep 17 00:00:00 2001 From: Michael Fekadu Date: Mon, 2 Mar 2020 13:26:39 -0800 Subject: [PATCH 2/2] uses && to make sure each step passes sequentially --- deploy.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deploy.sh b/deploy.sh index 55eda8d..c6281fd 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,5 +1,5 @@ #!/bin/bash -python3 setup_special_files_from_env.py -./download_nlp_stuff.sh -python3 download_nltk_stuff.py -gunicorn flask_api:app --config=gunicorn_config.py +python3 setup_special_files_from_env.py && \ + ./download_nlp_stuff.sh && \ + python3 download_nltk_stuff.py && \ + gunicorn flask_api:app --config=gunicorn_config.py