def _get_dest_editors(self, target_arg=None): """ Inspects the target/destination of the command argument to determine which VSCode-like editor(s) are the intended target for which to check for outdated extensions. This function uses fuzzy matching with a pre-determined threshold to find matching code editor names that match enough to be considered the intended target editor destinations. The purpose of this is to allow a small amount of leeway in what target names the user provides and how the program interprets them. For instance, with a fuzzy-matching threshold of 85% (the default), a user could provide an intended target of 'code', 'vscode', 'vs.code', or 'vs-code', and each of those values would resolve to the base Visual Studio Code editor. In the event that the target editor is not able to be resolved to the name of a known, supported code editor, then no value is added to the set of resolved targets. Keyword Arguments: target_arg {list} -- A list of strings to compare against the names of known, supported code editors. (default: []) Returns: set -- A unique set of matching code editor names. """ targets = set() target_arg = target_arg or [] for target in target_arg: # find the single best match from the list of known, supported # code editors (that matches above the specified threshold) try: match, _ = process.extractOne( query=target, choices=_AVAILABLE_EDITOR_VALUES, score_cutoff=_FUZZY_SORT_CONFIDENCE_THRESHOLD) # We don't want the value in this instance, we want the key, # so find the key that's associated with the value match. match = list(SupportedEditorCommands.keys())[ list(SupportedEditorCommands.values()).index(match)] # If we couldn't find a match using the editor values themselves, # we'll check for a fuzzy match using the supported editor keys except TypeError: try: match, _ = process.extractOne( query=target, choices=_AVAILABLE_EDITOR_KEYS, score_cutoff=_FUZZY_SORT_CONFIDENCE_THRESHOLD) # If we still couldn't find a match, then we'll just move # on to the next item in the list of targets. except TypeError: continue # Add the match to the running set of matched targets targets.add(match) return targets
from fuzzywuzzy import process from rich.console import Console from rich.table import Table from rich import box from pyvem._command import Command from pyvem._config import _PROG, rich_theme from pyvem._help import Help from pyvem._editor import SupportedEditorCommands, get_editors from pyvem._logging import get_rich_logger _FUZZY_SORT_CONFIDENCE_THRESHOLD = 85 _AVAILABLE_EDITOR_KEYS = SupportedEditorCommands.keys() _AVAILABLE_EDITOR_VALUES = SupportedEditorCommands.values() _console = Console(theme=rich_theme) _LOGGER = get_rich_logger(__name__, console=_console) _HELP = Help( name='outdated', brief='Show extensions that can be updated', synopsis=f'{_PROG} outdated\n' f'{_PROG} outdated [[<extension> ...]]\n' f'{_PROG} outdated [[<extension> ...]] [[--<editor>]]\n' f'{_PROG} outdated [[--<editor>]]\n' f'{_PROG} outdated [[--editors]]\n' f'{_PROG} outdated [[--all-editors]]\n\n' f'[h2]aliases:[/h2] {_PROG} dated, {_PROG} old\n', description='This command will check the VSCode Marketplace to see if any (or, specific) '