From 4878a204878c20a153f2cdf20ed05e083ffe1936 Mon Sep 17 00:00:00 2001 From: Keith James Date: Mon, 4 Nov 2024 13:48:54 +0000 Subject: [PATCH] Add log entries for the application and CLI names Bump npg-python-lib from 0.3.1 to 0.3.3 --- requirements.txt | 2 +- src/npg_irods/__init__.py | 20 +++++++++++++++++++ src/npg_irods/cli/__init__.py | 19 ++++++++++++++++++ src/npg_irods/cli/apply_ont_metadata.py | 3 ++- src/npg_irods/cli/check_checksums.py | 3 ++- src/npg_irods/cli/check_common_metadata.py | 3 ++- src/npg_irods/cli/check_consent_withdrawn.py | 3 ++- src/npg_irods/cli/check_replicas.py | 3 ++- src/npg_irods/cli/copy_confirm.py | 3 ++- src/npg_irods/cli/locate_data_objects.py | 11 +++++++++- src/npg_irods/cli/repair_checksums.py | 3 ++- src/npg_irods/cli/repair_common_metadata.py | 3 ++- src/npg_irods/cli/repair_replicas.py | 3 ++- src/npg_irods/cli/safe_remove_script.py | 3 ++- .../cli/update_secondary_metadata.py | 3 ++- src/npg_irods/cli/withdraw_consent.py | 3 ++- src/npg_irods/cli/write_html_report.py | 3 ++- 17 files changed, 76 insertions(+), 15 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1c1fefb..c0db006 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ cryptography==43.0.3 npg_id_generation@https://github.com/wtsi-npg/npg_id_generation/releases/download/5.0.1/npg_id_generation-5.0.1.tar.gz -npg-python-lib@https://github.com/wtsi-npg/npg-python-lib/releases/download/0.3.1/npg_python_lib-0.3.1.tar.gz +npg-python-lib@https://github.com/wtsi-npg/npg-python-lib/releases/download/0.3.3/npg_python_lib-0.3.3.tar.gz partisan@https://github.com/wtsi-npg/partisan/releases/download/2.13.0/partisan-2.13.0.tar.gz pymysql==1.1.1 python-dateutil==2.9.0.post0 diff --git a/src/npg_irods/__init__.py b/src/npg_irods/__init__.py index 813f5e9..e7c8cd0 100644 --- a/src/npg_irods/__init__.py +++ b/src/npg_irods/__init__.py @@ -19,10 +19,30 @@ import importlib.metadata +import sys + +import structlog __version__ = importlib.metadata.version("npg-irods-python") +# If this proves generally useful, it could be moved to npg-python-lib +def add_appinfo_structlog_processor(): + """Add a custom structlog processor reporting executable information to the + configuration.""" + + def _add_executable_info(_logger, _method_name, event: dict): + """Add executable name and version to all log entries.""" + event["application"] = "npg-irods-python" + event["executable"] = sys.argv[0] + event["version"] = version() + return event + + c = structlog.get_config() + c["processors"] = [_add_executable_info] + c["processors"] + structlog.configure(**c) + + def version() -> str: """Return the current version.""" return __version__ diff --git a/src/npg_irods/cli/__init__.py b/src/npg_irods/cli/__init__.py index e630e89..bd09e95 100644 --- a/src/npg_irods/cli/__init__.py +++ b/src/npg_irods/cli/__init__.py @@ -1 +1,20 @@ +# -*- coding: utf-8 -*- +# +# Copyright © 2024 Genome Research Ltd. All rights reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + + """Command line interface for npg-irods-python.""" diff --git a/src/npg_irods/cli/apply_ont_metadata.py b/src/npg_irods/cli/apply_ont_metadata.py index e39519f..dadeb0d 100755 --- a/src/npg_irods/cli/apply_ont_metadata.py +++ b/src/npg_irods/cli/apply_ont_metadata.py @@ -32,7 +32,7 @@ from npg.log import configure_structlog from sqlalchemy.orm import Session -from npg_irods import db, version +from npg_irods import add_appinfo_structlog_processor, db, version from npg_irods.ont import apply_metadata description = """ @@ -76,6 +76,7 @@ colour=args.colour, json=args.json, ) +add_appinfo_structlog_processor() log = structlog.get_logger("main") diff --git a/src/npg_irods/cli/check_checksums.py b/src/npg_irods/cli/check_checksums.py index 66f451e..4a9d8af 100755 --- a/src/npg_irods/cli/check_checksums.py +++ b/src/npg_irods/cli/check_checksums.py @@ -24,7 +24,7 @@ from npg.cli import add_io_arguments, add_logging_arguments from npg.log import configure_structlog -from npg_irods import version +from npg_irods import add_appinfo_structlog_processor, version from npg_irods.utilities import check_checksums description = """ @@ -88,6 +88,7 @@ colour=args.colour, json=args.json, ) +add_appinfo_structlog_processor() log = structlog.get_logger("main") diff --git a/src/npg_irods/cli/check_common_metadata.py b/src/npg_irods/cli/check_common_metadata.py index efc1f43..3388dab 100755 --- a/src/npg_irods/cli/check_common_metadata.py +++ b/src/npg_irods/cli/check_common_metadata.py @@ -24,7 +24,7 @@ from npg.cli import add_io_arguments, add_logging_arguments from npg.log import configure_structlog -from npg_irods import version +from npg_irods import add_appinfo_structlog_processor, version from npg_irods.utilities import check_common_metadata description = """ @@ -87,6 +87,7 @@ colour=args.colour, json=args.json, ) +add_appinfo_structlog_processor() log = structlog.get_logger("main") diff --git a/src/npg_irods/cli/check_consent_withdrawn.py b/src/npg_irods/cli/check_consent_withdrawn.py index 654f5a1..5dc323c 100755 --- a/src/npg_irods/cli/check_consent_withdrawn.py +++ b/src/npg_irods/cli/check_consent_withdrawn.py @@ -24,7 +24,7 @@ from npg.cli import add_io_arguments, add_logging_arguments from npg.log import configure_structlog -from npg_irods import version +from npg_irods import add_appinfo_structlog_processor, version from npg_irods.utilities import ( check_consent_withdrawn, ) @@ -84,6 +84,7 @@ colour=args.colour, json=args.json, ) +add_appinfo_structlog_processor() log = structlog.get_logger("main") diff --git a/src/npg_irods/cli/check_replicas.py b/src/npg_irods/cli/check_replicas.py index a282a9a..c500e07 100755 --- a/src/npg_irods/cli/check_replicas.py +++ b/src/npg_irods/cli/check_replicas.py @@ -24,7 +24,7 @@ from npg.cli import add_io_arguments, add_logging_arguments from npg.log import configure_structlog -from npg_irods import version +from npg_irods import add_appinfo_structlog_processor, version from npg_irods.utilities import check_replicas description = """ @@ -96,6 +96,7 @@ colour=args.colour, json=args.json, ) +add_appinfo_structlog_processor() log = structlog.get_logger("main") diff --git a/src/npg_irods/cli/copy_confirm.py b/src/npg_irods/cli/copy_confirm.py index 72f2e65..f869710 100755 --- a/src/npg_irods/cli/copy_confirm.py +++ b/src/npg_irods/cli/copy_confirm.py @@ -25,7 +25,7 @@ from npg.log import configure_structlog from partisan.exception import RodsError -from npg_irods import version +from npg_irods import add_appinfo_structlog_processor, version from npg_irods.common import rods_path from npg_irods.exception import ChecksumError from npg_irods.utilities import copy @@ -95,6 +95,7 @@ colour=args.colour, json=args.json, ) +add_appinfo_structlog_processor() log = structlog.get_logger("main") diff --git a/src/npg_irods/cli/locate_data_objects.py b/src/npg_irods/cli/locate_data_objects.py index 0bc9858..b338921 100644 --- a/src/npg_irods/cli/locate_data_objects.py +++ b/src/npg_irods/cli/locate_data_objects.py @@ -37,7 +37,15 @@ from partisan.irods import AVU, DataObject, RodsItem, query_metadata from sqlalchemy.orm import Session -from npg_irods import db, illumina, ont, pacbio, sequenom, version +from npg_irods import ( + add_appinfo_structlog_processor, + db, + illumina, + ont, + pacbio, + sequenom, + version, +) from npg_irods.db.mlwh import ( find_consent_withdrawn_samples, @@ -770,6 +778,7 @@ def main(): colour=args.colour, json=args.json, ) + add_appinfo_structlog_processor() args.func(args) diff --git a/src/npg_irods/cli/repair_checksums.py b/src/npg_irods/cli/repair_checksums.py index ce66e0c..475dc8c 100755 --- a/src/npg_irods/cli/repair_checksums.py +++ b/src/npg_irods/cli/repair_checksums.py @@ -24,7 +24,7 @@ from npg.cli import add_io_arguments, add_logging_arguments from npg.log import configure_structlog -from npg_irods import version +from npg_irods import add_appinfo_structlog_processor, version from npg_irods.utilities import repair_checksums description = """ @@ -93,6 +93,7 @@ colour=args.colour, json=args.json, ) +add_appinfo_structlog_processor() log = structlog.get_logger("main") diff --git a/src/npg_irods/cli/repair_common_metadata.py b/src/npg_irods/cli/repair_common_metadata.py index 26560ab..10396bc 100755 --- a/src/npg_irods/cli/repair_common_metadata.py +++ b/src/npg_irods/cli/repair_common_metadata.py @@ -24,7 +24,7 @@ from npg.cli import add_io_arguments, add_logging_arguments from npg.log import configure_structlog -from npg_irods import version +from npg_irods import add_appinfo_structlog_processor, version from npg_irods.utilities import repair_common_metadata description = """ @@ -90,6 +90,7 @@ colour=args.colour, json=args.json, ) +add_appinfo_structlog_processor() log = structlog.get_logger("main") diff --git a/src/npg_irods/cli/repair_replicas.py b/src/npg_irods/cli/repair_replicas.py index 4cb8146..39c286a 100755 --- a/src/npg_irods/cli/repair_replicas.py +++ b/src/npg_irods/cli/repair_replicas.py @@ -24,7 +24,7 @@ from npg.cli import add_io_arguments, add_logging_arguments from npg.log import configure_structlog -from npg_irods import version +from npg_irods import add_appinfo_structlog_processor, version from npg_irods.utilities import repair_replicas description = """ @@ -92,6 +92,7 @@ colour=args.colour, json=args.json, ) +add_appinfo_structlog_processor() log = structlog.get_logger("main") diff --git a/src/npg_irods/cli/safe_remove_script.py b/src/npg_irods/cli/safe_remove_script.py index eab7a12..7336982 100755 --- a/src/npg_irods/cli/safe_remove_script.py +++ b/src/npg_irods/cli/safe_remove_script.py @@ -24,7 +24,7 @@ from npg.cli import add_logging_arguments from npg.log import configure_structlog -from npg_irods import version +from npg_irods import add_appinfo_structlog_processor, version from npg_irods.utilities import write_safe_remove_script description = """ @@ -84,6 +84,7 @@ colour=args.colour, json=args.json, ) +add_appinfo_structlog_processor() log = structlog.get_logger("main") diff --git a/src/npg_irods/cli/update_secondary_metadata.py b/src/npg_irods/cli/update_secondary_metadata.py index 961abfc..9633abb 100755 --- a/src/npg_irods/cli/update_secondary_metadata.py +++ b/src/npg_irods/cli/update_secondary_metadata.py @@ -26,7 +26,7 @@ from npg.conf import IniData from npg.log import configure_structlog -from npg_irods import db, version +from npg_irods import add_appinfo_structlog_processor, db, version from npg_irods.utilities import update_secondary_metadata description = """ @@ -109,6 +109,7 @@ def main(): colour=args.colour, json=args.json, ) + add_appinfo_structlog_processor() dbconfig = IniData(db.Config).from_file(args.db_config.name, "mlwh_ro") engine = sqlalchemy.create_engine( diff --git a/src/npg_irods/cli/withdraw_consent.py b/src/npg_irods/cli/withdraw_consent.py index 6235aed..4f07f33 100755 --- a/src/npg_irods/cli/withdraw_consent.py +++ b/src/npg_irods/cli/withdraw_consent.py @@ -24,7 +24,7 @@ from npg.cli import add_logging_arguments from npg.log import configure_structlog -from npg_irods import version +from npg_irods import add_appinfo_structlog_processor, version from npg_irods.utilities import ( withdraw_consent, ) @@ -89,6 +89,7 @@ colour=args.colour, json=args.json, ) +add_appinfo_structlog_processor() log = structlog.get_logger("main") diff --git a/src/npg_irods/cli/write_html_report.py b/src/npg_irods/cli/write_html_report.py index b661436..4f4e2b9 100644 --- a/src/npg_irods/cli/write_html_report.py +++ b/src/npg_irods/cli/write_html_report.py @@ -26,7 +26,7 @@ from partisan.exception import RodsError from yattag import indent -from npg_irods import version +from npg_irods import add_appinfo_structlog_processor, version from npg_irods.html_reports import ont_runs_html_report_this_year description = """Writes an HTML report summarising data in iRODS. @@ -80,6 +80,7 @@ colour=args.colour, json=args.json, ) +add_appinfo_structlog_processor() log = structlog.get_logger("main")