Skip to content

Commit 6826faf

Browse files
committed
Move pooch import into Registry
1 parent 300c26a commit 6826faf

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/ess/reduce/data.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)
3-
import pooch
43

54

65
class Registry:
7-
def __init__(self, instrument: str, files: dict[str, str], version: str):
6+
"""A registry for data files.
7+
8+
Note
9+
----
10+
This class requires [Pooch](https://www.fatiando.org/pooch/latest/) which
11+
is not a hard dependency of ESSreduce and needs to be installed separately.
12+
"""
13+
14+
def __init__(self, instrument: str, files: dict[str, str], version: str) -> None:
15+
import pooch
16+
817
self._registry = pooch.create(
918
path=pooch.os_cache(f'ess/{instrument}'),
1019
env=f'ESS_{instrument.upper()}_DATA_DIR',
@@ -14,8 +23,10 @@ def __init__(self, instrument: str, files: dict[str, str], version: str):
1423
registry=files,
1524
retry_if_failed=3,
1625
)
26+
self._unzip_processor = pooch.Unzip()
1727

18-
def __contains__(self, key):
28+
def __contains__(self, key: str) -> bool:
29+
"""Return True if the key is in the registry."""
1930
return key in self._registry.registry
2031

2132
def get_path(self, name: str, unzip: bool = False) -> str:
@@ -28,8 +39,15 @@ def get_path(self, name: str, unzip: bool = False) -> str:
2839
Name of the file to get the path for.
2940
unzip:
3041
If `True`, unzip the file before returning the path.
42+
43+
Returns
44+
-------
45+
:
46+
The Path to the file.
3147
"""
32-
return self._registry.fetch(name, processor=pooch.Unzip() if unzip else None)
48+
return self._registry.fetch(
49+
name, processor=self._unzip_processor if unzip else None
50+
)
3351

3452

3553
_bifrost_registry = Registry(

0 commit comments

Comments
 (0)