MCPcopy Create free account
hub / github.com/pytorch/pytorch / _CommitDataCache

Class _CommitDataCache

scripts/release_notes/common.py:307–332  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305
306
307class _CommitDataCache:
308 def __init__(self, path):
309 self.path = path
310 self.data = {}
311 if os.path.exists(path):
312 self.data = self.read_from_disk()
313 else:
314 os.makedirs(Path(path).parent, exist_ok=True)
315
316 def get(self, commit):
317 if commit not in self.data.keys():
318 # Fetch and cache the data
319 self.data[commit] = get_features(commit)
320 self.write_to_disk()
321 return self.data[commit]
322
323 def read_from_disk(self):
324 with open(self.path, "r") as f:
325 data = json.load(f)
326 data = {commit: dict_to_features(dct) for commit, dct in data.items()}
327 return data
328
329 def write_to_disk(self):
330 data = {commit: features._asdict() for commit, features in self.data.items()}
331 with open(self.path, "w") as f:
332 json.dump(data, f)

Callers 1

get_commit_data_cacheFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…