From ba68a314639161bde5e93d5405858dfda1233932 Mon Sep 17 00:00:00 2001 From: Purnendu Chakraborty Date: Tue, 30 Apr 2024 10:36:56 -0400 Subject: [PATCH] Patch for reading mepo1 state --- src/mepo/state/state.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/mepo/state/state.py b/src/mepo/state/state.py index 24be3511..0437f12b 100644 --- a/src/mepo/state/state.py +++ b/src/mepo/state/state.py @@ -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