fix model download

This commit is contained in:
Henning Peters 2016-01-14 12:02:56 +01:00
parent bc229790ac
commit 9b75d872b0
2 changed files with 20 additions and 12 deletions

View File

@ -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)

View File

@ -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):