Leon4gr45 commited on
Commit
60fb08a
·
verified ·
1 Parent(s): 2448759

Delete vrag/settings.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. vrag/settings.py +0 -59
vrag/settings.py DELETED
@@ -1,59 +0,0 @@
1
- """Atomic configuration history. Defaults are read-only unless storage is configured."""
2
- import asyncio
3
- import json
4
- import os
5
- from pathlib import Path
6
- import tempfile
7
- from config.schema import Configuration
8
-
9
- class ConfigStore:
10
- def __init__(self, path=None):
11
- self.path = Path(path or os.environ['VM_STATE_DIR']) if path or os.environ.get('VM_STATE_DIR') else None
12
- self.lock = asyncio.Lock()
13
- self.history = [Configuration()]
14
- self.version = 1
15
- if self.path:
16
- self.path.mkdir(parents=True, exist_ok=True)
17
- state = self.path / 'config-history.json'
18
- if state.exists():
19
- self.history = [Configuration.model_validate(c) for c in json.loads(state.read_text())]
20
- self.version = len(self.history)
21
- def snapshot(self):
22
- # Deep copy prevents nested mutation of in-flight snapshots.
23
- return self.version, self.history[-1].model_copy(deep=True)
24
- async def apply(self, config, expected):
25
- if not self.path:
26
- raise ValueError('VM_STATE_DIR is required for configuration updates; defaults are read-only')
27
- async with self.lock:
28
- if expected != self.version:
29
- raise ValueError('configuration changed; reload before applying')
30
- if len(self.history) >= 100:
31
- raise ValueError('configuration history limit reached; archive state before more updates')
32
- history = self.history + [config]
33
- fd, tmp = tempfile.mkstemp(dir=self.path, prefix='.config-')
34
- try:
35
- with os.fdopen(fd, 'w') as f:
36
- json.dump([c.model_dump() for c in history], f)
37
- f.flush()
38
- os.fsync(f.fileno())
39
- # Persist the previous complete history before switching the active file.
40
- if (self.path / 'config-history.json').exists():
41
- import shutil
42
- backup = self.path / '.config-history.backup.tmp'
43
- shutil.copyfile(self.path / 'config-history.json', backup)
44
- with backup.open('rb') as previous:
45
- os.fsync(previous.fileno())
46
- os.replace(backup, self.path / 'config-history.backup.json')
47
- os.replace(tmp, self.path / 'config-history.json')
48
- directory_fd = os.open(self.path, os.O_RDONLY)
49
- try:
50
- os.fsync(directory_fd)
51
- finally:
52
- os.close(directory_fd)
53
- finally:
54
- if os.path.exists(tmp):
55
- os.unlink(tmp)
56
- self.history, self.version = history, len(history)
57
- return self.version
58
-
59
- store = ConfigStore()