diff --git a/CHANGELOG.md b/CHANGELOG.md index 18966b1..0f3c3de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,13 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Removed + +* Config file reader code that can be reused if it's not tied to the multitude + of dependencies in this package + ## [0.1.0] - 2024-07-24 ### Added -# Initial project scaffold, code and tests +* Initial project scaffold, code and tests diff --git a/pyproject.toml b/pyproject.toml index 774e780..7206402 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ SQLAlchemy = { version="^2.0.1", extras=["pymysql"] } SQLAlchemy-Utils = "^0.41.2" cryptography = "^44.0.0" PyYAML = "^6.0.0" -npg_porch_cli = { git="https://github.com/wtsi-npg/npg_porch_cli.git", tag="0.1.0" } +npg_porch_cli = { git="https://github.com/wtsi-npg/npg_porch_cli.git", tag="0.2.0" } partisan = { url = "https://github.com/wtsi-npg/partisan/releases/download/2.13.0/partisan-2.13.0.tar.gz" } npg-python-lib = { url = "https://github.com/wtsi-npg/npg-python-lib/releases/download/0.3.4/npg_python_lib-0.3.4.tar.gz" } requests = "^2.32.0" diff --git a/src/npg_notify/config.py b/src/npg_notify/config.py deleted file mode 100644 index b079e30..0000000 --- a/src/npg_notify/config.py +++ /dev/null @@ -1,75 +0,0 @@ -import configparser -import json -import pathlib - -"""Common utility functions for the package.""" - -DEFAULT_CONF_FILE_TYPE = "ini" - - -def get_config_data(conf_file_path: str, conf_file_section: str = None): - """ - Parses a configuration file and returns its content. - - Allows for two types of configuration files, 'ini' and 'json'. The type of - the file is determined from the extension of the file name. In case of no - extension an 'ini' type is assumed. - - The content of the file is not cached, so subsequent calls to get data from - the same configuration file result in re-reading and re-parsing of the file. - - Args: - - conf_file_path: - A configuration file with database connection details. - conf_file_section: - The section of the configuration file. Optional. Should be defined - for 'ini' files. - - Returns: - For an 'ini' file returns the content of the given section of the file as - a dictionary. - For a 'json' file, if the conf_file_section argument is not defined, the - content of a file as a Python object is returned. If the conf_file_section - argument is defined, the object returned by the parser is assumed to be - a dictionary that has the value of the 'conf_file_section' argument as a key. - The value corresponding to this key is returned. - """ - - conf_file_extension = pathlib.Path(conf_file_path).suffix - if conf_file_extension: - conf_file_extension = conf_file_extension[1:] - else: - conf_file_extension = DEFAULT_CONF_FILE_TYPE - - if conf_file_extension == DEFAULT_CONF_FILE_TYPE: - if not conf_file_section: - raise Exception( - "'conf_file_section' argument is not given, " - "it should be defined for '{DEFAULT_CONF_FILE_TYPE}' " - "configuration file." - ) - - config = configparser.ConfigParser() - config.read(conf_file_path) - - return {i[0]: i[1] for i in config[conf_file_section].items()} - - elif conf_file_extension == "json": - conf: dict = json.load(conf_file_path) - if conf_file_section: - if isinstance(conf, dict) is False: - raise Exception(f"{conf_file_path} does not have sections.") - if conf_file_section in conf.keys: - conf = conf[conf_file_section] - else: - raise Exception( - f"{conf_file_path} does not contain {conf_file_section} key" - ) - - return conf - - else: - raise Exception( - f"Parsing for '{conf_file_extension}' files is not implemented" - ) diff --git a/src/npg_notify/db/utils.py b/src/npg_notify/db/utils.py index a87d8d8..7a76ddb 100644 --- a/src/npg_notify/db/utils.py +++ b/src/npg_notify/db/utils.py @@ -10,7 +10,7 @@ from sqlalchemy.orm import DeclarativeBase, Session from sqlalchemy_utils import create_database, database_exists, drop_database -from npg_notify.config import get_config_data +from npg_porch_cli.config import get_config_data def get_db_connection_string( diff --git a/src/npg_notify/porch_wrapper/qc_state.py b/src/npg_notify/porch_wrapper/qc_state.py index 041e4b2..3db795d 100644 --- a/src/npg_notify/porch_wrapper/qc_state.py +++ b/src/npg_notify/porch_wrapper/qc_state.py @@ -7,11 +7,11 @@ from pathlib import PurePath from urllib.parse import urljoin -from npg_notify.config import get_config_data from npg_notify.db.mlwh import get_study_contacts from npg_notify.db.utils import get_connection, get_db_connection_string from npg_notify.mail import generate_email_pac_bio, send_notification from npg_porch_cli import send_request +from npg_porch_cli.config import get_config_data from npg_porch_cli.api import Pipeline, PorchAction from npg_porch_cli.api import send as send_porch_request