feat: can desactivate isolated namespace feature
This commit is contained in:
parent
c4404a7d46
commit
36f13dec22
10 changed files with 61 additions and 13 deletions
|
|
@ -133,7 +133,7 @@ class ParserVariable:
|
|||
def __init__(self, rougailconfig):
|
||||
self.rougailconfig = rougailconfig
|
||||
self.load_config()
|
||||
self.paths = Paths(None)
|
||||
self.paths = Paths(None, True)
|
||||
self.families = []
|
||||
self.variables = []
|
||||
self.parents = {".": []}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,9 @@ from typing import (
|
|||
import logging
|
||||
from re import compile, findall
|
||||
|
||||
from ..i18n import _
|
||||
from .object_model import Family, Variable
|
||||
from ..error import DictConsistencyError
|
||||
from ..i18n import _
|
||||
from ..tiramisu import normalize_family
|
||||
|
||||
|
||||
|
|
@ -35,12 +36,14 @@ class Paths:
|
|||
def __init__(
|
||||
self,
|
||||
default_namespace: str,
|
||||
isolated_namespace: bool,
|
||||
) -> None:
|
||||
self._data: Dict[str, Union[Variable, Family]] = {}
|
||||
self._dynamics: Dict[str:str] = {}
|
||||
if default_namespace is not None:
|
||||
default_namespace = normalize_family(default_namespace)
|
||||
self.default_namespace = default_namespace
|
||||
self.isolated_namespace = isolated_namespace
|
||||
|
||||
def has_value(self) -> bool:
|
||||
return self._data != {}
|
||||
|
|
@ -201,6 +204,7 @@ class Paths:
|
|||
option = self._data[path]
|
||||
option_namespace = option.namespace
|
||||
if (
|
||||
self.isolated_namespace and
|
||||
self.default_namespace not in [namespace, option_namespace]
|
||||
and namespace != option_namespace
|
||||
):
|
||||
|
|
|
|||
|
|
@ -39,7 +39,9 @@ class Walker:
|
|||
rougailconfig = self.convert.rougailconfig
|
||||
self.sort_structural_files_all = rougailconfig["sort_structural_files_all"]
|
||||
if rougailconfig["main_namespace"]:
|
||||
self.convert.paths = Paths(rougailconfig["main_namespace"])
|
||||
self.convert.paths = Paths(rougailconfig["main_namespace"],
|
||||
rougailconfig["isolated_namespace"],
|
||||
)
|
||||
self.load_with_extra(
|
||||
rougailconfig["extra_namespaces"],
|
||||
rougailconfig["main_namespace"],
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ main_structural_directories:
|
|||
multi: true
|
||||
disabled:
|
||||
jinja: >-
|
||||
{{% if 'directory' not in step.structural %}}
|
||||
directory is not in step.structural
|
||||
{{% if 'directory' not in _.step.structural %}}
|
||||
directory is not in _.step.structural
|
||||
{{% endif %}}
|
||||
{{% if cli is defined and cli.versions is defined and cli.versions %}}
|
||||
cli.versions is specified
|
||||
|
|
@ -50,8 +50,8 @@ sort_structural_files_all:
|
|||
default: false
|
||||
disabled:
|
||||
jinja: >-
|
||||
{{% if 'directory' not in step.structural %}}
|
||||
directory is not in step.structural
|
||||
{{% if 'directory' not in _.step.structural %}}
|
||||
directory is not in _.step.structural
|
||||
{{% endif %}}
|
||||
|
||||
main_namespace:
|
||||
|
|
@ -61,18 +61,27 @@ main_namespace:
|
|||
mandatory: false
|
||||
disabled:
|
||||
jinja: >-
|
||||
{{% if 'directory' not in step.structural %}}
|
||||
directory is not in step.structural
|
||||
{{% endif %}}
|
||||
{{{{ 'directory' not in _.step.structural }}}}
|
||||
return_type: boolean
|
||||
description: directory is not in _.step.structural
|
||||
|
||||
isolated_namespace:
|
||||
description: {_("Namespaces are isolated")}
|
||||
default: true
|
||||
disabled:
|
||||
jinja: >-
|
||||
{{{{ 'directory' not in _.step.structural or not _.main_namespace }}}}
|
||||
return_type: boolean
|
||||
description: directory is not in _.step.structural or main_namespace is not set
|
||||
|
||||
extra_namespaces:
|
||||
description: {_("Extra namespaces")}
|
||||
type: leadership
|
||||
disabled:
|
||||
jinja: >-
|
||||
{{% if 'directory' not in step.structural %}}
|
||||
directory is not in step.structural
|
||||
{{% endif %}}
|
||||
{{{{ 'directory' not in _.step.structural or not _.main_namespace }}}}
|
||||
return_type: boolean
|
||||
description: directory is not in _.step.structural or main_namespace is not set
|
||||
|
||||
names:
|
||||
description: {_("Extra namespace name")}
|
||||
|
|
|
|||
0
tests/errors/00_9extra_outside/errno_38
Normal file
0
tests/errors/00_9extra_outside/errno_38
Normal file
7
tests/errors/00_9extra_outside/extra/00-base.yml
Normal file
7
tests/errors/00_9extra_outside/extra/00-base.yml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
version: '1.1'
|
||||
variable:
|
||||
description: a variable
|
||||
default:
|
||||
jinja: 'no'
|
||||
description: return no
|
||||
9
tests/errors/00_9extra_outside/extra2/00-base.yml
Normal file
9
tests/errors/00_9extra_outside/extra2/00-base.yml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
%YAML 1.2
|
||||
---
|
||||
version: 1.1
|
||||
|
||||
variable:
|
||||
description: a variable
|
||||
default:
|
||||
variable: extra.variable
|
||||
...
|
||||
0
tests/errors/00_9extra_outside/force_namespace
Normal file
0
tests/errors/00_9extra_outside/force_namespace
Normal file
3
tests/errors/00_9extra_outside/rougail/00-base.yml
Normal file
3
tests/errors/00_9extra_outside/rougail/00-base.yml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
version: '1.1'
|
||||
variable: rougail # a variable
|
||||
|
|
@ -167,3 +167,17 @@ def test_duplicate_5():
|
|||
cfg.value.get()
|
||||
with raises(ConflictError):
|
||||
cfg.option('od.od_val').value.get()
|
||||
|
||||
|
||||
def test_isolated_namespace():
|
||||
rougailconfig = RougailConfig.copy()
|
||||
rougailconfig['main_namespace'] = 'rougail'
|
||||
rougailconfig['main_structural_directories'] = ['tests/errors/00_9extra_outside/rougail/']
|
||||
rougailconfig['extra_namespaces'] = {'extra': ['tests/errors/00_9extra_outside/extra/'],
|
||||
'extra2': ['tests/errors/00_9extra_outside/extra2/'],
|
||||
}
|
||||
rougailconfig["isolated_namespace"] = False
|
||||
eolobj = Rougail(rougailconfig=rougailconfig)
|
||||
cfg = eolobj.run()
|
||||
assert cfg.option('extra.variable').value.get() == 'no'
|
||||
assert cfg.option('extra2.variable').value.get() == 'no'
|
||||
|
|
|
|||
Loading…
Reference in a new issue