Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added function to reset the Catalog paths #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions model_catalogs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,38 @@
# this is where the original model catalog files and previously-calculated
# model boundaries can be found, which are hard-wired in the repo
# version change for this behavior
try: # >= Python 3.9
CAT_PATH = importlib.resources.files("model_catalogs") / "catalogs"
except AttributeError: # < Python3.9
with importlib.resources.path("model_catalogs", "catalogs") as pth:
CAT_PATH = pth
CAT_PATH_ORIG = CAT_PATH / "orig"
CAT_PATH_BOUNDARIES = CAT_PATH / "boundaries"
CAT_PATH_TRANSFORM = CAT_PATH / "transform.yaml"
def set_cat_paths(cat_path=None):
'''
set the paths for the catalog (yml files)

:param cat_path: path to the source catalog

NOTE: These three paths need to exist, as do:
cat_path
cat_path/orig
cat_path/boundaries
'''
# fixme: global's not ideal -- better to have a mutable config object:
# maybe a dict or dataclass
global CAT_PATH
global CAT_PATH_ORIG
global CAT_PATH_BOUNDARIES
global CAT_PATH_TRANSFORM

if cat_path is None:
try: # >= Python 3.9
CAT_PATH = importlib.resources.files("model_catalogs") / "catalogs"
except AttributeError: # < Python3.9
with importlib.resources.path("model_catalogs", "catalogs") as pth:
CAT_PATH = pth
else:
CAT_PATH = Path(cat_path)

CAT_PATH_ORIG = CAT_PATH / "orig"
CAT_PATH_BOUNDARIES = CAT_PATH / "boundaries"
CAT_PATH_TRANSFORM = CAT_PATH / "transform.yaml"

set_cat_paths()

# test files
try: # >= Python 3.9
Expand Down