Skip to content

Commit

Permalink
Local path saved to state file is relative to fixture directory
Browse files Browse the repository at this point in the history
  • Loading branch information
pchakraborty committed May 14, 2024
1 parent 8917834 commit 64a5ade
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/mepo/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ def mepo1_patch_undo():
def read_state(cls):
if cls.state_exists():
with open(cls.get_file(), "r") as fin:
allcomps_d = json.load(fin)
allcomps_s = json.load(fin)
# List of dicts -> state (list of MepoComponent objects)
allcomps = []
for comp in allcomps_d:
allcomps.append(MepoComponent().deserialize(comp))
for comp_s in allcomps_s:
comp = MepoComponent().deserialize(comp_s)
# Relative path to absolute
comp.local = os.path.join(cls.get_root_dir(), comp.local)
allcomps.append(comp)
return allcomps
elif cls.state_exists(old_style=True):
print(
Expand Down Expand Up @@ -148,6 +151,8 @@ def write_state(cls, allcomps):
new_state_file = cls.__get_new_state_file()
allcomps_s = []
for comp in allcomps:
# Save relative path (to fixture dir) to state
comp.local = os.path.relpath(comp.local, start=cls.get_root_dir())
allcomps_s.append(comp.serialize())
with open(new_state_file, "w") as fout:
json.dump(allcomps_s, fout)
Expand Down

0 comments on commit 64a5ade

Please sign in to comment.