Coverage for gwcelery/util/resources.py: 100%
10 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-11-14 05:52 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-11-14 05:52 +0000
1"""Package data helpers."""
2import json
3from importlib import resources
5__all__ = ('read_binary', 'read_json', 'read_text')
8def read_binary(pkg, filename):
9 """Load a binary file from package data."""
10 return resources.files(pkg).joinpath(filename).read_bytes()
13def read_json(pkg, filename):
14 """Load a JSON file from package data."""
15 with resources.files(pkg).joinpath(filename).open('r') as f:
16 return json.load(f)
19def read_text(pkg, filename):
20 """Load a binary file from package data."""
21 return resources.files(pkg).joinpath(filename).read_text()