import os
import libpyhat
base = os.path.split(libpyhat.__file__)[0]
data_dir = os.path.join(base, "data_sets")
dirs = next(os.walk(data_dir))[1]
file_2_dir = {}
for d in dirs:
tmp = os.path.join(data_dir, d)
file_in_tmp = os.listdir(tmp)
for f in file_in_tmp:
file_2_dir[f] = tmp
[docs]
def get_path(dataset_name): # pragma: no cover
"""
Get the path of the example file
Parameters
==========
dataset_name : str
The name of the example file to return the absolute path
"""
if not isinstance(dataset_name, str):
try:
dataset_name = str(dataset_name)
except:
raise KeyError("Cannot coerce requested example name to string")
if dataset_name in dirs:
return os.path.join(data_dir, dataset_name)
elif dataset_name in file_2_dir:
d = file_2_dir[dataset_name]
return os.path.join(d, dataset_name)
elif dataset_name == "":
return os.path.join(base, "data_sets", dataset_name)
else:
print("Example directories:")
print(dirs)
print("Available examples:")
print(file_2_dir)
raise KeyError(dataset_name + " not found in built-in examples")