diff --git a/spacy/about.py b/spacy/about.py index e6999b136..6498f80ee 100644 --- a/spacy/about.py +++ b/spacy/about.py @@ -13,4 +13,4 @@ __license__ = 'MIT' __docs__ = 'https://spacy.io/docs/usage' __download_url__ = 'https://github.com/explosion/spacy-models/releases/download' __compatibility__ = 'https://raw.githubusercontent.com/explosion/spacy-models/master/compatibility.json' -__shortcuts__ = {'en': 'en_core_web_sm', 'de': 'de_core_news_md', 'vectors': 'en_vectors_glove_md'} +__shortcuts__ = 'https://raw.githubusercontent.com/explosion/spacy-models/master/shortcuts.json' diff --git a/spacy/cli/download.py b/spacy/cli/download.py index 06333eabf..0419de118 100644 --- a/spacy/cli/download.py +++ b/spacy/cli/download.py @@ -17,37 +17,45 @@ def download(model=None, direct=False): if direct: download_model('{m}/{m}.tar.gz'.format(m=model)) else: - model_name = about.__shortcuts__[model] if model in about.__shortcuts__ else model + model_name = check_shortcut(model) compatibility = get_compatibility() version = get_version(model_name, compatibility) download_model('{m}-{v}/{m}-{v}.tar.gz'.format(m=model_name, v=version)) link_package(model_name, model, force=True) -def get_compatibility(): - version = about.__version__ - r = requests.get(about.__compatibility__) +def get_json(url, desc): + r = requests.get(url) if r.status_code != 200: util.sys_exit( - "Couldn't fetch compatibility table. Please find the right model for " - "your spaCy installation (v{v}), and download it manually:".format(v=version), + "Couldn't fetch {d}. Please find the right model for your spaCy " + "installation (v{v}), and download it manually:".format(d=desc, v=about.__version__), "python -m spacy.download [full model name + version] --direct", title="Server error ({c})".format(c=r.status_code)) + return r.json() - comp = r.json()['spacy'] + +def check_shortcut(model): + shortcuts = get_json(about.__shortcuts__, "available shortcuts") + return shortcuts.get(model, model) + + +def get_compatibility(): + version = about.__version__ + comp_table = get_json(about.__compatibility__, "compatibility table") + comp = comp_table['spacy'] if version not in comp: util.sys_exit( "No compatible models found for v{v} of spaCy.".format(v=version), title="Compatibility error") - else: - return comp[version] + return comp[version] def get_version(model, comp): if model not in comp: util.sys_exit( "No compatible model found for " - "{m} (spaCy v{v}).".format(m=model, v=about.__version__), + "'{m}' (spaCy v{v}).".format(m=model, v=about.__version__), title="Compatibility error") return comp[model][0]