Skip to content

Commit

Permalink
Patch 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 1d54e5e commit ba68a31
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/mepo/state/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,23 @@ def initialize(cls, project_config_file, directory_style):
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:
with open(cls.get_file(), 'rb') as fin:
allcomps = pickle.load(fin)
except ModuleNotFoundError:
# Patch start
# mepo1 to mepo2 includes reanming
# mepo.d/state/state.py -> src/mepo/state/state.py
# 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 mepo1 state
import mepo.state
import mepo.utilities
sys.modules['state'] = mepo.state
sys.modules['utilities'] = mepo.utilities
# Patch end
with open(cls.get_file(), 'rb') as fin:
allcomps = pickle.load(fin)
return allcomps

@classmethod
Expand Down

0 comments on commit ba68a31

Please sign in to comment.