From e0b189a4c6e645264c8541e8e9514e8173e4dc28 Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Wed, 1 Nov 2023 10:03:08 -0400 Subject: [PATCH] PR feedback --- src/wags_tails/chembl.py | 14 ++------------ src/wags_tails/do.py | 16 +++------------- src/wags_tails/mondo.py | 16 ++++------------ src/wags_tails/ncit.py | 14 ++------------ src/wags_tails/oncotree.py | 19 ++----------------- src/wags_tails/utils/downloads.py | 11 ++++++----- 6 files changed, 19 insertions(+), 71 deletions(-) diff --git a/src/wags_tails/chembl.py b/src/wags_tails/chembl.py index 4f4291e..a863e9d 100644 --- a/src/wags_tails/chembl.py +++ b/src/wags_tails/chembl.py @@ -3,7 +3,6 @@ import re import tarfile from pathlib import Path -from typing import Optional import requests @@ -14,17 +13,8 @@ class ChemblData(DataSource): """Provide access to ChEMBL database.""" - def __init__(self, data_dir: Optional[Path] = None, silent: bool = False) -> None: - """Set common class parameters. - - :param data_dir: direct location to store data files in, if specified. See - ``get_data_dir()`` in the ``storage_utils`` module for further configuration - details. - :param silent: if True, don't print any info/updates to console - """ - self._src_name = "chembl" - self._filetype = "db" - super().__init__(data_dir, silent) + _src_name = "chembl" + _filetype = "db" @staticmethod def _get_latest_version() -> str: diff --git a/src/wags_tails/do.py b/src/wags_tails/do.py index 58f3340..a4a0230 100644 --- a/src/wags_tails/do.py +++ b/src/wags_tails/do.py @@ -3,7 +3,6 @@ import tarfile from datetime import datetime from pathlib import Path -from typing import Optional import requests @@ -15,18 +14,9 @@ class DoData(GitHubDataSource): """Provide access to human disease ontology data.""" - def __init__(self, data_dir: Optional[Path] = None, silent: bool = False) -> None: - """Set common class parameters. - - :param data_dir: direct location to store data files in, if specified. See - ``get_data_dir()`` in the ``storage_utils`` module for further configuration - details. - :param silent: if True, don't print any info/updates to console - """ - self._src_name = "do" - self._filetype = "owl" - self._repo = "DiseaseOntology/HumanDiseaseOntology" - super().__init__(data_dir, silent) + _src_name = "do" + _filetype = "owl" + _repo = "DiseaseOntology/HumanDiseaseOntology" @staticmethod def _asset_handler(dl_path: Path, outfile_path: Path) -> None: diff --git a/src/wags_tails/mondo.py b/src/wags_tails/mondo.py index d6e16c1..a67faf7 100644 --- a/src/wags_tails/mondo.py +++ b/src/wags_tails/mondo.py @@ -2,7 +2,7 @@ import logging from datetime import datetime from pathlib import Path -from typing import Optional, Tuple +from typing import Tuple import requests @@ -17,17 +17,9 @@ class MondoData(GitHubDataSource): """Provide access to Mondo disease ontology data.""" - def __init__(self, data_dir: Optional[Path] = None, silent: bool = False) -> None: - """Set common class parameters. - - :param data_dir: direct location to store data files in, if specified. See - ``get_data_dir()`` in the ``storage_utils`` module for further configuration - details. - :param silent: if True, don't print any info/updates to console - """ - self._src_name = "mondo" - self._repo = "monarch-initiative/mondo" - super().__init__(data_dir, silent) + _src_name = "mondo" + _filetype = "owl" + _repo = "monarch-initiative/mondo" @staticmethod def _get_latest_version() -> Tuple[str, str]: diff --git a/src/wags_tails/ncit.py b/src/wags_tails/ncit.py index a170de4..e9ad9ea 100644 --- a/src/wags_tails/ncit.py +++ b/src/wags_tails/ncit.py @@ -1,7 +1,6 @@ """Provide source fetching for NCI Thesaurus.""" import re from pathlib import Path -from typing import Optional import requests @@ -12,17 +11,8 @@ class NcitData(DataSource): """Provide access to NCI Thesaurus database.""" - def __init__(self, data_dir: Optional[Path] = None, silent: bool = False) -> None: - """Set common class parameters. - - :param data_dir: direct location to store data files in, if specified. See - ``get_data_dir()`` in the ``storage_utils`` module for further configuration - details. - :param silent: if True, don't print any info/updates to console - """ - self._src_name = "ncit" - self._filetype = "owl" - super().__init__(data_dir, silent) + _src_name = "ncit" + _filetype = "owl" @staticmethod def _get_latest_version() -> str: diff --git a/src/wags_tails/oncotree.py b/src/wags_tails/oncotree.py index a5dc835..d3eb454 100644 --- a/src/wags_tails/oncotree.py +++ b/src/wags_tails/oncotree.py @@ -1,8 +1,6 @@ """Provide access to Oncotree data.""" -import logging from datetime import datetime from pathlib import Path -from typing import Optional import requests @@ -10,25 +8,12 @@ from .utils.downloads import download_http from .utils.versioning import DATE_VERSION_PATTERN -_logger = logging.getLogger(__name__) - class OncoTreeData(DataSource): """Provide access to OncoTree data.""" - def __init__(self, data_dir: Optional[Path] = None, silent: bool = False) -> None: - """Set common class parameters. - - :param data_dir: direct location to store data files in. If not provided, tries - to find a "oncotree" subdirectory within the path at environment variable - $WAGS_TAILS_DIR, or within a "wags_tails" subdirectory under environment - variables $XDG_DATA_HOME or $XDG_DATA_DIRS, or finally, at - ``~/.local/share/`` - :param silent: if True, don't print any info/updates to console - """ - self._src_name = "oncotree" - self._filetype = "json" - super().__init__(data_dir, silent) + _src_name = "oncotree" + _filetype = "json" def _get_latest_version(self) -> str: """Retrieve latest version value diff --git a/src/wags_tails/utils/downloads.py b/src/wags_tails/utils/downloads.py index 068bb0f..23b167d 100644 --- a/src/wags_tails/utils/downloads.py +++ b/src/wags_tails/utils/downloads.py @@ -17,8 +17,8 @@ def handle_zip(dl_path: Path, outfile_path: Path) -> None: """Provide simple callback function to extract the largest file within a given zipfile and save it within the appropriate data directory. - :param Path dl_path: path to temp data file - :param Path outfile_path: path to save file within + :param dl_path: path to temp data file + :param outfile_path: path to save file within """ with zipfile.ZipFile(dl_path, "r") as zip_ref: if len(zip_ref.filelist) > 1: @@ -46,6 +46,7 @@ def download_http( :param headers: Any needed HTTP headers to include in request :param handler: provide if downloaded file requires additional action, e.g. it's a zip file. + :param tqdm_params: Optional TQDM configuration. """ if not tqdm_params: tqdm_params = {} @@ -60,12 +61,12 @@ def download_http( total_size = int(r.headers.get("content-length", 0)) with open(dl_path, "wb") as h: if not tqdm_params["disable"]: - if "apiKey" in url: + if "apiKey" in url: # don't print RxNorm API key pattern = r"&apiKey=.{8}-.{4}-.{4}-.{4}-.{12}" print_url = re.sub(pattern, "", os.path.basename(url)) - print(f"Downloading {print_url}") + print(f"Downloading {print_url}...") else: - print(f"Downloading {os.path.basename(url)}") + print(f"Downloading {os.path.basename(url)}...") with tqdm( total=total_size, **tqdm_params,