From 9b75d872b08fe66a5a5c0a8534e36c0e252d3089 Mon Sep 17 00:00:00 2001 From: Henning Peters Date: Thu, 14 Jan 2016 12:02:56 +0100 Subject: [PATCH] fix model download --- spacy/en/download.py | 16 ++++++---------- spacy/util.py | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/spacy/en/download.py b/spacy/en/download.py index f91b44601..bdc0ac9b0 100644 --- a/spacy/en/download.py +++ b/spacy/en/download.py @@ -3,7 +3,9 @@ import os import shutil import plac -from sputnik import Sputnik +import sputnik + +from .. import about def migrate(path): @@ -35,23 +37,17 @@ def link(package, path): force=("Force overwrite", "flag", "f", bool), ) def main(data_size='all', force=False): - # TODO read version from the same source as the setup - sputnik = Sputnik('spacy', '0.100.0', console=sys.stdout) - path = os.path.dirname(os.path.abspath(__file__)) data_path = os.path.abspath(os.path.join(path, '..', 'data')) if not os.path.isdir(data_path): os.mkdir(data_path) - command = sputnik.command( - data_path=data_path, - repository_url='https://index.spacy.io') - if force: - command.purge() + sputnik.purge('spacy', about.short_version, data_path=data_path) - package = command.install('en_default') + package = sputnik.install('spacy', about.short_version, 'en_default==1.0.4', + data_path=data_path) # FIXME clean up old-style packages migrate(path) diff --git a/spacy/util.py b/spacy/util.py index 49bbf3841..5aa4cde96 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -7,6 +7,7 @@ import os.path import sputnik from sputnik.dir_package import DirPackage from sputnik.package_stub import PackageStub +from sputnik.package_list import PackageNotFoundException, CompatiblePackageNotFoundException from . import about from .attrs import TAG, HEAD, DEP, ENT_IOB, ENT_TYPE @@ -22,8 +23,19 @@ def get_package(value=None, data_path=None): elif value is None and data_path is not None: return DirPackage(data_path) - return sputnik.package('spacy', about.short_version, - value or 'en_default==1.0.4', data_path=data_path) + try: + return sputnik.package('spacy', about.short_version, + value or 'en_default==1.0.4', + data_path=data_path) + + except PackageNotFoundException as e: + raise RuntimeError("Model not installed. Please run 'python -m " + "spacy.en.download' to install latest compatible " + "model.") + except CompatiblePackageNotFoundException as e: + raise RuntimeError("Installed model is not compatible with spaCy " + "version. Please run 'python -m spacy.en.download " + "--force' to install latest compatible model.") def normalize_slice(length, start, stop, step=None):