pylint path.py
This commit is contained in:
@ -36,7 +36,8 @@ class PropertyAnnotator:
|
||||
if hasattr(variable, 'mode') and variable.mode:
|
||||
properties.append(variable.mode)
|
||||
variable.mode = None
|
||||
if 'force_store_value' in properties and 'force_default_on_freeze' in properties:
|
||||
if 'force_store_value' in properties and 'force_default_on_freeze' in properties: # pragma: no cover
|
||||
# should not appened
|
||||
xmlfiles = self.objectspace.display_xmlfiles(variable.xmlfiles)
|
||||
msg = _('cannot have auto_freeze or auto_store with the hidden '
|
||||
f'variable "{variable.name}" in {xmlfiles}')
|
||||
|
@ -1,3 +1,5 @@
|
||||
"""Manage path to find objects
|
||||
"""
|
||||
from .i18n import _
|
||||
from .error import DictConsistencyError
|
||||
from .config import Config
|
||||
@ -22,12 +24,15 @@ class Path:
|
||||
name: str,
|
||||
variableobj: str,
|
||||
) -> str: # pylint: disable=C0111
|
||||
"""Add a new family
|
||||
"""
|
||||
if namespace == Config['variable_namespace']:
|
||||
full_name = '.'.join([namespace, name])
|
||||
self.full_paths_families[name] = full_name
|
||||
else:
|
||||
if '.' not in name:
|
||||
raise DictConsistencyError(_(f'Variable "{name}" in namespace "{namespace}" must have dot'), 39)
|
||||
if '.' not in name: # pragma: no cover
|
||||
msg = _(f'Variable "{name}" in namespace "{namespace}" must have dot')
|
||||
raise DictConsistencyError(msg, 39)
|
||||
full_name = name
|
||||
if full_name in self.families and \
|
||||
self.families[full_name]['variableobj'] != variableobj: # pragma: no cover
|
||||
@ -43,6 +48,8 @@ class Path:
|
||||
path: str,
|
||||
variableobj: str,
|
||||
) -> str: # pylint: disable=C0111
|
||||
"""add a new leadership
|
||||
"""
|
||||
self.families[path] = dict(name=path,
|
||||
namespace=namespace,
|
||||
variableobj=variableobj,
|
||||
@ -53,14 +60,19 @@ class Path:
|
||||
name: str,
|
||||
current_namespace: str,
|
||||
) -> 'Family': # pylint: disable=C0111
|
||||
"""Get a family
|
||||
"""
|
||||
name = '.'.join([normalize_family(subname) for subname in name.split('.')])
|
||||
if name not in self.families and name in self.full_paths_families:
|
||||
name = self.full_paths_families[name]
|
||||
if name not in self.families:
|
||||
raise DictConsistencyError(_('unknown option {}').format(name), 42)
|
||||
dico = self.families[name]
|
||||
if current_namespace not in [Config['variable_namespace'], 'services'] and current_namespace != dico['namespace']:
|
||||
raise DictConsistencyError(_(f'A family located in the "{dico["namespace"]}" namespace shall not be used in the "{current_namespace}" namespace'), 38)
|
||||
if current_namespace not in [Config['variable_namespace'], 'services'] and \
|
||||
current_namespace != dico['namespace']:
|
||||
msg = _(f'A family located in the "{dico["namespace"]}" namespace '
|
||||
f'shall not be used in the "{current_namespace}" namespace')
|
||||
raise DictConsistencyError(msg, 38)
|
||||
return dico['variableobj']
|
||||
|
||||
# Leadership
|
||||
@ -70,6 +82,8 @@ class Path:
|
||||
leadership_name: str,
|
||||
name: str,
|
||||
) -> None: # pylint: disable=C0111
|
||||
"""set a variable a leadership member
|
||||
"""
|
||||
# need rebuild path and move object in new path
|
||||
old_path = leader_family_name + '.' + name
|
||||
leadership_path = leader_family_name + '.' + leadership_name
|
||||
@ -82,9 +96,13 @@ class Path:
|
||||
self.full_paths_variables[name] = new_path
|
||||
|
||||
def is_in_leadership(self, name):
|
||||
"""Is the variable is in a leadership
|
||||
"""
|
||||
return self._get_variable(name)['leader'] is not None
|
||||
|
||||
def is_leader(self, path): # pylint: disable=C0111
|
||||
"""Is the variable is a leader
|
||||
"""
|
||||
variable = self._get_variable(path)
|
||||
if not variable['leader']:
|
||||
return False
|
||||
@ -99,6 +117,8 @@ class Path:
|
||||
is_dynamic: bool,
|
||||
variableobj,
|
||||
) -> str: # pylint: disable=C0111
|
||||
"""Add a new variable (with path)
|
||||
"""
|
||||
if '.' not in name:
|
||||
full_path = '.'.join([family, name])
|
||||
if namespace == Config['variable_namespace']:
|
||||
@ -116,6 +136,8 @@ class Path:
|
||||
def get_variable(self,
|
||||
name: str,
|
||||
) -> 'Variable': # pylint: disable=C0111
|
||||
"""Get variable object from a path
|
||||
"""
|
||||
variable, suffix = self._get_variable(name, with_suffix=True)
|
||||
if suffix:
|
||||
raise DictConsistencyError(_(f"{name} is a dynamic variable"), 36)
|
||||
@ -124,30 +146,41 @@ class Path:
|
||||
def get_variable_family_path(self,
|
||||
name: str,
|
||||
) -> str: # pylint: disable=C0111
|
||||
"""Get the full path of a family
|
||||
"""
|
||||
return self._get_variable(name)['family']
|
||||
|
||||
def get_variable_path(self,
|
||||
name: str,
|
||||
current_namespace: str,
|
||||
) -> str: # pylint: disable=C0111
|
||||
"""get full path of a variable
|
||||
"""
|
||||
dico, suffix = self._get_variable(name,
|
||||
with_suffix=True,
|
||||
)
|
||||
namespace = dico['variableobj'].namespace
|
||||
if namespace not in [Config['variable_namespace'], 'services'] and current_namespace != namespace:
|
||||
raise DictConsistencyError(_(f'A variable located in the "{namespace}" namespace shall not be used in the "{current_namespace}" namespace'), 41)
|
||||
if namespace not in [Config['variable_namespace'], 'services'] and \
|
||||
current_namespace != namespace:
|
||||
msg = _(f'A variable located in the "{namespace}" namespace shall not be used '
|
||||
f'in the "{current_namespace}" namespace')
|
||||
raise DictConsistencyError(msg, 41)
|
||||
return dico['variableobj'].path, suffix
|
||||
|
||||
def path_is_defined(self,
|
||||
name: str,
|
||||
path: str,
|
||||
) -> str: # pylint: disable=C0111
|
||||
if '.' not in name and name not in self.variables and name in self.full_paths_variables:
|
||||
"""The path is a valid path
|
||||
"""
|
||||
if '.' not in path and path not in self.variables and path in self.full_paths_variables:
|
||||
return True
|
||||
return name in self.variables
|
||||
return path in self.variables
|
||||
|
||||
def variable_is_dynamic(self,
|
||||
name: str,
|
||||
) -> bool:
|
||||
"""This variable is in dynamic family
|
||||
"""
|
||||
return self._get_variable(name)['is_dynamic']
|
||||
|
||||
def _get_variable(self,
|
||||
|
Reference in New Issue
Block a user