Compare commits

..

No commits in common. "a4c1d36d6c8236a9471bfd8a3486ce9476410e1e244bb232edfbd5c1de2647b5" and "878fc246dd4f8b8462f4c3880bbb448f3459320f7919ebb07a931751c63c4a96" have entirely different histories.

17 changed files with 24 additions and 156 deletions

View file

@ -24,3 +24,4 @@ RougailOutput = RougailOutputEnvironment
__all__ = ("RougailOutputEnvironment", "__version__") __all__ = ("RougailOutputEnvironment", "__version__")

View file

@ -1,3 +1 @@
# version of this module, use for example in rougail commandline to display versions
# (with --cli.versions option)
__version__ = "0.1.0" __version__ = "0.1.0"

View file

@ -16,6 +16,7 @@ You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
from .i18n import _ from .i18n import _
@ -23,8 +24,7 @@ def get_rougail_config(
*, *,
backward_compatibility=True, backward_compatibility=True,
) -> dict: ) -> dict:
options = [ options = [f"""
f"""
environment: environment:
exists: true exists: true
redefine: true redefine: true
@ -36,8 +36,7 @@ environment:
return_type: boolean return_type: boolean
description: >- description: >-
{_('if environment is not in "step.output" and not in "step.user_data"')} {_('if environment is not in "step.output" and not in "step.user_data"')}
""", """, f"""
f"""
environment: environment:
exists: false exists: false
type: family type: family
@ -52,8 +51,7 @@ environment:
variable: step.output variable: step.output
when_not: environment when_not: environment
propertyerror: false propertyerror: false
""", """, f"""
f"""
environment: environment:
output: output:
@ -119,9 +117,8 @@ environment:
{{% endif %}} {{% endif %}}
description: >- description: >-
{_('if "_.multi_in_array" the value is ";" otherwise the value is ","')} {_('if "_.multi_in_array" the value is ";" otherwise the value is ","')}
""", """]
]
return { return {
"name": "environment", "name": "environment",
"process": "output", "process": "output",

View file

@ -16,8 +16,6 @@ You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
from typing import Optional
from shlex import quote from shlex import quote
from rougail.error import ExtensionError from rougail.error import ExtensionError
@ -26,7 +24,6 @@ from .i18n import _
class RougailOutputEnvironment: class RougailOutputEnvironment:
"""Rougail output that generate environment variables"""
output_name = "environment" output_name = "environment"
def __init__( def __init__(
@ -70,23 +67,15 @@ class RougailOutputEnvironment:
else: else:
self.booleans = {True: 1, False: 0} self.booleans = {True: 1, False: 0}
self.upper = self.rougailconfig["environment.output.upper"] self.upper = self.rougailconfig["environment.output.upper"]
self.path_is_variable_name = self.rougailconfig[ self.path_is_variable_name = self.rougailconfig["environment.output.path_is_variable_name"]
"environment.output.path_is_variable_name"
]
if self.path_is_variable_name: if self.path_is_variable_name:
self.custom_separator = self.rougailconfig[ self.custom_separator = self.rougailconfig["environment.output.custom_separator"]
"environment.output.custom_separator"
]
else: else:
self.custom_separator = None self.custom_separator = None
self.multi_in_array = self.rougailconfig["environment.output.multi_in_array"] self.multi_in_array = self.rougailconfig["environment.output.multi_in_array"]
if not self.multi_in_array: if not self.multi_in_array:
self.multi_separator = self.rougailconfig[ self.multi_separator = self.rougailconfig["environment.output.multi_separator"]
"environment.output.multi_separator" self.submulti_separator = self.rougailconfig["environment.output.submulti_separator"]
]
self.submulti_separator = self.rougailconfig[
"environment.output.submulti_separator"
]
ret = self.exporter() ret = self.exporter()
if isinstance(self.dico, str): if isinstance(self.dico, str):
value = self.dico value = self.dico
@ -168,10 +157,8 @@ class RougailOutputEnvironment:
def set_value(self, name, values): def set_value(self, name, values):
if name in self.dico: if name in self.dico:
raise ExtensionError( raise ExtensionError(_('The variable name "{0}" is duplicated').format(name))
_('The variable name "{0}" is duplicated').format(name) self.dico[name] = f'{name}={self.conv_values(name, values)}'
)
self.dico[name] = f"{name}={self.conv_values(name, values)}"
def conv_values(self, name, values): def conv_values(self, name, values):
if isinstance(values, list): if isinstance(values, list):
@ -188,22 +175,12 @@ class RougailOutputEnvironment:
for value in values: for value in values:
value = self.conv_to_string(value) value = self.conv_to_string(value)
if self.submulti_separator in value: if self.submulti_separator in value:
raise ExtensionError( raise ExtensionError(_('the character "{0}" is a sub multi separator, this character must not in the "{1}" value').format(self.submulti_separator, name))
_(
'the character "{0}" is a sub multi separator, '
'this character must not in the "{1}" value'
).format(self.submulti_separator, name)
)
new_values.append(value) new_values.append(value)
values = self.submulti_separator.join(new_values) values = self.submulti_separator.join(new_values)
values = self.conv_to_string(values) values = self.conv_to_string(values)
if not self.multi_in_array and self.multi_separator in values: if not self.multi_in_array and self.multi_separator in values:
raise ExtensionError( raise ExtensionError(_('the character "{0}" is a multi separator, this character must not in the "{1}" value').format(self.multi_separator, name))
_(
'the character "{0}" is a multi separator, '
'this character must not in the "{1}" value'
).format(self.multi_separator, name)
)
return quote(values) return quote(values)
def conv_to_string(self, values): def conv_to_string(self, values):
@ -230,15 +207,10 @@ class RougailOutputEnvironment:
if not follower_name: if not follower_name:
follower_name = self.get_name(follower) follower_name = self.get_name(follower)
followers_name[follower_path] = follower_name followers_name[follower_path] = follower_name
followers_data.setdefault(follower_name, {})[ followers_data.setdefault(follower_name, {})[follower.index()] = follower.value.get()
follower.index()
] = follower.value.get()
leader_len = len(leader_values) leader_len = len(leader_values)
for name, values in followers_data.items(): for name, values in followers_data.items():
self.set_value( self.set_value(name, [values[idx] if idx in values else "" for idx in range(leader_len)])
name,
[values[idx] if idx in values else "" for idx in range(leader_len)],
)
RougailOutput = RougailOutputEnvironment RougailOutput = RougailOutputEnvironment

View file

@ -1,12 +0,0 @@
%YAML 1.2
---
version: 1.1
family_1: # A family
variable: # A variable
family_2: # An other family
variable: # A variable
...

View file

@ -1,8 +0,0 @@
%YAML 1.2
---
version: 1.1
variable: # A variable
- val1
- val;2
...

View file

@ -1,20 +0,0 @@
%YAML 1.2
---
version: 1.1
sequence:
description: A sequence
type: sequence
variable1:
description: A variable 1
default:
- val1
- val2
variable2:
description: A variable 2
default:
- val1
- val;2
...

View file

@ -1,20 +0,0 @@
%YAML 1.2
---
version: 1.1
sequence:
description: A sequence
type: sequence
variable1:
description: A variable 1
default:
- val1
- val2
variable2:
description: A variable 2
default:
- val1
- val,2
...

View file

@ -1,43 +0,0 @@
from pathlib import Path
from pytest import raises
from rougail_tests.utils import get_rougail_config, get_values_for_config
#########################
from rougail.output_environment import RougailOutputEnvironment as RougailOutput
#########################
from rougail.error import ExtensionError
from rougail import Rougail
def _test_error(test_dir):
rougailconfig = get_rougail_config(test_dir, False)
if not rougailconfig:
return
# rougailconfig['tiramisu_cache'] = "cache.py"
##################################
rougailconfig['step.output'] = 'environment'
rougailconfig["environment.output.path_is_variable_name"] = False
rougailconfig["environment.output.multi_in_array"] = False
##################################
rougail = Rougail(rougailconfig)
config = rougail.run()
##################################
get_values_for_config(config, level="mandatory")
##################################
with raises(ExtensionError):
RougailOutput(config, rougailconfig=rougailconfig).run()
def test_error_duplicate():
_test_error(Path("tests/errors/duplicate"))
def test_error_multi_separator():
_test_error(Path("tests/errors/multi_separator"))
def test_error_multi_separator2():
_test_error(Path("tests/errors/multi_separator2"))
def test_error_submulti_separator():
_test_error(Path("tests/errors/submulti_separator"))

View file

@ -1,10 +1,13 @@
import os
from pytest import fixture, raises
from pathlib import Path from pathlib import Path
from pytest import fixture from rougail import Rougail, RougailConfig
from rougail_tests.utils import get_structures_list, get_rougail_config, get_values_for_config
######################### #########################
from rougail.output_environment import RougailOutputEnvironment as RougailOutput from rougail.output_environment import RougailOutputEnvironment as RougailOutput
from json import load, dump
######################### #########################
from rougail import Rougail
from rougail_tests.utils import get_structures_list, get_rougail_config, get_values_for_config, config_to_dict
EXT = "env" EXT = "env"
@ -61,7 +64,7 @@ def _test_structural_files(test_dir, namespace, ext, change=False):
with output_file.open('w') as outfh: with output_file.open('w') as outfh:
outfh.write(generated_output) outfh.write(generated_output)
with output_file.open() as outfh: with output_file.open() as outfh:
attented_output = outfh.read() attented_output = outfh.read()
assert generated_output == attented_output, f'filename {output_file}' assert generated_output == attented_output, f'filename {output_file}'