Skip to content

Commit

Permalink
Work with importlib_resources 1.3 released an hour ago (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii authored Mar 6, 2020
1 parent 6d19da5 commit 9a0f6cc
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/skhep_testdata/local_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
# 3.9's importlib.resources. Let's be sure to use the package for now:
import importlib_resources

try:
from importlib_resources import as_file
except ImportError:
from importlib_resources.trees import as_file

try:
from contextlib import ExitStack
except ImportError:
Expand All @@ -23,7 +28,7 @@ def data_path(filename, raise_missing=True):
ref = importlib_resources.files("skhep_testdata.data") / filename
file_manager = ExitStack()
atexit.register(file_manager.close)
file_path = file_manager.enter_context(importlib_resources.trees.as_file(ref))
file_path = file_manager.enter_context(as_file(ref))
if raise_missing and not file_path.exists():
raise RuntimeError("Unknown or missing file: {0}".format(filename))
return str(file_path)

0 comments on commit 9a0f6cc

Please sign in to comment.