check emacsmirror for packages with same name

...in addition to MELPA, as described in #6
This commit is contained in:
riscy 2020-03-18 19:58:37 -07:00
parent 6064b34d3e
commit 5dc65b7c9d

View file

@ -8,7 +8,7 @@ Test this file:
Use this file a script: Use this file a script:
python <this_file>.py python <this_file>.py
""" """
from __future__ import print_function import configparser
import functools import functools
import glob import glob
import io # noqa: F401 -- used by doctests import io # noqa: F401 -- used by doctests
@ -432,26 +432,37 @@ def _print_package_files(files: list):
def print_related_packages(recipe: str): def print_related_packages(recipe: str):
"""Print list of potentially related packages.""" """Print list of potentially related packages."""
# TODO: can this be made more useful? known_packages = _known_packages()
package_tokens = { known_names = [
token for token in _package_name(recipe).split('-') if token != 'mode' name
} for name in known_packages
related_packages = [ if name in _package_name(recipe) or _package_name(recipe) in name
f"- https://melpa.org/#/{_melpa_archive()[other_package_tokens]}"
for other_package_tokens in _melpa_archive()
if package_tokens & other_package_tokens
] ]
if related_packages: if not known_names:
_note('\n### Similarly named packages ###\n', CLR_INFO) return
print('\n'.join(related_packages[:5])) _note('\n### Similarly named packages ###\n', CLR_INFO)
for name in known_names:
if name == _package_name(recipe):
_fail(f"- {name}: {known_packages[name]} (name conflict)")
else:
print(f"- {name}: {known_packages[name]}")
@functools.lru_cache() @functools.lru_cache()
def _melpa_archive() -> dict: def _known_packages() -> dict:
return { melpa_packages = {
frozenset(package.split('-')): package package: f"https://melpa.org/#/{package}"
for package in requests.get('http://melpa.org/archive.json').json() for package in requests.get('http://melpa.org/archive.json').json()
} }
epkgs = 'https://raw.githubusercontent.com/emacsmirror/epkgs/master/.gitmodules'
epkgs_parser = configparser.ConfigParser()
epkgs_parser.read_string(requests.get(epkgs).text)
epkgs_packages = {
epkg.split('"')[1]: epkgs_parser[epkg]['url']
for epkg in epkgs_parser
if epkg != 'DEFAULT'
}
return {**epkgs_packages, **melpa_packages}
def yes_p(text: str) -> bool: def yes_p(text: str) -> bool: