Skip to content

Commit

Permalink
more things
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson committed Oct 27, 2023
1 parent 3a5f7bd commit 510f19b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/wags_tails/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Data acquisition tools for Wagnerds."""
from .base_source import DataSource
from .chembl import ChemblData
from .chemidplus import ChemIDplusData
from .custom import CustomData
Expand All @@ -7,9 +8,11 @@
from .guide_to_pharmacology import GToPLigandData
from .hemonc import HemOncData
from .mondo import MondoData
from .ncit import NcitData
from .rxnorm import RxNormData

__all__ = [
"DataSource",
"ChemblData",
"ChemIDplusData",
"CustomData",
Expand All @@ -18,5 +21,6 @@
"GToPLigandData",
"HemOncData",
"MondoData",
"NcitData",
"RxNormData",
]
12 changes: 9 additions & 3 deletions src/wags_tails/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(
latest_version_cb: Callable[[], str],
download_cb: Callable[[Path, str], None],
data_dir: Optional[Path] = None,
file_name: Optional[str] = None,
silent: bool = False,
) -> None:
"""Set common class parameters.
Expand All @@ -41,12 +42,17 @@ def __init__(
$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 file_name: name to use for base of filename if given
:param silent: if True, don't print any info/updates to console
"""
self._src_name = src_name
self._file_suffix = file_suffix
self._get_latest_version = latest_version_cb
self._download_data = download_cb
if file_name:
self._file_name = file_name
else:
self._file_name = src_name
super().__init__(data_dir, silent)

def get_latest(
Expand All @@ -65,15 +71,15 @@ def get_latest(

if from_local:
file_path = self._get_latest_local_file(
f"{self._src_name}_*.{self._file_suffix}"
f"{self._file_name}_*.{self._file_suffix}"
)
return file_path, parse_file_version(
file_path, f"{self._src_name}_(\\d+).{self._file_suffix}"
file_path, f"{self._file_name}_(\\d+).{self._file_suffix}"
)

latest_version = self._get_latest_version()
latest_file = (
self._data_dir / f"{self._src_name}_{latest_version}.{self._file_suffix}"
self._data_dir / f"{self._file_name}_{latest_version}.{self._file_suffix}"
)
if (not force_refresh) and latest_file.exists():
_logger.debug(
Expand Down

0 comments on commit 510f19b

Please sign in to comment.