Jonathan Maw pushed to branch jonathan/pickle-yaml at BuildStream / buildstream
Commits:
-
913f3e65
by Jonathan Maw at 2018-09-19T14:40:36Z
5 changed files:
- buildstream/_loader/loader.py
- buildstream/_project.py
- buildstream/_yaml.py
- + buildstream/_yamlcache.py
- + tests/frontend/yamlcache.py
Changes:
... | ... | @@ -30,6 +30,7 @@ from ..element import Element |
30 | 30 |
from .._profile import Topics, profile_start, profile_end
|
31 | 31 |
from .._platform import Platform
|
32 | 32 |
from .._includes import Includes
|
33 |
+from .._yamlcache import YamlCache
|
|
33 | 34 |
|
34 | 35 |
from .types import Symbol, Dependency
|
35 | 36 |
from .loadelement import LoadElement
|
... | ... | @@ -113,7 +114,8 @@ class Loader(): |
113 | 114 |
profile_start(Topics.LOAD_PROJECT, target)
|
114 | 115 |
junction, name, loader = self._parse_name(target, rewritable, ticker,
|
115 | 116 |
fetch_subprojects=fetch_subprojects)
|
116 |
- loader._load_file(name, rewritable, ticker, fetch_subprojects)
|
|
117 |
+ with YamlCache.open(self._context) as yaml_cache:
|
|
118 |
+ loader._load_file(name, rewritable, ticker, fetch_subprojects, yaml_cache)
|
|
117 | 119 |
deps.append(Dependency(name, junction=junction))
|
118 | 120 |
profile_end(Topics.LOAD_PROJECT, target)
|
119 | 121 |
|
... | ... | @@ -202,11 +204,12 @@ class Loader(): |
202 | 204 |
# rewritable (bool): Whether we should load in round trippable mode
|
203 | 205 |
# ticker (callable): A callback to report loaded filenames to the frontend
|
204 | 206 |
# fetch_subprojects (bool): Whether to fetch subprojects while loading
|
207 |
+ # yaml_cache (YamlCache): A yaml cache
|
|
205 | 208 |
#
|
206 | 209 |
# Returns:
|
207 | 210 |
# (LoadElement): A loaded LoadElement
|
208 | 211 |
#
|
209 |
- def _load_file(self, filename, rewritable, ticker, fetch_subprojects):
|
|
212 |
+ def _load_file(self, filename, rewritable, ticker, fetch_subprojects, yaml_cache=None):
|
|
210 | 213 |
|
211 | 214 |
# Silently ignore already loaded files
|
212 | 215 |
if filename in self._elements:
|
... | ... | @@ -219,7 +222,8 @@ class Loader(): |
219 | 222 |
# Load the data and process any conditional statements therein
|
220 | 223 |
fullpath = os.path.join(self._basedir, filename)
|
221 | 224 |
try:
|
222 |
- node = _yaml.load(fullpath, shortname=filename, copy_tree=rewritable, project=self.project)
|
|
225 |
+ node = _yaml.load(fullpath, shortname=filename, copy_tree=rewritable,
|
|
226 |
+ project=self.project, yaml_cache=yaml_cache)
|
|
223 | 227 |
except LoadError as e:
|
224 | 228 |
if e.reason == LoadErrorReason.MISSING_FILE:
|
225 | 229 |
# If we can't find the file, try to suggest plausible
|
... | ... | @@ -262,13 +266,13 @@ class Loader(): |
262 | 266 |
# Load all dependency files for the new LoadElement
|
263 | 267 |
for dep in element.deps:
|
264 | 268 |
if dep.junction:
|
265 |
- self._load_file(dep.junction, rewritable, ticker, fetch_subprojects)
|
|
269 |
+ self._load_file(dep.junction, rewritable, ticker, fetch_subprojects, yaml_cache)
|
|
266 | 270 |
loader = self._get_loader(dep.junction, rewritable=rewritable, ticker=ticker,
|
267 | 271 |
fetch_subprojects=fetch_subprojects)
|
268 | 272 |
else:
|
269 | 273 |
loader = self
|
270 | 274 |
|
271 |
- dep_element = loader._load_file(dep.name, rewritable, ticker, fetch_subprojects)
|
|
275 |
+ dep_element = loader._load_file(dep.name, rewritable, ticker, fetch_subprojects, yaml_cache)
|
|
272 | 276 |
|
273 | 277 |
if _yaml.node_get(dep_element.node, str, Symbol.KIND) == 'junction':
|
274 | 278 |
raise LoadError(LoadErrorReason.INVALID_DATA,
|
... | ... | @@ -19,6 +19,7 @@ |
19 | 19 |
# Tiago Gomes <tiago gomes codethink co uk>
|
20 | 20 |
|
21 | 21 |
import os
|
22 |
+import hashlib
|
|
22 | 23 |
from collections import Mapping, OrderedDict
|
23 | 24 |
from pluginbase import PluginBase
|
24 | 25 |
from . import utils
|
... | ... | @@ -183,20 +183,35 @@ class CompositeTypeError(CompositeError): |
183 | 183 |
# shortname (str): The filename in shorthand for error reporting (or None)
|
184 | 184 |
# copy_tree (bool): Whether to make a copy, preserving the original toplevels
|
185 | 185 |
# for later serialization
|
186 |
+# yaml_cache (YamlCache): A yaml cache to consult rather than parsing
|
|
186 | 187 |
#
|
187 | 188 |
# Returns (dict): A loaded copy of the YAML file with provenance information
|
188 | 189 |
#
|
189 | 190 |
# Raises: LoadError
|
190 | 191 |
#
|
191 |
-def load(filename, shortname=None, copy_tree=False, *, project=None):
|
|
192 |
+def load(filename, shortname=None, copy_tree=False, *, project=None, yaml_cache=None):
|
|
192 | 193 |
if not shortname:
|
193 | 194 |
shortname = filename
|
194 | 195 |
|
195 | 196 |
file = ProvenanceFile(filename, shortname, project)
|
196 | 197 |
|
197 | 198 |
try:
|
199 |
+ data = None
|
|
198 | 200 |
with open(filename) as f:
|
199 |
- return load_data(f, file, copy_tree=copy_tree)
|
|
201 |
+ contents = f.read()
|
|
202 |
+ if yaml_cache:
|
|
203 |
+ assert project
|
|
204 |
+ key = yaml_cache.calculate_key(contents, copy_tree)
|
|
205 |
+ data = yaml_cache.get(project, filename, key)
|
|
206 |
+ |
|
207 |
+ if not data:
|
|
208 |
+ data = load_data(contents, file, copy_tree=copy_tree)
|
|
209 |
+ |
|
210 |
+ if yaml_cache:
|
|
211 |
+ assert project
|
|
212 |
+ yaml_cache.put(project, filename, key, data)
|
|
213 |
+ |
|
214 |
+ return data
|
|
200 | 215 |
except FileNotFoundError as e:
|
201 | 216 |
raise LoadError(LoadErrorReason.MISSING_FILE,
|
202 | 217 |
"Could not find file at {}".format(filename)) from e
|
1 |
+#
|
|
2 |
+# Copyright 2018 Bloomberg Finance LP
|
|
3 |
+#
|
|
4 |
+# This program is free software; you can redistribute it and/or
|
|
5 |
+# modify it under the terms of the GNU Lesser General Public
|
|
6 |
+# License as published by the Free Software Foundation; either
|
|
7 |
+# version 2 of the License, or (at your option) any later version.
|
|
8 |
+#
|
|
9 |
+# This library is distributed in the hope that it will be useful,
|
|
10 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12 |
+# Lesser General Public License for more details.
|
|
13 |
+#
|
|
14 |
+# You should have received a copy of the GNU Lesser General Public
|
|
15 |
+# License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
+#
|
|
17 |
+# Authors:
|
|
18 |
+# Jonathan Maw <jonathan maw codethink co uk>
|
|
19 |
+ |
|
20 |
+import os
|
|
21 |
+import pickle
|
|
22 |
+import hashlib
|
|
23 |
+import io
|
|
24 |
+ |
|
25 |
+import sys
|
|
26 |
+ |
|
27 |
+from contextlib import contextmanager
|
|
28 |
+from collections import namedtuple
|
|
29 |
+ |
|
30 |
+from ._cachekey import generate_key
|
|
31 |
+from ._context import Context
|
|
32 |
+from . import utils, _yaml
|
|
33 |
+ |
|
34 |
+ |
|
35 |
+YAML_CACHE_FILENAME = "yaml_cache.pickle"
|
|
36 |
+ |
|
37 |
+ |
|
38 |
+# YamlCache()
|
|
39 |
+#
|
|
40 |
+# A cache that wraps around the loading of yaml in projects.
|
|
41 |
+#
|
|
42 |
+# The recommended way to use a YamlCache is:
|
|
43 |
+# with YamlCache.open(context) as yamlcache:
|
|
44 |
+# # Load all the yaml
|
|
45 |
+# ...
|
|
46 |
+#
|
|
47 |
+# Args:
|
|
48 |
+# context (Context): The invocation Context
|
|
49 |
+#
|
|
50 |
+class YamlCache():
|
|
51 |
+ |
|
52 |
+ def __init__(self, context):
|
|
53 |
+ self._project_caches = {}
|
|
54 |
+ self._context = context
|
|
55 |
+ |
|
56 |
+ # Writes the yaml cache to the specified path.
|
|
57 |
+ def write(self):
|
|
58 |
+ path = self._get_cache_file(self._context)
|
|
59 |
+ parent_dir = os.path.dirname(path)
|
|
60 |
+ os.makedirs(parent_dir, exist_ok=True)
|
|
61 |
+ with open(path, "wb") as f:
|
|
62 |
+ BstPickler(f).dump(self)
|
|
63 |
+ |
|
64 |
+ # Gets a parsed file from the cache.
|
|
65 |
+ #
|
|
66 |
+ # Args:
|
|
67 |
+ # project (Project): The project this file is in.
|
|
68 |
+ # filepath (str): The path to the file.
|
|
69 |
+ # key (str): The key to the file within the cache. Typically, this is the
|
|
70 |
+ # value of `calculate_key()` with the file's unparsed contents
|
|
71 |
+ # and any relevant metadata passed in.
|
|
72 |
+ #
|
|
73 |
+ # Returns:
|
|
74 |
+ # (decorated dict): The parsed yaml from the cache, or None if the file isn't in the cache.
|
|
75 |
+ def get(self, project, filepath, key):
|
|
76 |
+ assert filepath.startswith(project.directory)
|
|
77 |
+ relative_filepath = os.path.relpath(filepath, project.directory)
|
|
78 |
+ try:
|
|
79 |
+ project_cache = self._project_caches[project.name]
|
|
80 |
+ try:
|
|
81 |
+ cachedyaml = project_cache.elements[relative_filepath]
|
|
82 |
+ if cachedyaml._key == key:
|
|
83 |
+ # We've unpickled the YamlCache, but not the specific file
|
|
84 |
+ if cachedyaml._contents is None:
|
|
85 |
+ cachedyaml._contents = BstUnpickler.loads(cachedyaml._pickled_contents, self._context)
|
|
86 |
+ return cachedyaml._contents
|
|
87 |
+ except KeyError:
|
|
88 |
+ pass
|
|
89 |
+ except KeyError:
|
|
90 |
+ pass
|
|
91 |
+ return None
|
|
92 |
+ |
|
93 |
+ # Put a parsed file into the cache.
|
|
94 |
+ #
|
|
95 |
+ # Args:
|
|
96 |
+ # project (Project): The project this file is in.
|
|
97 |
+ # filepath (str): The path to the file.
|
|
98 |
+ # key (str): The key to the file within the cache. Typically, this is the
|
|
99 |
+ # value of `calculate_key()` with the file's unparsed contents
|
|
100 |
+ # and any relevant metadata passed in.
|
|
101 |
+ # value (decorated dict): The data to put into the cache.
|
|
102 |
+ def put(self, project, filepath, key, value):
|
|
103 |
+ assert filepath.startswith(project.directory)
|
|
104 |
+ relative_filepath = os.path.relpath(filepath, project.directory)
|
|
105 |
+ try:
|
|
106 |
+ project_cache = self._project_caches[project.name]
|
|
107 |
+ except KeyError:
|
|
108 |
+ project_cache = self._project_caches[project.name] = CachedProject({})
|
|
109 |
+ |
|
110 |
+ project_cache.elements[relative_filepath] = CachedYaml(key, value)
|
|
111 |
+ |
|
112 |
+ # Checks whether a file is cached
|
|
113 |
+ # Args:
|
|
114 |
+ # project (Project): The project this file is in.
|
|
115 |
+ # filepath (str): The path to the file, *relative to the project's directory*.
|
|
116 |
+ #
|
|
117 |
+ # Returns:
|
|
118 |
+ # (bool): Whether the file is cached
|
|
119 |
+ def is_cached(self, project, filepath):
|
|
120 |
+ assert filepath.startswith(project.directory)
|
|
121 |
+ relative_filepath = os.path.relpath(filepath, project.directory)
|
|
122 |
+ try:
|
|
123 |
+ project_cache = self._project_caches[project.name]
|
|
124 |
+ if relative_filepath in project_cache.elements:
|
|
125 |
+ return True
|
|
126 |
+ except KeyError:
|
|
127 |
+ pass
|
|
128 |
+ return False
|
|
129 |
+ |
|
130 |
+ # Return an instance of the YamlCache which writes to disk when it leaves scope.
|
|
131 |
+ #
|
|
132 |
+ # Args:
|
|
133 |
+ # context (Context): The context.
|
|
134 |
+ #
|
|
135 |
+ # Returns:
|
|
136 |
+ # (YamlCache): A YamlCache.
|
|
137 |
+ @staticmethod
|
|
138 |
+ @contextmanager
|
|
139 |
+ def open(context):
|
|
140 |
+ # Try to load from disk first
|
|
141 |
+ cachefile = YamlCache._get_cache_file(context)
|
|
142 |
+ cache = None
|
|
143 |
+ if os.path.exists(cachefile):
|
|
144 |
+ try:
|
|
145 |
+ with open(cachefile, "rb") as f:
|
|
146 |
+ cache = BstUnpickler(f, context).load()
|
|
147 |
+ except pickle.UnpicklingError as e:
|
|
148 |
+ sys.stderr.write("Failed to load YamlCache, {}\n".format(e))
|
|
149 |
+ |
|
150 |
+ if not cache:
|
|
151 |
+ cache = YamlCache(context)
|
|
152 |
+ |
|
153 |
+ yield cache
|
|
154 |
+ |
|
155 |
+ cache.write()
|
|
156 |
+ |
|
157 |
+ # Calculates a key for putting into the cache.
|
|
158 |
+ @staticmethod
|
|
159 |
+ def calculate_key(*args):
|
|
160 |
+ string = pickle.dumps(args)
|
|
161 |
+ return hashlib.sha1(string).hexdigest()
|
|
162 |
+ |
|
163 |
+ # Retrieves a path to the yaml cache file.
|
|
164 |
+ @staticmethod
|
|
165 |
+ def _get_cache_file(context):
|
|
166 |
+ toplevel_project = context.get_toplevel_project()
|
|
167 |
+ return os.path.join(toplevel_project.directory, ".bst", YAML_CACHE_FILENAME)
|
|
168 |
+ |
|
169 |
+ |
|
170 |
+CachedProject = namedtuple('CachedProject', ['elements'])
|
|
171 |
+ |
|
172 |
+ |
|
173 |
+class CachedYaml():
|
|
174 |
+ def __init__(self, key, contents):
|
|
175 |
+ self._key = key
|
|
176 |
+ self.set_contents(contents)
|
|
177 |
+ |
|
178 |
+ # Sets the contents of the CachedYaml.
|
|
179 |
+ #
|
|
180 |
+ # Args:
|
|
181 |
+ # contents (provenanced dict): The contents to put in the cache.
|
|
182 |
+ #
|
|
183 |
+ def set_contents(self, contents):
|
|
184 |
+ self._contents = contents
|
|
185 |
+ self._pickled_contents = BstPickler.dumps(contents)
|
|
186 |
+ |
|
187 |
+ # Pickling helper method, prevents 'contents' from being serialised
|
|
188 |
+ def __getstate__(self):
|
|
189 |
+ data = self.__dict__.copy()
|
|
190 |
+ data['_contents'] = None
|
|
191 |
+ return data
|
|
192 |
+ |
|
193 |
+ |
|
194 |
+# In _yaml.load, we have a ProvenanceFile that stores the project the file
|
|
195 |
+# came from. Projects can't be pickled, but it's always going to be the same
|
|
196 |
+# project between invocations (unless the entire project is moved but the
|
|
197 |
+# file stayed in the same place)
|
|
198 |
+class BstPickler(pickle.Pickler):
|
|
199 |
+ def persistent_id(self, obj):
|
|
200 |
+ if isinstance(obj, _yaml.ProvenanceFile):
|
|
201 |
+ if obj.project:
|
|
202 |
+ # ProvenanceFile's project object cannot be stored as it is.
|
|
203 |
+ project_tag = obj.project.name
|
|
204 |
+ # ProvenanceFile's filename must be stored relative to the
|
|
205 |
+ # project, as the project dir may move.
|
|
206 |
+ name = os.path.relpath(obj.name, obj.project.directory)
|
|
207 |
+ else:
|
|
208 |
+ project_tag = None
|
|
209 |
+ name = obj.name
|
|
210 |
+ return ("ProvenanceFile", name, obj.shortname, project_tag)
|
|
211 |
+ elif isinstance(obj, Context):
|
|
212 |
+ return ("Context",)
|
|
213 |
+ else:
|
|
214 |
+ return None
|
|
215 |
+ |
|
216 |
+ @staticmethod
|
|
217 |
+ def dumps(obj):
|
|
218 |
+ stream = io.BytesIO()
|
|
219 |
+ BstPickler(stream).dump(obj)
|
|
220 |
+ stream.seek(0)
|
|
221 |
+ return stream.read()
|
|
222 |
+ |
|
223 |
+ |
|
224 |
+class BstUnpickler(pickle.Unpickler):
|
|
225 |
+ def __init__(self, file, context):
|
|
226 |
+ super().__init__(file)
|
|
227 |
+ self._context = context
|
|
228 |
+ |
|
229 |
+ def persistent_load(self, pid):
|
|
230 |
+ if pid[0] == "ProvenanceFile":
|
|
231 |
+ _, tagged_name, shortname, project_tag = pid
|
|
232 |
+ |
|
233 |
+ if project_tag is not None:
|
|
234 |
+ for p in self._context.get_projects():
|
|
235 |
+ if project_tag == p.name:
|
|
236 |
+ project = p
|
|
237 |
+ break
|
|
238 |
+ |
|
239 |
+ name = os.path.join(project.directory, tagged_name)
|
|
240 |
+ |
|
241 |
+ if not project:
|
|
242 |
+ projects = [p.name for p in self._context.get_projects()]
|
|
243 |
+ raise pickle.UnpicklingError("No project with name {} found in {}"
|
|
244 |
+ .format(key_id, projects))
|
|
245 |
+ else:
|
|
246 |
+ project = None
|
|
247 |
+ name = tagged_name
|
|
248 |
+ |
|
249 |
+ return _yaml.ProvenanceFile(name, shortname, project)
|
|
250 |
+ elif pid[0] == "Context":
|
|
251 |
+ return self._context
|
|
252 |
+ else:
|
|
253 |
+ raise pickle.UnpicklingError("Unsupported persistent object, {}".format(pid))
|
|
254 |
+ |
|
255 |
+ @staticmethod
|
|
256 |
+ def loads(text, context):
|
|
257 |
+ stream = io.BytesIO()
|
|
258 |
+ stream.write(bytes(text))
|
|
259 |
+ stream.seek(0)
|
|
260 |
+ return BstUnpickler(stream, context).load()
|
1 |
+import os
|
|
2 |
+import pytest
|
|
3 |
+import hashlib
|
|
4 |
+import tempfile
|
|
5 |
+from ruamel import yaml
|
|
6 |
+ |
|
7 |
+from tests.testutils import cli, generate_junction, create_element_size, create_repo
|
|
8 |
+from buildstream import _yaml
|
|
9 |
+from buildstream._yamlcache import YamlCache
|
|
10 |
+from buildstream._project import Project
|
|
11 |
+from buildstream._context import Context
|
|
12 |
+from contextlib import contextmanager
|
|
13 |
+ |
|
14 |
+ |
|
15 |
+def generate_project(tmpdir, ref_storage, with_junction, name="test"):
|
|
16 |
+ if with_junction == 'junction':
|
|
17 |
+ subproject_dir = generate_project(
|
|
18 |
+ tmpdir, ref_storage,
|
|
19 |
+ 'no-junction', name='test-subproject'
|
|
20 |
+ )
|
|
21 |
+ |
|
22 |
+ project_dir = os.path.join(tmpdir, name)
|
|
23 |
+ os.makedirs(project_dir)
|
|
24 |
+ # project.conf
|
|
25 |
+ project_conf_path = os.path.join(project_dir, 'project.conf')
|
|
26 |
+ elements_path = 'elements'
|
|
27 |
+ project_conf = {
|
|
28 |
+ 'name': name,
|
|
29 |
+ 'element-path': elements_path,
|
|
30 |
+ 'ref-storage': ref_storage,
|
|
31 |
+ }
|
|
32 |
+ _yaml.dump(project_conf, project_conf_path)
|
|
33 |
+ |
|
34 |
+ # elements
|
|
35 |
+ if with_junction == 'junction':
|
|
36 |
+ junction_name = 'junction.bst'
|
|
37 |
+ junction_dir = os.path.join(project_dir, elements_path)
|
|
38 |
+ junction_path = os.path.join(project_dir, elements_path, junction_name)
|
|
39 |
+ os.makedirs(junction_dir)
|
|
40 |
+ generate_junction(tmpdir, subproject_dir, junction_path)
|
|
41 |
+ element_depends = [{'junction': junction_name, 'filename': 'test.bst'}]
|
|
42 |
+ else:
|
|
43 |
+ element_depends = []
|
|
44 |
+ |
|
45 |
+ element_name = 'test.bst'
|
|
46 |
+ create_element_size(element_name, project_dir, elements_path, element_depends, 1)
|
|
47 |
+ |
|
48 |
+ return project_dir
|
|
49 |
+ |
|
50 |
+ |
|
51 |
+@contextmanager
|
|
52 |
+def with_yamlcache(project_dir):
|
|
53 |
+ context = Context()
|
|
54 |
+ project = Project(project_dir, context)
|
|
55 |
+ with YamlCache.open(context) as yamlcache:
|
|
56 |
+ yield yamlcache, project
|
|
57 |
+ |
|
58 |
+ |
|
59 |
+def yamlcache_key(yamlcache, in_file, copy_tree=False):
|
|
60 |
+ with open(in_file) as f:
|
|
61 |
+ key = yamlcache.calculate_key(f.read(), copy_tree)
|
|
62 |
+ return key
|
|
63 |
+ |
|
64 |
+ |
|
65 |
+def modified_file(input_file):
|
|
66 |
+ with open(input_file) as f:
|
|
67 |
+ data = f.read()
|
|
68 |
+ assert 'variables' not in data
|
|
69 |
+ data += '\nvariables: {modified: True}\n'
|
|
70 |
+ _, temppath = tempfile.mkstemp(text=True)
|
|
71 |
+ with open(temppath, 'w') as f:
|
|
72 |
+ f.write(data)
|
|
73 |
+ |
|
74 |
+ return temppath
|
|
75 |
+ |
|
76 |
+ |
|
77 |
+@pytest.mark.parametrize('ref_storage', ['inline', 'project.refs'])
|
|
78 |
+@pytest.mark.parametrize('with_junction', ['no-junction', 'junction'])
|
|
79 |
+@pytest.mark.parametrize('move_project', ['move', 'no-move'])
|
|
80 |
+def test_yamlcache_used(cli, tmpdir, ref_storage, with_junction, move_project):
|
|
81 |
+ # Generate the project
|
|
82 |
+ project = generate_project(str(tmpdir), ref_storage, with_junction)
|
|
83 |
+ if with_junction == 'junction':
|
|
84 |
+ result = cli.run(project=project, args=['fetch', '--track', 'junction.bst'])
|
|
85 |
+ result.assert_success()
|
|
86 |
+ |
|
87 |
+ # bst show to put it in the cache
|
|
88 |
+ result = cli.run(project=project, args=['show', 'test.bst'])
|
|
89 |
+ result.assert_success()
|
|
90 |
+ |
|
91 |
+ element_path = os.path.join(project, 'elements', 'test.bst')
|
|
92 |
+ with with_yamlcache(project) as (yc, prj):
|
|
93 |
+ # Check that it's in the cache
|
|
94 |
+ assert yc.is_cached(prj, element_path)
|
|
95 |
+ |
|
96 |
+ # *Absolutely* horrible cache corruption to check it's being used
|
|
97 |
+ # Modifying the data from the cache is fraught with danger,
|
|
98 |
+ # so instead I'll load a modified version of the original file
|
|
99 |
+ temppath = modified_file(element_path)
|
|
100 |
+ contents = _yaml.load(temppath, copy_tree=False, project=prj)
|
|
101 |
+ key = yamlcache_key(yc, element_path)
|
|
102 |
+ yc.put(prj, element_path, key, contents)
|
|
103 |
+ |
|
104 |
+ # Show that a variable has been added
|
|
105 |
+ result = cli.run(project=project, args=['show', '--format', '%{vars}', 'test.bst'])
|
|
106 |
+ result.assert_success()
|
|
107 |
+ data = yaml.safe_load(result.output)
|
|
108 |
+ assert 'modified' in data
|
|
109 |
+ assert data['modified'] == 'True'
|
|
110 |
+ |
|
111 |
+ |
|
112 |
+@pytest.mark.parametrize('ref_storage', ['inline', 'project.refs'])
|
|
113 |
+@pytest.mark.parametrize('with_junction', ['junction', 'no-junction'])
|
|
114 |
+@pytest.mark.parametrize('move_project', ['move', 'no-move'])
|
|
115 |
+def test_yamlcache_changed_file(cli, ref_storage, with_junction, move_project):
|
|
116 |
+ # inline and junction can only be changed by opening a workspace
|
|
117 |
+ pass
|
|
118 |
+ |
|
119 |
+ |
|
120 |
+@pytest.mark.parametrize('ref_storage', ['inline', 'project.refs'])
|
|
121 |
+@pytest.mark.parametrize('with_junction', ['junction', 'no-junction'])
|
|
122 |
+@pytest.mark.parametrize('move_project', ['move', 'no-move'])
|
|
123 |
+def test_yamlcache_track_changed(cli, ref_storage, with_junction, move_project):
|
|
124 |
+ # Skip inline junction, tracking those is forbidden
|
|
125 |
+ pass
|