improve variable naming/fix shadowed function name

This commit is contained in:
riscy 2020-12-28 15:59:31 -08:00
parent bb1569facd
commit 243e1feea1

View file

@ -534,13 +534,13 @@ def _print_package_requires(recipe: str, elisp_dir: str):
) )
def print_similar_packages(package_name: str): def print_similar_packages(name: str):
"""Print list of similar, or at least similarly named, packages.""" """Print list of similar, or at least similarly named, packages."""
keywords = [package_name] keywords = [name]
keywords += [re.sub(r'[0-9]', '', package_name)] keywords += [re.sub(r'[0-9]', '', name)]
keywords += [package_name[:-5]] if package_name.endswith('-mode') else [] keywords += [name[:-5]] if name.endswith('-mode') else []
keywords += ['org-' + package_name[3:]] if package_name.startswith('ox-') else [] keywords += ['org-' + name[3:]] if name.startswith('ox-') else []
keywords += ['ox-' + package_name[4:]] if package_name.startswith('org-') else [] keywords += ['ox-' + name[4:]] if name.startswith('org-') else []
all_candidates = { all_candidates = {
**emacsattic_packages(keywords), **emacsattic_packages(keywords),
**emacswiki_packages(keywords), **emacswiki_packages(keywords),
@ -548,21 +548,22 @@ def print_similar_packages(package_name: str):
**elpa_packages(keywords), **elpa_packages(keywords),
**melpa_packages(keywords), **melpa_packages(keywords),
} }
best_candidates = [] top_candidates = [
for candidate in all_candidates: (name_, url)
if any(keyword in candidate for keyword in keywords): for name_, url in all_candidates.items()
best_candidates.append(candidate) if any(keyword in name_ for keyword in keywords)
if not best_candidates: ][:10]
if not top_candidates:
return return
_note('### Similarly named ###\n', CLR_INFO) _note('### Similarly named ###\n', CLR_INFO)
for name in best_candidates[:10]: for name_, url in top_candidates:
print(f"- {name}: {all_candidates[name]}") print(f"- {name_}: {url}")
if package_name in all_candidates: if name in all_candidates:
_fail(f"- Error: package '{package_name}' already exists!", highlight='Error:') _fail(f"- Error: package '{name}' already exists!", highlight='Error:')
# helm asks some add-on functions use a `helm-source-` prefix # helm asks some add-on functions use a `helm-source-` prefix
# and org-mode asks some add-on packages to use a `ox-` prefix: # and org-mode asks some add-on packages to use a `ox-` prefix:
if package_name.startswith('helm-source') or package_name == 'ox': if name.startswith('helm-source') or name == 'ox':
_fail(f"- Error: {package_name} is implicitly in use") _fail(f"- Error: {name} is implicitly in use")
print() print()