From 347e7237f89e23ff163844297bc3fe3092f09558 Mon Sep 17 00:00:00 2001 From: Alex Myers Date: Thu, 6 Apr 2023 14:37:24 -0500 Subject: [PATCH] reckless: match name using installer entry formats When enabling or disabling a plugin, the entrypoint is inferred from the user provided name. A canonical name should be used, which the installer entrypoint formats help to determine (this generally strips the file extension if one is provided.) --- tools/reckless | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tools/reckless b/tools/reckless index dcca8f18d..aed2e8197 100755 --- a/tools/reckless +++ b/tools/reckless @@ -322,8 +322,23 @@ class InferInstall(): """Once a plugin is installed, we may need its directory and entrypoint""" def __init__(self, name: str): reck_contents = os.listdir(RECKLESS_CONFIG.reckless_dir) - if name[-3:] == '.py' or name[-3:] == '.js': - name = name[:-3] + + def match_name(name) -> str: + for tier in range(0, 10): + # Look for each installers preferred entrypoint format first + for n, inst in INSTALLERS.items(): + fmt = inst.entries[tier] + if '{name}' in fmt: + pre = fmt.split('{name}')[0] + post = fmt.split('{name}')[-1] + if name.startswith(pre) and name.endswith(post): + return name.lstrip(pre).rstrip(post) + else: + if fmt == name: + return name + return name + + name = match_name(name) if name in reck_contents: self.dir = Path(RECKLESS_CONFIG.reckless_dir).joinpath(name) else: