Skip to content

Commit

Permalink
Fix the regular expression escapes for more recent python versions. T…
Browse files Browse the repository at this point in the history
…he strings should be raw strings eg, "((\w+)://)(.*)" -> r'((\w+)://)(.*)', otherwise the \w will be treated as an excaped unicode character.
  • Loading branch information
tmolteno committed Nov 7, 2024
1 parent 7b908b0 commit cfb1e7e
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion scabha/basetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion scabha/cargo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion scabha/configuratt/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(",")])
Expand Down
2 changes: 1 addition & 1 deletion stimela/backends/kube/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions stimela/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion stimela/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion stimela/kitchen/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])]
Expand Down
2 changes: 1 addition & 1 deletion stimela/kitchen/wranglers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit cfb1e7e

Please sign in to comment.