|
|
|
@ -302,7 +302,7 @@ class Table:
|
|
|
|
|
|
|
|
|
|
self.columns = set()
|
|
|
|
|
if fields is not None:
|
|
|
|
|
self.columns.update(self.fields)
|
|
|
|
|
self.columns.update(fields)
|
|
|
|
|
else:
|
|
|
|
|
self.columns = set(values[0].keys())
|
|
|
|
|
|
|
|
|
@ -380,6 +380,10 @@ class TableType(VariableType):
|
|
|
|
|
else:
|
|
|
|
|
if isinstance(value, Table):
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
if variable.fields:
|
|
|
|
|
return Table(value, variable, fields=variable.fields)
|
|
|
|
|
else:
|
|
|
|
|
return Table(value, variable)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -563,8 +567,9 @@ class DependenceSource:
|
|
|
|
|
|
|
|
|
|
class VariableNode:
|
|
|
|
|
'''Класс ноды соответствующей переменной в дереве переменных.'''
|
|
|
|
|
def __init__(self, name, namespace, variable_type=VariableType,
|
|
|
|
|
source=None):
|
|
|
|
|
def __init__(self, name: str, namespace: "NamespaceNode",
|
|
|
|
|
variable_type=VariableType,
|
|
|
|
|
source=None, fields: list = []):
|
|
|
|
|
self.name = name
|
|
|
|
|
if issubclass(variable_type, VariableType):
|
|
|
|
|
self.variable_type = variable_type
|
|
|
|
@ -572,6 +577,7 @@ class VariableNode:
|
|
|
|
|
raise VariableTypeError('variable_type must be VariableType'
|
|
|
|
|
', but not {}'.format(type(variable_type)))
|
|
|
|
|
self.calculating = False
|
|
|
|
|
self.fields = fields
|
|
|
|
|
|
|
|
|
|
self.namespace = namespace
|
|
|
|
|
self.namespace.add_variable(self)
|
|
|
|
@ -633,6 +639,9 @@ class VariableNode:
|
|
|
|
|
else:
|
|
|
|
|
value = self._source
|
|
|
|
|
|
|
|
|
|
if self.variable_type is TableType:
|
|
|
|
|
self.value = self.variable_type.process_value(value, self)
|
|
|
|
|
else:
|
|
|
|
|
self.value = self.variable_type.process_value(value, self)
|
|
|
|
|
self._invalidated = False
|
|
|
|
|
|
|
|
|
@ -681,9 +690,6 @@ class VariableNode:
|
|
|
|
|
# Если источники не совпадают или текущее значение переменной было
|
|
|
|
|
# установлено пользователем, то инвалидируем переменную и меняем
|
|
|
|
|
# источник.
|
|
|
|
|
if self.name == "machine":
|
|
|
|
|
print('self.source =', self.source)
|
|
|
|
|
print('source =', source)
|
|
|
|
|
if self._source != source or self.set_by_user:
|
|
|
|
|
self.set_by_user = False
|
|
|
|
|
self._invalidate()
|
|
|
|
@ -950,19 +956,13 @@ class VariableAPI(metaclass=Singleton):
|
|
|
|
|
self.errors = []
|
|
|
|
|
|
|
|
|
|
def __call__(self, name: str, source=None, type=VariableType,
|
|
|
|
|
readonly=False, fixed=False, force=False):
|
|
|
|
|
readonly=False, fixed=False, force=False, fields=None):
|
|
|
|
|
'''Метод для создания переменных внутри with Namespace('name').'''
|
|
|
|
|
if name == "machine":
|
|
|
|
|
print("creating var...")
|
|
|
|
|
|
|
|
|
|
if name not in self.current_namespace._variables:
|
|
|
|
|
variable = VariableNode(name, self.current_namespace)
|
|
|
|
|
else:
|
|
|
|
|
variable = self.current_namespace[name]
|
|
|
|
|
|
|
|
|
|
if name == "machine":
|
|
|
|
|
print('using dependence')
|
|
|
|
|
|
|
|
|
|
if isinstance(source, DependenceSource):
|
|
|
|
|
try:
|
|
|
|
|
source.check()
|
|
|
|
@ -974,12 +974,16 @@ class VariableAPI(metaclass=Singleton):
|
|
|
|
|
else:
|
|
|
|
|
variable.source = source
|
|
|
|
|
|
|
|
|
|
if fields:
|
|
|
|
|
variable.fields = fields
|
|
|
|
|
|
|
|
|
|
if readonly:
|
|
|
|
|
variable.set_variable_type(type, readonly=True)
|
|
|
|
|
elif fixed:
|
|
|
|
|
variable.set_variable_type(type, fixed=True)
|
|
|
|
|
else:
|
|
|
|
|
variable.set_variable_type(type)
|
|
|
|
|
|
|
|
|
|
return variable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|