diff --git a/fxconv/fxconv.py b/fxconv/fxconv.py index 014a04a..5d9aa47 100644 --- a/fxconv/fxconv.py +++ b/fxconv/fxconv.py @@ -1178,11 +1178,7 @@ def convert(input, params, target, output=None, model=None, custom=None): if output is None: output = os.path.splitext(input)[0] + ".o" - if "name" in params: - pass - elif "name_regex" in params: - params["name"] = re.sub(*params["name_regex"], os.path.basename(input)) - else: + if "name" not in params: raise FxconvError(f"no name specified for conversion '{input}'") if target["arch"] is None: @@ -1448,7 +1444,8 @@ class Metadata: def rules_for(self, path): """ Returns the parameters that apply to the specified path, or None if no - wildcard matches it. + wildcard matches it. The special key "name_regex" is also resolved into + the regular key "name". """ basename = os.path.basename(path) @@ -1460,4 +1457,9 @@ class Metadata: params.update(**p) matched = True - return params if matched else None + if not matched: + return None + + if "name_regex" in params and not "name" in params: + params["name"] = re.sub(*params["name_regex"], basename) + return params