From 92e740bf4d8c94b122b76ede81c8a093e8a3c305 Mon Sep 17 00:00:00 2001 From: Alicja Polanska Date: Thu, 26 Sep 2024 14:56:20 +0100 Subject: [PATCH 1/9] Remove unused import. --- harmonic/logs.py | 64 +++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/harmonic/logs.py b/harmonic/logs.py index 4f31d962..71c4b7c2 100644 --- a/harmonic/logs.py +++ b/harmonic/logs.py @@ -3,13 +3,13 @@ import logging import yaml import harmonic -import colorlog + def setup_logging(custom_yaml_path=None, default_level=logging.DEBUG): """initialise and configure logging. - - Should be called at the beginning of code to initialise and configure the - desired logging level. Logging levels can be ints in [0,50] where 10 is + + Should be called at the beginning of code to initialise and configure the + desired logging level. Logging levels can be ints in [0,50] where 10 is debug logging and 50 is critical logging. Args: @@ -25,34 +25,40 @@ def setup_logging(custom_yaml_path=None, default_level=logging.DEBUG): """ if custom_yaml_path == None: - path = os.path.join(os.path.dirname(os.path.dirname( - os.path.realpath(harmonic.__file__))) + '/logs/logging.yaml') + path = os.path.join( + os.path.dirname(os.path.dirname(os.path.realpath(harmonic.__file__))) + + "/logs/logging.yaml" + ) if custom_yaml_path != None: path = custom_yaml_path - value = os.getenv('LOG_CFG', None) + value = os.getenv("LOG_CFG", None) if value: path = value if os.path.exists(path): - with open(path, 'rt') as f: + with open(path, "rt") as f: config = yaml.safe_load(f.read()) if custom_yaml_path == None: - config['handlers']['info_file_handler']['filename'] = os.path.join( - os.path.dirname(os.path.dirname( - os.path.realpath(harmonic.__file__))) + '/logs/info.log') - config['handlers']['debug_file_handler']['filename'] = os.path.join( - os.path.dirname(os.path.dirname( - os.path.realpath(harmonic.__file__))) + '/logs/debug.log') - config['handlers']['critical_file_handler']['filename'] = os.path.join( - os.path.dirname(os.path.dirname( - os.path.realpath(harmonic.__file__))) + '/logs/critical.log') - config['handlers']['info_file_handler']['filename'] = os.path.join( - os.path.dirname(os.path.dirname( - os.path.realpath(harmonic.__file__))) + '/logs/info.log') + config["handlers"]["info_file_handler"]["filename"] = os.path.join( + os.path.dirname(os.path.dirname(os.path.realpath(harmonic.__file__))) + + "/logs/info.log" + ) + config["handlers"]["debug_file_handler"]["filename"] = os.path.join( + os.path.dirname(os.path.dirname(os.path.realpath(harmonic.__file__))) + + "/logs/debug.log" + ) + config["handlers"]["critical_file_handler"]["filename"] = os.path.join( + os.path.dirname(os.path.dirname(os.path.realpath(harmonic.__file__))) + + "/logs/critical.log" + ) + config["handlers"]["info_file_handler"]["filename"] = os.path.join( + os.path.dirname(os.path.dirname(os.path.realpath(harmonic.__file__))) + + "/logs/info.log" + ) logging.config.dictConfig(config) else: logging.basicConfig(level=default_level) raise ValueError("Logging config pathway incorrect.") - critical_log('Using custom config from {}'.format(path)) + critical_log("Using custom config from {}".format(path)) def debug_log(message): @@ -63,11 +69,12 @@ def debug_log(message): message: Message to log. """ - logger = logging.getLogger('Harmonic') + logger = logging.getLogger("Harmonic") logger.debug(message) + def warning_log(message): - """Log a warning (e.g. for internal code warnings such as large dynamic + """Log a warning (e.g. for internal code warnings such as large dynamic ranges). Args: @@ -75,9 +82,10 @@ def warning_log(message): message: Warning to log. """ - logger = logging.getLogger('Harmonic') + logger = logging.getLogger("Harmonic") logger.warning(message) + def critical_log(message): """Log a critical message (e.g. core code failures etc). @@ -86,11 +94,12 @@ def critical_log(message): message: Message to log. """ - logger = logging.getLogger('Harmonic') + logger = logging.getLogger("Harmonic") logger.critical(message) + def info_log(message): - """Log an information message (e.g. evidence value printing, run completion + """Log an information message (e.g. evidence value printing, run completion etc). Args: @@ -98,6 +107,5 @@ def info_log(message): message: Message to log. """ - logger = logging.getLogger('Harmonic') + logger = logging.getLogger("Harmonic") logger.info(message) - From 27a09a8449164d1560cfd9f5f48f2b94861f594a Mon Sep 17 00:00:00 2001 From: Alicja Polanska Date: Thu, 26 Sep 2024 15:05:12 +0100 Subject: [PATCH 2/9] Change and move logging file. --- logs/logging.yaml => default-logging-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename logs/logging.yaml => default-logging-config.yaml (89%) diff --git a/logs/logging.yaml b/default-logging-config.yaml similarity index 89% rename from logs/logging.yaml rename to default-logging-config.yaml index 0ddc30e1..c71b0227 100644 --- a/logs/logging.yaml +++ b/default-logging-config.yaml @@ -1,5 +1,5 @@ # ================================================== -# Logging setup for Harmonic Software package (2018) +# Logging setup for Harmonic Software package (2024) # ================================================== version: 1 @@ -29,21 +29,21 @@ handlers: class: logging.FileHandler level: INFO formatter: simple - filename: /logs/info.log + filename: info.log encoding: utf8 debug_file_handler: class: logging.FileHandler level: DEBUG formatter: simple - filename: /logs/debug.log + filename: debug.log encoding: utf8 critical_file_handler: class: logging.FileHandler level: CRITICAL formatter: simple - filename: /logs/critical.log + filename: critical.log encoding: utf8 loggers: From 17db679d11986a2c406df7a3c7735b5a003b99d5 Mon Sep 17 00:00:00 2001 From: Alicja Polanska Date: Thu, 26 Sep 2024 15:05:36 +0100 Subject: [PATCH 3/9] Update logging setup --- harmonic/logs.py | 49 +++++++++++++++--------------------------------- 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/harmonic/logs.py b/harmonic/logs.py index 71c4b7c2..87d3fcde 100644 --- a/harmonic/logs.py +++ b/harmonic/logs.py @@ -1,6 +1,7 @@ import os import logging.config import logging +from pathlib import Path import yaml import harmonic @@ -24,41 +25,21 @@ def setup_logging(custom_yaml_path=None, default_level=logging.DEBUG): ValueError: Raised if logging.yaml is not in ./logs/ directory. """ - if custom_yaml_path == None: - path = os.path.join( - os.path.dirname(os.path.dirname(os.path.realpath(harmonic.__file__))) - + "/logs/logging.yaml" - ) - if custom_yaml_path != None: - path = custom_yaml_path - value = os.getenv("LOG_CFG", None) - if value: - path = value - if os.path.exists(path): - with open(path, "rt") as f: - config = yaml.safe_load(f.read()) - if custom_yaml_path == None: - config["handlers"]["info_file_handler"]["filename"] = os.path.join( - os.path.dirname(os.path.dirname(os.path.realpath(harmonic.__file__))) - + "/logs/info.log" - ) - config["handlers"]["debug_file_handler"]["filename"] = os.path.join( - os.path.dirname(os.path.dirname(os.path.realpath(harmonic.__file__))) - + "/logs/debug.log" - ) - config["handlers"]["critical_file_handler"]["filename"] = os.path.join( - os.path.dirname(os.path.dirname(os.path.realpath(harmonic.__file__))) - + "/logs/critical.log" - ) - config["handlers"]["info_file_handler"]["filename"] = os.path.join( - os.path.dirname(os.path.dirname(os.path.realpath(harmonic.__file__))) - + "/logs/info.log" - ) - logging.config.dictConfig(config) + if "LOG_CFG" in os.environ: + path = Path(os.environ["LOG_CFG"]) + elif custom_yaml_path is None: + path = Path(harmonic.__file__).parent / "default-logging-config.yaml" else: - logging.basicConfig(level=default_level) - raise ValueError("Logging config pathway incorrect.") - critical_log("Using custom config from {}".format(path)) + path = Path(custom_yaml_path) + if not path.exists(): + raise ValueError(f"Logging config path {path} does not exist.") + with open(path, "rt") as f: + config = yaml.safe_load(f.read()) + if custom_yaml_path is None: + config["handlers"]["info_file_handler"]["filename"] = "info.log" + config["handlers"]["debug_file_handler"]["filename"] = "debug.log" + config["handlers"]["critical_file_handler"]["filename"] = "critical.log" + logging.config.dictConfig(config) def debug_log(message): From cade6756906d46977ea21f1089f92130aab3c40d Mon Sep 17 00:00:00 2001 From: Alicja Polanska Date: Thu, 26 Sep 2024 15:22:00 +0100 Subject: [PATCH 4/9] Move logging to harmonic --- default-logging-config.yaml | 58 ------------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 default-logging-config.yaml diff --git a/default-logging-config.yaml b/default-logging-config.yaml deleted file mode 100644 index c71b0227..00000000 --- a/default-logging-config.yaml +++ /dev/null @@ -1,58 +0,0 @@ -# ================================================== -# Logging setup for Harmonic Software package (2024) -# ================================================== - -version: 1 -disable_existing_loggers: False -formatters: - simple: - format: "[%(asctime)s] [%(name)s] [%(levelname)s]: %(message)s" - colored: - (): "colorlog.ColoredFormatter" - datefmt: "%Y-%m-%d %H:%M:%S" - format: "%(log_color)s[%(asctime)s] [%(name)s] [%(levelname)s]: %(message)s%(reset)s" - log_colors: - DEBUG: blue - INFO: cyan - WARNING: purple - ERROR: orange - CRITICAL: red - -handlers: - console: - class: logging.StreamHandler - level: INFO - formatter: colored - stream: ext://sys.stdout - - info_file_handler: - class: logging.FileHandler - level: INFO - formatter: simple - filename: info.log - encoding: utf8 - - debug_file_handler: - class: logging.FileHandler - level: DEBUG - formatter: simple - filename: debug.log - encoding: utf8 - - critical_file_handler: - class: logging.FileHandler - level: CRITICAL - formatter: simple - filename: critical.log - encoding: utf8 - -loggers: - Harmonic: - level: DEBUG - handlers: [console, critical_file_handler, info_file_handler, debug_file_handler] - propagate: no - -root: - level: INFO - handlers: [console, info_file_handler, debug_file_handler] -... \ No newline at end of file From 6613489a83f04c00a0288be7dfc3874a6a675080 Mon Sep 17 00:00:00 2001 From: Alicja Polanska Date: Thu, 26 Sep 2024 15:24:23 +0100 Subject: [PATCH 5/9] Move logging file --- harmonic/default-logging-config.yaml | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 harmonic/default-logging-config.yaml diff --git a/harmonic/default-logging-config.yaml b/harmonic/default-logging-config.yaml new file mode 100644 index 00000000..c71b0227 --- /dev/null +++ b/harmonic/default-logging-config.yaml @@ -0,0 +1,58 @@ +# ================================================== +# Logging setup for Harmonic Software package (2024) +# ================================================== + +version: 1 +disable_existing_loggers: False +formatters: + simple: + format: "[%(asctime)s] [%(name)s] [%(levelname)s]: %(message)s" + colored: + (): "colorlog.ColoredFormatter" + datefmt: "%Y-%m-%d %H:%M:%S" + format: "%(log_color)s[%(asctime)s] [%(name)s] [%(levelname)s]: %(message)s%(reset)s" + log_colors: + DEBUG: blue + INFO: cyan + WARNING: purple + ERROR: orange + CRITICAL: red + +handlers: + console: + class: logging.StreamHandler + level: INFO + formatter: colored + stream: ext://sys.stdout + + info_file_handler: + class: logging.FileHandler + level: INFO + formatter: simple + filename: info.log + encoding: utf8 + + debug_file_handler: + class: logging.FileHandler + level: DEBUG + formatter: simple + filename: debug.log + encoding: utf8 + + critical_file_handler: + class: logging.FileHandler + level: CRITICAL + formatter: simple + filename: critical.log + encoding: utf8 + +loggers: + Harmonic: + level: DEBUG + handlers: [console, critical_file_handler, info_file_handler, debug_file_handler] + propagate: no + +root: + level: INFO + handlers: [console, info_file_handler, debug_file_handler] +... \ No newline at end of file From 86d870261a211f8e1d518d6db1db49d402e5f2f1 Mon Sep 17 00:00:00 2001 From: Alicja Polanska Date: Thu, 26 Sep 2024 15:24:38 +0100 Subject: [PATCH 6/9] Unpin numpy and cython versions --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 197ae6e4..2559e031 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["setuptools", "wheel", "numpy==1.23.1", "Cython==0.29.30"] +requires = ["setuptools", "wheel", "numpy", "Cython"] build-backend = "setuptools.build_meta" \ No newline at end of file From cafd90e0a4a6fb66a2ba9c3776e30e8c09e55f9b Mon Sep 17 00:00:00 2001 From: Alicja Polanska Date: Thu, 26 Sep 2024 15:24:56 +0100 Subject: [PATCH 7/9] Change logging setup --- setup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 449bf9f3..9fa686a2 100644 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ def read_file(file): "Intended Audience :: Science/Research", ], name="harmonic", - version="1.2.2", + version="1.2.3", prefix=".", url="https://github.com/astro-informatics/harmonic", author="Jason D. McEwen, Alicja Polanska, Christopher G. R. Wallis, Matthew A. Price, Matthew M. Docherty & Contributors", @@ -59,6 +59,8 @@ def read_file(file): long_description_content_type="text/x-rst", long_description=long_description, packages=["harmonic"], + include_package_data=True, + package_data={"harmonic": ["default-logging-config.yaml"]}, cmdclass={"build_ext": build_ext}, ext_modules=cythonize( [ From 25b88977d0ca52a5d0013c2edcf963f29dc8e90b Mon Sep 17 00:00:00 2001 From: alicjapolanska Date: Thu, 26 Sep 2024 15:33:27 +0100 Subject: [PATCH 8/9] Remove unused imports. --- setup.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup.py b/setup.py index 9fa686a2..ee13723e 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,5 @@ -import sys import os import shutil -import setuptools from setuptools import setup, Extension from Cython.Distutils import build_ext from Cython.Build import cythonize From 4040adae46b7b09ecd995669cca01b8c0203534a Mon Sep 17 00:00:00 2001 From: alicjapolanska Date: Thu, 26 Sep 2024 15:43:28 +0100 Subject: [PATCH 9/9] Increment version. --- docs/conf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index e26cc2c3..f29e6369 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,9 +25,9 @@ author = "Jason D. McEwen, Christopher G. R. Wallis, Matthew A. Price, Matthew M. Docherty, Alicja Polanska" # The short X.Y version -version = "1.2.2" +version = "1.2.3" # The full version, including alpha/beta/rc tags -release = "1.2.2" +release = "1.2.3" # -- General configuration ---------------------------------------------------