Skip to content

Commit

Permalink
Fixed absolute path handling and api key error messaging.
Browse files Browse the repository at this point in the history
  • Loading branch information
TJohnsonAZ committed Jan 31, 2024
1 parent 5bbefd9 commit c97bd3b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
12 changes: 4 additions & 8 deletions epymorph/cli/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ def define_argparser(command_parser: _SubParsersAction):
'geo',
type=str,
help='the name of the geo to fetch; must include a geo path if not already in the library')
fetch_command.add_argument(
'-p', '--path',
help='(optional) the path to a geo spec file not in the library'
)
fetch_command.add_argument(
'-f', '--force',
action='store_true',
Expand Down Expand Up @@ -79,11 +75,11 @@ def fetch(geo_name_or_path: str, force: bool) -> int:
if geo_name_or_path in geo_library_dynamic:
geo_name = geo_name_or_path
geo_path = None
elif os.path.exists(Path(geo_name_or_path)):
geo_path = Path(geo_name_or_path)
geo_name = geo_path.name.split('.')[0]
elif os.path.exists(Path(geo_name_or_path).expanduser()):
geo_path = Path(geo_name_or_path).expanduser()
geo_name = geo_path.stem
else:
return 1 # exit code: geo not found
raise cache.GeoCacheException("Specified geo not found.")

# cache geo according to information passed
filepath = cache.CACHE_PATH / F.to_archive_filename(geo_name)
Expand Down
14 changes: 9 additions & 5 deletions epymorph/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,23 @@ def load_model_geo(name_or_path: str, ignore_cache: bool) -> Geo:
if name_or_path in geo_library:
return geo_library[name_or_path]()

path = Path(name_or_path)
path = Path(name_or_path).expanduser()
if not path.exists():
raise UnknownModel('GEO', name_or_path)

# check for non-library geo cached
cached = load_from_cache(path.name.split('.')[0])
if cached is not None:
return cached
if not ignore_cache:
cached = load_from_cache(path.stem)
if cached is not None:
return cached

if path.suffix == ".geo":
return DynamicGeoFileOps.load_from_spec(path, adrio_maker_library)
else:
elif path.suffix == ".tar":
return StaticGeoFileOps.load_from_archive(path)
else:
msg = "Invalid file type. A geo can only be loaded from a .geo or .geo.tar file."
raise Exception(msg)


@load_messaging("IPM")
Expand Down
4 changes: 2 additions & 2 deletions epymorph/geo/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def fetch(geo_name_or_path: str) -> None:

# checks for geo spec at given path (path passed)
else:
geo_path = Path(geo_name_or_path)
geo_path = Path(geo_name_or_path).expanduser()
if os.path.exists(geo_path):
geo_name = geo_path.name.split('.')[0]
geo_name = geo_path.stem
filepath = CACHE_PATH / F.to_archive_filename(geo_name)
geo = DF.load_from_spec(geo_path, adrio_maker_library)
static_geo = convert_to_static_geo(geo)
Expand Down
3 changes: 2 additions & 1 deletion epymorph/geo/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,5 @@ def load_from_spec(file: os.PathLike, adrio_maker_library: ADRIOMakerLibrary) ->
spec = DynamicGeoSpec.deserialize(spec_json)
return DynamicGeo.from_library(spec, adrio_maker_library)
except Exception as e:
raise GeoValidationException(f"Unable to load '{file}' as a geo.") from e
msg = f"Unable to load '{file}' as a geo: {e}"
raise GeoValidationException(msg) from e

0 comments on commit c97bd3b

Please sign in to comment.