Skip to content

Commit

Permalink
fix: track bolt version in cached ast
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Jun 15, 2022
1 parent 21524bb commit 1e5d2d1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion bolt/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from typing import Any, Callable, Dict, Iterator, List, Optional, Set, Union

from beet import BubbleException, Context, TextFile, TextFileBase, generate_tree
from beet.core.utils import JsonDict, required_field
from beet.core.utils import JsonDict, import_from_string, required_field
from mecha import (
AstCacheBackend,
AstCommand,
Expand Down Expand Up @@ -329,6 +329,17 @@ class ModuleCacheBackend(AstCacheBackend):
"""Cache backend that also restores the generated modules."""

runtime: Runtime = required_field()
bolt_version: str = import_from_string("bolt.__version__")

def load_data(self, f: BufferedReader) -> JsonDict:
data = super().load_data(f)
if data["bolt"] != self.bolt_version:
raise ValueError("Version mismatch.")
return data

def dump_data(self, data: JsonDict, f: BufferedWriter):
data["bolt"] = self.bolt_version
super().dump_data(data, f)

def load(self, f: BufferedReader) -> AstRoot:
data = self.load_data(f)
Expand Down

0 comments on commit 1e5d2d1

Please sign in to comment.