Config interface ok

This commit is contained in:
2026-08-10 16:37:59 -03:00
parent 2777b34026
commit d087b64320
12 changed files with 4052 additions and 172 deletions
+99 -19
View File
@@ -11,7 +11,105 @@ import sys
import venv
from pathlib import Path
from typing import Optional
from . import log, PathLike
from collections.abc import MutableMapping
from . import logger, PathLike
class DataDict(dict):
"""Wrapper around dictionary objects for easier dict subclassing
See module [collections](https://github.com/python/cpython/blob/3.14/Lib/collections/__init__.py#L1133)
"""
def __init__(self, *args, **kwargs):
self._data = {}
if args is not None:
if isinstance(args, list):
for a in args:
if not isinstance(a,tuple) or len(a) != 2:
# list is not a list of (k,v) tuples
self._args = args
break
# all list items are (k,v) tuples
self.update(args)
self._args = args
if kwargs:
self.update(kwargs)
# Emulate accessing class attributes
def __getattr__(self, key):
# This gets called only if __getattribute__ doesn't find key
return self._data[key]
def __setattr__(self, key, value):
if key.startswith("_"):
return super().__setattr__ (key, value)
return self._data.__setitem__(key, value)
def __delattr__(self, key):
if key.startswith("_"):
return super().__delattr__(key)
return self._data.__delitem__(key)
# Emulate dict methods
def __len__(self):
return len(self._data)
def __getitem__(self, key):
if key in self._data:
return self._data[key]
if hasattr(self.__class__, "__missing__"):
return self.__class__.__missing__(self, key)
raise KeyError(key)
def __setitem__(self, key, value):
self._data[key] = value
def __delitem__(self, key):
del self._data[key]
def __iter__(self):
return iter(self._data)
def __contains__(self, key):
return key in self._data
def get(self, key, default=None):
if key in self:
return self[key]
return default
def __repr__(self):
return repr(self._data)
def __or__(self, other):
return self._data | other
def __ror__(self, other):
return other | self._data
def __ior__(self, other):
self._data |= other
return self
def __copy__(self):
# TODO: verify if this is correct
return dict(self._data)
def copy(self):
import copy
return copy.copy(self._data)
@classmethod
def fromkeys(cls, iterable, value=None):
d = cls()
for key in iterable:
d[key] = value
return d
def get_vendor_root() -> Path:
return Path(__file__).resolve().parents[1] / "vendor"
@@ -72,21 +170,3 @@ def build_run_command(
# else str(venv_path / "bin" / backend_cmd)
# )
def check_env(self, which=None):
if not which:
return None
if isinstance(which, str):
if " " in which:
which = which.split()
which = [which]
for bin in which:
p = shutil.which(bin)
if not p:
log(f"{bin} is either NOT installed or "
"NOT in your system PATH.")
return False
else:
log(f"{bin} found at: {p}")
return True