Skip to content

Commit

Permalink
Rebase cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TJohnsonAZ committed Feb 2, 2024
1 parent 7a071ff commit 6201250
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 56 deletions.
17 changes: 0 additions & 17 deletions epymorph/cli/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,16 @@ 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')
<<<<<<< HEAD
=======
fetch_command.add_argument(
'-p', '--path',
help='(optional) the path to a geo spec file not in the library'
)
>>>>>>> 02fcd27 (Added ability to input a path to geo files)
fetch_command.add_argument(
'-f', '--force',
action='store_true',
help='(optional) include this flag to force an override of previously cached data')
fetch_command.set_defaults(handler=lambda args: fetch(
<<<<<<< HEAD
geo_name_or_path=args.geo,
=======
geo_name=args.geo,
geo_path=args.path,
>>>>>>> 02fcd27 (Added ability to input a path to geo files)
force=args.force
))

Expand Down Expand Up @@ -80,11 +72,7 @@ def define_argparser(command_parser: _SubParsersAction):
# - 2 empty cache


<<<<<<< HEAD
def fetch(geo_name_or_path: str, force: bool) -> int:
=======
def fetch(geo_name: str, force: bool, geo_path=None) -> int:
>>>>>>> 02fcd27 (Added ability to input a path to geo files)
"""CLI command handler: cache dynamic geo data."""

# split geo name and path
Expand All @@ -107,13 +95,8 @@ def fetch(geo_name: str, force: bool, geo_path=None) -> int:
choice = input(f'{geo_name} is already cached, overwrite? [y/n] ')
if force or choice == 'y':
try:
<<<<<<< HEAD
cache.fetch(geo_name_or_path)
print("geo sucessfully cached.")
=======
cache.fetch(geo_name, geo_path)
print('geo sucessfully cached.')
>>>>>>> 02fcd27 (Added ability to input a path to geo files)
except cache.GeoCacheException as e:
print(e)
return 1 # exit code: geo not found
Expand Down
13 changes: 1 addition & 12 deletions epymorph/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def define_argparser(command_parser: _SubParsersAction):
action='store_true',
help='(optional) include this flag to run the simulation without utilizing the Geo cache.')
p.add_argument(
'-g', '--mute_geo',
'-m', '--mute_geo',
action='store_false',
help='(optional) include this flag to silence geo data retreival messaging.')

Expand Down Expand Up @@ -259,7 +259,6 @@ 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]()

<<<<<<< HEAD
path = Path(name_or_path).expanduser()
if not path.exists():
raise UnknownModel('GEO', name_or_path)
Expand All @@ -277,16 +276,6 @@ def load_model_geo(name_or_path: str, ignore_cache: bool) -> Geo:
else:
msg = "Invalid file type. A geo can only be loaded from a .geo or .geo.tar file."
raise Exception(msg)
=======
path = Path(name_or_path)
if not path.exists():
raise UnknownModel('GEO', name_or_path)

if path.suffix == ".geo":
return DynamicGeoFileOps.load_from_spec(path, adrio_maker_library)
else:
return StaticGeoFileOps.load_from_archive(path)
>>>>>>> 02fcd27 (Added ability to input a path to geo files)


@load_messaging("IPM")
Expand Down
31 changes: 4 additions & 27 deletions epymorph/geo/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
from platformdirs import user_cache_path

from epymorph.data import adrio_maker_library, geo_library_dynamic
<<<<<<< HEAD
from epymorph.geo.dynamic import DynamicGeo
=======
>>>>>>> 02fcd27 (Added ability to input a path to geo files)
from epymorph.geo.dynamic import DynamicGeoFileOps as DF
from epymorph.geo.dynamic import dynamic_geo_messaging
from epymorph.geo.geo import Geo
Expand All @@ -23,51 +20,31 @@ class GeoCacheException(Exception):
"""An exception raised when a geo cache operation fails."""


<<<<<<< HEAD
def fetch(geo_name_or_path: str) -> None:
=======
def fetch(geo_name: str, geo_path=None) -> None:
>>>>>>> 02fcd27 (Added ability to input a path to geo files)
"""
Caches all attribute data for a dynamic geo from the library or spec file at a given path.
Raises GeoCacheException if spec not found.
"""
<<<<<<< HEAD

# checks for geo in the library (name passed)
if geo_name_or_path in geo_library_dynamic:
file_path = CACHE_PATH / F.to_archive_filename(geo_name_or_path)
geo_load = geo_library_dynamic.get(geo_name_or_path)
if geo_load is not None:
geo = geo_load()
static_geo = convert_to_static_geo(geo)
with dynamic_geo_messaging(geo):
static_geo = convert_to_static_geo(geo)
static_geo.save(file_path)

# checks for geo spec at given path (path passed)
=======
filepath = CACHE_PATH / F.to_archive_filename(geo_name)
geo_load = geo_library_dynamic.get(geo_name)
if geo_path is not None:
geo_path = Path(geo_path)
# checks for geo in library
if geo_load is not None:
geo = geo_load()
with dynamic_geo_messaging(geo):
static_geo = convert_to_static_geo(geo)
static_geo.save(filepath)
# checks for geo spec at given path
elif geo_path is not None and os.path.exists(geo_path):
geo = DF.load_from_spec(geo_path, adrio_maker_library)
static_geo = convert_to_static_geo(geo)
static_geo.save(filepath)
>>>>>>> 02fcd27 (Added ability to input a path to geo files)
else:
geo_path = Path(geo_name_or_path).expanduser()
if os.path.exists(geo_path):
geo_name = geo_path.stem
file_path = 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)
with dynamic_geo_messaging(geo):
static_geo = convert_to_static_geo(geo)
static_geo.save(file_path)
else:
raise GeoCacheException(f'spec file at {geo_name_or_path} not found.')
Expand Down

0 comments on commit 6201250

Please sign in to comment.