Skip to content

Commit

Permalink
Added fix for reading mepo1 state
Browse files Browse the repository at this point in the history
  • Loading branch information
pchakraborty committed Apr 30, 2024
1 parent acdd32a commit 13febd8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/mepo/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,20 @@ def read_state(cls):
if not cls.exists():
raise StateDoesNotExistError('Error! mepo state does not exist')
with open(cls.get_file(), 'rb') as fin:
allcomps = pickle.load(fin)
try:
allcomps = pickle.load(fin)
except ModuleNotFoundError:
# mepo1 to mepo2 includes renaming of directories
# Since pickle requires that "the class definition must be
# importable and live in the same module as when the object was
# stored", we need to patch sys.modules to be able to read state
# that was created using mepo1
import mepo
sys.modules['state'] = mepo.state
sys.modules['state.component'] = mepo.component
sys.modules['utilities'] = mepo.utilities
fin.seek(0)
allcomps = pickle.load(fin)
return allcomps

@classmethod
Expand Down

0 comments on commit 13febd8

Please sign in to comment.