diff --git a/src/rougail/convert/convert.py b/src/rougail/convert/convert.py index 509650b0c..e5e9b0a06 100644 --- a/src/rougail/convert/convert.py +++ b/src/rougail/convert/convert.py @@ -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 = {".": []} diff --git a/src/rougail/convert/path.py b/src/rougail/convert/path.py index 2d29b5baf..740e4a9f6 100644 --- a/src/rougail/convert/path.py +++ b/src/rougail/convert/path.py @@ -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 ): diff --git a/src/rougail/structural_directory/__init__.py b/src/rougail/structural_directory/__init__.py index 6a4f9ff7b..5f494daee 100644 --- a/src/rougail/structural_directory/__init__.py +++ b/src/rougail/structural_directory/__init__.py @@ -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"], diff --git a/src/rougail/structural_directory/config.py b/src/rougail/structural_directory/config.py index f1805d46a..d36561da1 100644 --- a/src/rougail/structural_directory/config.py +++ b/src/rougail/structural_directory/config.py @@ -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")} diff --git a/tests/errors/00_9extra_outside/errno_38 b/tests/errors/00_9extra_outside/errno_38 new file mode 100644 index 000000000..e69de29bb diff --git a/tests/errors/00_9extra_outside/extra/00-base.yml b/tests/errors/00_9extra_outside/extra/00-base.yml new file mode 100644 index 000000000..0416ef6b2 --- /dev/null +++ b/tests/errors/00_9extra_outside/extra/00-base.yml @@ -0,0 +1,7 @@ +--- +version: '1.1' +variable: + description: a variable + default: + jinja: 'no' + description: return no diff --git a/tests/errors/00_9extra_outside/extra2/00-base.yml b/tests/errors/00_9extra_outside/extra2/00-base.yml new file mode 100644 index 000000000..4bbbce8ad --- /dev/null +++ b/tests/errors/00_9extra_outside/extra2/00-base.yml @@ -0,0 +1,9 @@ +%YAML 1.2 +--- +version: 1.1 + +variable: + description: a variable + default: + variable: extra.variable +... diff --git a/tests/errors/00_9extra_outside/force_namespace b/tests/errors/00_9extra_outside/force_namespace new file mode 100644 index 000000000..e69de29bb diff --git a/tests/errors/00_9extra_outside/rougail/00-base.yml b/tests/errors/00_9extra_outside/rougail/00-base.yml new file mode 100644 index 000000000..4f64b4402 --- /dev/null +++ b/tests/errors/00_9extra_outside/rougail/00-base.yml @@ -0,0 +1,3 @@ +--- +version: '1.1' +variable: rougail # a variable diff --git a/tests/test_others.py b/tests/test_others.py index 9e2a5fdce..31f019e75 100644 --- a/tests/test_others.py +++ b/tests/test_others.py @@ -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'