From cfb1e7e3f890bc624f756fb3fa9b2eb131182a38 Mon Sep 17 00:00:00 2001 From: tmolteno Date: Thu, 7 Nov 2024 07:15:51 +0200 Subject: [PATCH] Fix the regular expression escapes for more recent python versions. The strings should be raw strings eg, "((\w+)://)(.*)" -> r'((\w+)://)(.*)', otherwise the \w will be treated as an excaped unicode character. --- scabha/basetypes.py | 2 +- scabha/cargo.py | 2 +- scabha/configuratt/resolvers.py | 2 +- stimela/backends/kube/__init__.py | 2 +- stimela/commands/run.py | 4 ++-- stimela/config.py | 2 +- stimela/kitchen/recipe.py | 2 +- stimela/kitchen/wranglers.py | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scabha/basetypes.py b/scabha/basetypes.py index 7ceba11d..7a61ce4a 100644 --- a/scabha/basetypes.py +++ b/scabha/basetypes.py @@ -70,7 +70,7 @@ def parse(value: str, expand_user=True): If expand_user is True, ~ in (file-protocol) paths will be expanded. """ - match = re.fullmatch("((\w+)://)(.*)", value) + match = re.fullmatch(r'((\w+)://)(.*)', value) if not match: protocol, path, remote = "file", value, False else: diff --git a/scabha/cargo.py b/scabha/cargo.py index 46786dd2..5ff64409 100644 --- a/scabha/cargo.py +++ b/scabha/cargo.py @@ -524,7 +524,7 @@ def rich_help(self, tree, max_category=ParameterCategory.Optional): attrs.append(f"choices: {', '.join(schema.choices)}") info = [] schema.info and info.append(rich.markup.escape(schema.info)) - attrs and info.append(f"[dim]\[{rich.markup.escape(', '.join(attrs))}][/dim]") + attrs and info.append(f"[dim]\\[{rich.markup.escape(', '.join(attrs))}][/dim]") table.add_row(f"[bold]{name}[/bold]", f"[dim]{rich.markup.escape(str(schema.dtype))}[/dim]", " ".join(info)) diff --git a/scabha/configuratt/resolvers.py b/scabha/configuratt/resolvers.py index 62feee18..033a87bb 100644 --- a/scabha/configuratt/resolvers.py +++ b/scabha/configuratt/resolvers.py @@ -218,7 +218,7 @@ def load_include_files(keyword): if not incl: raise ConfigurattError(f"{errloc}: empty {keyword} specifier") # check for [flags] at end of specifier - match = re.match("^(.*)\[(.*)\]$", incl) + match = re.match(r'^(.*)\[(.*)\]$', incl) if match: incl = match.group(1) flags = set([x.strip().lower() for x in match.group(2).split(",")]) diff --git a/stimela/backends/kube/__init__.py b/stimela/backends/kube/__init__.py index fbeb8c5a..af0c6ea3 100644 --- a/stimela/backends/kube/__init__.py +++ b/stimela/backends/kube/__init__.py @@ -195,7 +195,7 @@ class DebugOptions(object): # if >0, events will be collected and reported log_events: bool = False # format string for reporting kubernetes events, this can include rich markup - event_format: str = "=NOSUBST('\[k8s event type: {event.type}, reason: {event.reason}] {event.message}')" + event_format: str = "=NOSUBST('\\[k8s event type: {event.type}, reason: {event.reason}] {event.message}')" event_colors: Dict[str, str] = DictDefault( warning="blue", error="yellow", default="grey50") diff --git a/stimela/commands/run.py b/stimela/commands/run.py index 4b88ef40..1ea7126e 100644 --- a/stimela/commands/run.py +++ b/stimela/commands/run.py @@ -46,7 +46,7 @@ def resolve_recipe_file(filename: str): # check for (location)filename.yml or (location)/filename.yml style match1 = re.fullmatch("^\\((.+)\\)/?(.+)$", filename) - match2 = re.fullmatch("^([\w.]+)::(.+)$", filename) + match2 = re.fullmatch(r"^([\w.]+)::(.+)$", filename) if match1 or match2: modulename, fname = (match1 or match2).groups() try: @@ -84,7 +84,7 @@ def load_recipe_files(filenames: List[str]): for filename in filenames: # check for (location)filename.yaml or (location)/filename.yaml style match1 = re.fullmatch("^\\((.+)\\)/?(.+)$", filename) - match2 = re.fullmatch("^([\w.]+)::(.+)$", filename) + match2 = re.fullmatch(r"^([\w.]+)::(.+)$", filename) if match1 or match2: modulename, filename = (match1 or match2).groups() try: diff --git a/stimela/config.py b/stimela/config.py index 7e439ad0..a535c44b 100644 --- a/stimela/config.py +++ b/stimela/config.py @@ -272,7 +272,7 @@ def _load(conf, config_file): ncpu=psutil.cpu_count(logical=True), node=platform.node().split('.', 1)[0], hostname=platform.node(), - env={key: value.replace('${', '\${') for key, value in os.environ.items()}) + env={key: value.replace('${', r'\${') for key, value in os.environ.items()}) runtime['ncpu-logical'] = psutil.cpu_count(logical=True) runtime['ncpu-physical'] = psutil.cpu_count(logical=False) diff --git a/stimela/kitchen/recipe.py b/stimela/kitchen/recipe.py index 8f7ec6c6..d63750c0 100644 --- a/stimela/kitchen/recipe.py +++ b/stimela/kitchen/recipe.py @@ -506,7 +506,7 @@ def _add_alias(self, alias_name: str, alias_target: Union[str, Tuple], alias_target = alias_target.replace("$", alias_name.rsplit('.', 1)[-1]) step_spec, step_param_name = alias_target.split('.', 1) # treat label as a "(cabtype)" specifier? - if re.match('^\(.+\)$', step_spec): + if re.match(r'^\(.+\)$', step_spec): steps = [(label, step) for label, step in self.steps.items() if (isinstance(step.cargo, Cab) and step.cab == step_spec[1:-1]) or (isinstance(step.cargo, Recipe) and step.recipe == step_spec[1:-1])] diff --git a/stimela/kitchen/wranglers.py b/stimela/kitchen/wranglers.py index bbb3f2a0..abc22693 100644 --- a/stimela/kitchen/wranglers.py +++ b/stimela/kitchen/wranglers.py @@ -204,7 +204,7 @@ def __init__(self, regex: re.Pattern, spec: str, name: Optional[str], group: str self.name = name or group if group in regex.groupindex: self.gid = group - elif re.fullmatch('\d+', group): + elif re.fullmatch(r'\d+', group): gid = int(group) if gid > regex.groups: raise CabValidationError(f"wrangler action '{spec}' for '{regex.pattern}': {gid} is not a valid ()-group")