From 853d4813254c717be80645cf1c73891d62044e0e Mon Sep 17 00:00:00 2001 From: Pan Chasinga Date: Mon, 16 Aug 2021 15:58:38 -0700 Subject: [PATCH 1/3] Replace print statement with logger --- python-package/setup.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/python-package/setup.py b/python-package/setup.py index e4fd1c0..8b0c1d4 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -1,11 +1,14 @@ +import logging import multiprocessing import os -import shutil import subprocess -import sys from setuptools import find_packages, setup +# # Configure logging +logger = logging.getLogger() +logger.setLevel("DEBUG") + # Get the absolute path of setup.py setup_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) @@ -101,8 +104,8 @@ # to the root directory of the mc2 repository for easier paths in # the configuration yamls. -print("\n####################\n") -print("Configuring shell for MC2 Client...\n") +logger.debug("\n{:#^20}\n".format('')) +logger.debug("Configuring shell for MC2 Client...\n") home_path = os.path.abspath(os.path.join(setup_path, "../")) # Terminal shell initialization scripts to support @@ -143,20 +146,20 @@ def set_path(path): shell_paths_set = [set_path(path) for path in shell_paths] if not any(shell_paths_set): - print("ERROR: Failed to write to any of the following:\n") + logger.debug("ERROR: Failed to write to any of the following:\n") for path in shell_paths: - print(f"\t{path}") - print( + logger.debug(f"\t{path}") + logger.debug( "\nPlease add the following line to your shell initialization\n" "file to ensure that MC2 Client is configured automatically:\n\n" f"\texport MC2_CLIENT_HOME={home_path}" ) else: - print("Successfully modified:\n") + logger.debug("Successfully modified:\n") for (success, path) in zip(shell_paths_set, shell_paths): if success: - print(f"\t{path}") - print("\nTo run MC2 Client you may need to restart your current shell.") + logger.debug(f"\t{path}") + logger.debug("\nTo run MC2 Client you may need to restart your current shell.") env_path = os.path.join(home_path, "mc2_client_env") print(f"\nTo configure your current shell, run:\n\n\tsource {env_path}\n") From 60c2ea438b0ac449673d29e5cea080768e12f0f6 Mon Sep 17 00:00:00 2001 From: Pan Chasinga Date: Tue, 17 Aug 2021 13:47:31 -0700 Subject: [PATCH 2/3] Revert "Replace print statement with logger" This reverts commit 853d4813254c717be80645cf1c73891d62044e0e. It's best to leave print statements in the setup script. See also: #179 --- python-package/setup.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/python-package/setup.py b/python-package/setup.py index 8b0c1d4..e4fd1c0 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -1,14 +1,11 @@ -import logging import multiprocessing import os +import shutil import subprocess +import sys from setuptools import find_packages, setup -# # Configure logging -logger = logging.getLogger() -logger.setLevel("DEBUG") - # Get the absolute path of setup.py setup_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) @@ -104,8 +101,8 @@ # to the root directory of the mc2 repository for easier paths in # the configuration yamls. -logger.debug("\n{:#^20}\n".format('')) -logger.debug("Configuring shell for MC2 Client...\n") +print("\n####################\n") +print("Configuring shell for MC2 Client...\n") home_path = os.path.abspath(os.path.join(setup_path, "../")) # Terminal shell initialization scripts to support @@ -146,20 +143,20 @@ def set_path(path): shell_paths_set = [set_path(path) for path in shell_paths] if not any(shell_paths_set): - logger.debug("ERROR: Failed to write to any of the following:\n") + print("ERROR: Failed to write to any of the following:\n") for path in shell_paths: - logger.debug(f"\t{path}") - logger.debug( + print(f"\t{path}") + print( "\nPlease add the following line to your shell initialization\n" "file to ensure that MC2 Client is configured automatically:\n\n" f"\texport MC2_CLIENT_HOME={home_path}" ) else: - logger.debug("Successfully modified:\n") + print("Successfully modified:\n") for (success, path) in zip(shell_paths_set, shell_paths): if success: - logger.debug(f"\t{path}") - logger.debug("\nTo run MC2 Client you may need to restart your current shell.") + print(f"\t{path}") + print("\nTo run MC2 Client you may need to restart your current shell.") env_path = os.path.join(home_path, "mc2_client_env") print(f"\nTo configure your current shell, run:\n\n\tsource {env_path}\n") From 47e70e60a203225803a3c37a757dd839ad7d28fc Mon Sep 17 00:00:00 2001 From: Pan Chasinga Date: Wed, 18 Aug 2021 06:00:41 -0700 Subject: [PATCH 3/3] Add log to test --- python-package/tests/__init__.py | 4 ++++ .../tests/azure/create_azure_resources.py | 11 ++++++----- .../tests/azure/delete_azure_resources.py | 16 +++++++++------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/python-package/tests/__init__.py b/python-package/tests/__init__.py index e69de29..d317a1f 100644 --- a/python-package/tests/__init__.py +++ b/python-package/tests/__init__.py @@ -0,0 +1,4 @@ +import logging + +test_logger = logging.getLogger("test") +test_logger.setLevel(logging.INFO) diff --git a/python-package/tests/azure/create_azure_resources.py b/python-package/tests/azure/create_azure_resources.py index 6c499de..10fa240 100644 --- a/python-package/tests/azure/create_azure_resources.py +++ b/python-package/tests/azure/create_azure_resources.py @@ -2,6 +2,7 @@ import pathlib import mc2client as mc2 +from . import test_logger as logger tests_dir = pathlib.Path(__file__).parent.absolute() config = os.path.join(tests_dir, "../test.yaml") @@ -9,17 +10,17 @@ dummy_file = os.path.join(tests_dir, "dummy.txt") -print("Creating resource group") +logger.info("Creating resource group") mc2.create_resource_group() -print("Creating storage") +logger.info("Creating storage") mc2.create_storage() -print("Creating container") +logger.info("Creating container") mc2.create_container() -print("Uploading file") +logger.info("Uploading file") mc2.upload_file(dummy_file, "dummy.txt") -print("Creating cluster") +logger.info("Creating cluster") mc2.create_cluster() diff --git a/python-package/tests/azure/delete_azure_resources.py b/python-package/tests/azure/delete_azure_resources.py index cd3c58c..39d4425 100644 --- a/python-package/tests/azure/delete_azure_resources.py +++ b/python-package/tests/azure/delete_azure_resources.py @@ -2,30 +2,32 @@ import pathlib import mc2client as mc2 +from . import test_logger as logger -print("Setting config file path") + +logger.info("Setting config file path") tests_dir = pathlib.Path(__file__).parent.absolute() config = os.path.join(tests_dir, "../test.yaml") mc2.set_config(config) download_path = os.path.join(tests_dir, "dummy_downloaded.txt") -print("Downloading file") +logger.info("Downloading file") mc2.download_file("dummy.txt", download_path) if not os.path.isfile(download_path): - print("Error: Couldn't download file from Azure") + logger.info("Error: Couldn't download file from Azure") else: os.remove(download_path) -print("Deleting container") +logger.info("Deleting container") mc2.delete_container() -print("Deleting storage") +logger.info("Deleting storage") mc2.delete_storage() -print("Deleting cluster") +logger.info("Deleting cluster") mc2.delete_cluster() -print("Deleting resource group") +logger.info("Deleting resource group") mc2.delete_resource_group()