Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
__init__.py
Go to the documentation of this file.
1import atexit
2import sys
3
4if sys.version_info < (3, 9):
5 import importlib_resources
6 try:
7 from importlib_resources import as_file
8 except ImportError:
9 from importlib_resources.trees import as_file
10else:
11 import importlib.resources as importlib_resources
12 from importlib.resources import as_file
13
14try:
15 from contextlib import ExitStack
16except ImportError:
17 from contextlib2 import ExitStack
18
19if sys.version_info < (3, 8):
20 from importlib_metadata import distribution
21else:
22 from importlib.metadata import distribution
23
24version = distribution(__name__).version
25__version__ = version
26
27LATEST_VERSIONS = {
28 "detx": "detx/detx_v3.detx",
29}
30
31
32def data_path(filename, raise_missing=True):
33 """Return the absolute filepath for a given filename in test data"""
34 ref = importlib_resources.files("km3net_testdata.data") / filename
35 file_manager = ExitStack()
36 atexit.register(file_manager.close)
37 file_path = file_manager.enter_context(as_file(ref))
38 if raise_missing and not file_path.exists():
39 raise RuntimeError("Unknown or missing file: {0}".format(filename))
40 return str(file_path)
41
42
43def latest(dataformat, raise_missing=True):
44 """Return the path to the latest version of the given dataformat"""
45 filename = LATEST_VERSIONS.get(dataformat, "latest." + dataformat)
46 return data_path(filename, raise_missing=raise_missing)
47
48
49__all__ = ["data_path"]
data_path(filename, raise_missing=True)
Definition __init__.py:32
latest(dataformat, raise_missing=True)
Definition __init__.py:43