Compare commits
No commits in common. "a4c1d36d6c8236a9471bfd8a3486ce9476410e1e244bb232edfbd5c1de2647b5" and "878fc246dd4f8b8462f4c3880bbb448f3459320f7919ebb07a931751c63c4a96" have entirely different histories.
a4c1d36d6c
...
878fc246dd
17 changed files with 24 additions and 156 deletions
|
|
@ -24,3 +24,4 @@ RougailOutput = RougailOutputEnvironment
|
|||
|
||||
|
||||
__all__ = ("RougailOutputEnvironment", "__version__")
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
src/rougail/output_environment/__pycache__/env.cpython-314.pyc
Normal file
BIN
src/rougail/output_environment/__pycache__/env.cpython-314.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/rougail/output_environment/__pycache__/i18n.cpython-314.pyc
Normal file
BIN
src/rougail/output_environment/__pycache__/i18n.cpython-314.pyc
Normal file
Binary file not shown.
|
|
@ -1,3 +1 @@
|
|||
# version of this module, use for example in rougail commandline to display versions
|
||||
# (with --cli.versions option)
|
||||
__version__ = "0.1.0"
|
||||
|
|
|
|||
|
|
@ -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/>.
|
||||
"""
|
||||
|
||||
|
||||
from .i18n import _
|
||||
|
||||
|
||||
|
|
@ -23,8 +24,7 @@ def get_rougail_config(
|
|||
*,
|
||||
backward_compatibility=True,
|
||||
) -> dict:
|
||||
options = [
|
||||
f"""
|
||||
options = [f"""
|
||||
environment:
|
||||
exists: true
|
||||
redefine: true
|
||||
|
|
@ -36,8 +36,7 @@ environment:
|
|||
return_type: boolean
|
||||
description: >-
|
||||
{_('if environment is not in "step.output" and not in "step.user_data"')}
|
||||
""",
|
||||
f"""
|
||||
""", f"""
|
||||
environment:
|
||||
exists: false
|
||||
type: family
|
||||
|
|
@ -52,8 +51,7 @@ environment:
|
|||
variable: step.output
|
||||
when_not: environment
|
||||
propertyerror: false
|
||||
""",
|
||||
f"""
|
||||
""", f"""
|
||||
environment:
|
||||
|
||||
output:
|
||||
|
|
@ -119,8 +117,7 @@ environment:
|
|||
{{% endif %}}
|
||||
description: >-
|
||||
{_('if "_.multi_in_array" the value is ";" otherwise the value is ","')}
|
||||
""",
|
||||
]
|
||||
"""]
|
||||
|
||||
return {
|
||||
"name": "environment",
|
||||
|
|
|
|||
|
|
@ -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/>.
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from shlex import quote
|
||||
from rougail.error import ExtensionError
|
||||
|
||||
|
|
@ -26,7 +24,6 @@ from .i18n import _
|
|||
|
||||
|
||||
class RougailOutputEnvironment:
|
||||
"""Rougail output that generate environment variables"""
|
||||
output_name = "environment"
|
||||
|
||||
def __init__(
|
||||
|
|
@ -70,23 +67,15 @@ class RougailOutputEnvironment:
|
|||
else:
|
||||
self.booleans = {True: 1, False: 0}
|
||||
self.upper = self.rougailconfig["environment.output.upper"]
|
||||
self.path_is_variable_name = self.rougailconfig[
|
||||
"environment.output.path_is_variable_name"
|
||||
]
|
||||
self.path_is_variable_name = self.rougailconfig["environment.output.path_is_variable_name"]
|
||||
if self.path_is_variable_name:
|
||||
self.custom_separator = self.rougailconfig[
|
||||
"environment.output.custom_separator"
|
||||
]
|
||||
self.custom_separator = self.rougailconfig["environment.output.custom_separator"]
|
||||
else:
|
||||
self.custom_separator = None
|
||||
self.multi_in_array = self.rougailconfig["environment.output.multi_in_array"]
|
||||
if not self.multi_in_array:
|
||||
self.multi_separator = self.rougailconfig[
|
||||
"environment.output.multi_separator"
|
||||
]
|
||||
self.submulti_separator = self.rougailconfig[
|
||||
"environment.output.submulti_separator"
|
||||
]
|
||||
self.multi_separator = self.rougailconfig["environment.output.multi_separator"]
|
||||
self.submulti_separator = self.rougailconfig["environment.output.submulti_separator"]
|
||||
ret = self.exporter()
|
||||
if isinstance(self.dico, str):
|
||||
value = self.dico
|
||||
|
|
@ -168,10 +157,8 @@ class RougailOutputEnvironment:
|
|||
|
||||
def set_value(self, name, values):
|
||||
if name in self.dico:
|
||||
raise ExtensionError(
|
||||
_('The variable name "{0}" is duplicated').format(name)
|
||||
)
|
||||
self.dico[name] = f"{name}={self.conv_values(name, values)}"
|
||||
raise ExtensionError(_('The variable name "{0}" is duplicated').format(name))
|
||||
self.dico[name] = f'{name}={self.conv_values(name, values)}'
|
||||
|
||||
def conv_values(self, name, values):
|
||||
if isinstance(values, list):
|
||||
|
|
@ -188,22 +175,12 @@ class RougailOutputEnvironment:
|
|||
for value in values:
|
||||
value = self.conv_to_string(value)
|
||||
if self.submulti_separator in value:
|
||||
raise ExtensionError(
|
||||
_(
|
||||
'the character "{0}" is a sub multi separator, '
|
||||
'this character must not in the "{1}" value'
|
||||
).format(self.submulti_separator, name)
|
||||
)
|
||||
raise ExtensionError(_('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)
|
||||
values = self.submulti_separator.join(new_values)
|
||||
values = self.conv_to_string(values)
|
||||
if not self.multi_in_array and self.multi_separator in values:
|
||||
raise ExtensionError(
|
||||
_(
|
||||
'the character "{0}" is a multi separator, '
|
||||
'this character must not in the "{1}" value'
|
||||
).format(self.multi_separator, name)
|
||||
)
|
||||
raise ExtensionError(_('the character "{0}" is a multi separator, this character must not in the "{1}" value').format(self.multi_separator, name))
|
||||
return quote(values)
|
||||
|
||||
def conv_to_string(self, values):
|
||||
|
|
@ -230,15 +207,10 @@ class RougailOutputEnvironment:
|
|||
if not follower_name:
|
||||
follower_name = self.get_name(follower)
|
||||
followers_name[follower_path] = follower_name
|
||||
followers_data.setdefault(follower_name, {})[
|
||||
follower.index()
|
||||
] = follower.value.get()
|
||||
followers_data.setdefault(follower_name, {})[follower.index()] = follower.value.get()
|
||||
leader_len = len(leader_values)
|
||||
for name, values in followers_data.items():
|
||||
self.set_value(
|
||||
name,
|
||||
[values[idx] if idx in values else "" for idx in range(leader_len)],
|
||||
)
|
||||
self.set_value(name, [values[idx] if idx in values else "" for idx in range(leader_len)])
|
||||
|
||||
|
||||
RougailOutput = RougailOutputEnvironment
|
||||
|
|
|
|||
BIN
tests/__pycache__/test_load.cpython-314-pytest-8.3.5.pyc
Normal file
BIN
tests/__pycache__/test_load.cpython-314-pytest-8.3.5.pyc
Normal file
Binary file not shown.
|
|
@ -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
|
||||
...
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
%YAML 1.2
|
||||
---
|
||||
version: 1.1
|
||||
|
||||
variable: # A variable
|
||||
- val1
|
||||
- val;2
|
||||
...
|
||||
|
|
@ -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
|
||||
...
|
||||
|
|
@ -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
|
||||
...
|
||||
|
|
@ -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"))
|
||||
|
|
@ -1,10 +1,13 @@
|
|||
import os
|
||||
from pytest import fixture, raises
|
||||
from pathlib import Path
|
||||
from pytest import fixture
|
||||
from rougail_tests.utils import get_structures_list, get_rougail_config, get_values_for_config
|
||||
from rougail import Rougail, RougailConfig
|
||||
#########################
|
||||
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"
|
||||
|
||||
|
|
@ -61,7 +64,7 @@ def _test_structural_files(test_dir, namespace, ext, change=False):
|
|||
with output_file.open('w') as outfh:
|
||||
outfh.write(generated_output)
|
||||
with output_file.open() as outfh:
|
||||
attented_output = outfh.read()
|
||||
attented_output = outfh.read()
|
||||
assert generated_output == attented_output, f'filename {output_file}'
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue