fix: black

This commit is contained in:
egarette@silique.fr 2025-05-11 19:10:08 +02:00
parent 7646c85546
commit 58677d06c0
4 changed files with 64 additions and 43 deletions

View file

@ -3,4 +3,4 @@ from .__version__ import __version__
RougailUserData = RougailUserDataEnvironment RougailUserData = RougailUserDataEnvironment
__all__ = ('RougailUserDataEnvironment',) __all__ = ("RougailUserDataEnvironment",)

View file

@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
""" """
from rougail.error import DictConsistencyError from rougail.error import DictConsistencyError
from rougail.annotator.variable import Walk from rougail.annotator.variable import Walk
from .i18n import _ from .i18n import _
@ -25,9 +26,9 @@ from .i18n import _
class Annotator(Walk): class Annotator(Walk):
"""Annotate for environment""" """Annotate for environment"""
level = 95 level = 95
def __init__( def __init__(
self, self,
objectspace, objectspace,
@ -42,11 +43,19 @@ class Annotator(Walk):
def check_family(self): def check_family(self):
for family in self.get_families(): for family in self.get_families():
if family.name != family.name.lower(): if family.name != family.name.lower():
msg = _('family name must be a lowercase name when we want to use user data "environment", so "{0}" is invalid') msg = _(
raise DictConsistencyError(msg.format(family.name), 200, family.xmlfiles) 'family name must be a lowercase name when we want to use user data "environment", so "{0}" is invalid'
)
raise DictConsistencyError(
msg.format(family.name), 200, family.xmlfiles
)
def check_variable(self): def check_variable(self):
for variable in self.get_variables(): for variable in self.get_variables():
if variable.name != variable.name.lower(): if variable.name != variable.name.lower():
msg = _('variable name must be a lowercase name when we want to use user data "environment", so "{0}" is invalid') msg = _(
raise DictConsistencyError(msg.format(variable.name), 201, variable.xmlfiles) 'variable name must be a lowercase name when we want to use user data "environment", so "{0}" is invalid'
)
raise DictConsistencyError(
msg.format(variable.name), 201, variable.xmlfiles
)

View file

@ -22,9 +22,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
""" """
def get_rougail_config(*, def get_rougail_config(
backward_compatibility=True, *,
) -> dict: backward_compatibility=True,
) -> dict:
options = """ options = """
environment: environment:
description: Define values from the environment description: Define values from the environment
@ -40,11 +41,12 @@ environment:
variable: main_namespace variable: main_namespace
when_not: null when_not: null
""" """
return {'name': 'environment', return {
'process': 'user data', "name": "environment",
'options': options, "process": "user data",
'level': 50, "options": options,
} "level": 50,
}
__all__ = ('get_rougail_config',) __all__ = ("get_rougail_config",)

View file

@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
""" """
import os import os
from rougail.object_model import CONVERT_OPTION from rougail.object_model import CONVERT_OPTION
from rougail.config import RougailConfig from rougail.config import RougailConfig
@ -26,36 +27,41 @@ from tiramisu.error import ValueOptionError
class RougailUserDataEnvironment: class RougailUserDataEnvironment:
def __init__(self, def __init__(
config: 'Config', self,
*, config: "Config",
rougailconfig: RougailConfig=None, *,
): rougailconfig: RougailConfig = None,
):
# this is the tiramisu config object # this is the tiramisu config object
self.config = config self.config = config
if rougailconfig is None: if rougailconfig is None:
rougailconfig = RougailConfig rougailconfig = RougailConfig
user_data = rougailconfig['step.user_data'] user_data = rougailconfig["step.user_data"]
if 'environment' not in user_data: if "environment" not in user_data:
user_data.append('environment') user_data.append("environment")
rougailconfig['step.user_data'] = user_data rougailconfig["step.user_data"] = user_data
user_data = rougailconfig['step.user_data'] user_data = rougailconfig["step.user_data"]
self.rougailconfig = rougailconfig self.rougailconfig = rougailconfig
if 'environment' not in user_data: if "environment" not in user_data:
raise ExtentionError('environment is not set in step.user_data') raise ExtentionError("environment is not set in step.user_data")
self.errors = [] self.errors = []
self.warnings = [] self.warnings = []
def run(self): def run(self):
values = self.parse() values = self.parse()
return [{'source': 'environment variable', return [
'errors': self.errors, {
'warnings': self.warnings, "source": "environment variable",
'values': values, "errors": self.errors,
'options': {'multi_separator': ',', "warnings": self.warnings,
'needs_convert': True, "values": values,
}, "options": {
}] "multi_separator": ",",
"needs_convert": True,
},
}
]
def parse(self): def parse(self):
variables = {} variables = {}
@ -65,23 +71,27 @@ class RougailUserDataEnvironment:
variables.update(get_rougail_environment(option.name())) variables.update(get_rougail_environment(option.name()))
else: else:
return variables return variables
return get_rougail_environment(None, self.rougailconfig['environment.default_environment_name']) return get_rougail_environment(
None, self.rougailconfig["environment.default_environment_name"]
)
def get_rougail_environment(namespace, environment_name=None): def get_rougail_environment(namespace, environment_name=None):
"""gets all the rougail environment variables and their values """gets all the rougail environment variables and their values
:sample: {'VARINT': '5', 'VARNAME34': '58, 22', 'VARNAME2': 'tata', :sample: {'VARINT': '5', 'VARNAME34': '58, 22', 'VARNAME2': 'tata',
'VARNAME1': 'titi', 'MYFAMILY.VARNAME3': 'spam'} 'VARNAME1': 'titi', 'MYFAMILY.VARNAME3': 'spam'}
:returns: rougail environment variables as a key/value dict :returns: rougail environment variables as a key/value dict
""" """
# then we filter the ROUGAIL_ environment variables # then we filter the ROUGAIL_ environment variables
if namespace is None: if namespace is None:
rougail_environment_var = environment_name.upper() + '_' rougail_environment_var = environment_name.upper() + "_"
len_env = len(rougail_environment_var) len_env = len(rougail_environment_var)
else: else:
rougail_environment_var = namespace.upper() + '.' rougail_environment_var = namespace.upper() + "."
len_env = 0 len_env = 0
return {envvar[len_env:].lower(): envval return {
for envvar, envval in os.environ.items() envvar[len_env:].lower(): envval
if envvar.startswith(rougail_environment_var)} for envvar, envval in os.environ.items()
if envvar.startswith(rougail_environment_var)
}