2016-01-15 17:01:02 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2015-10-18 10:35:04 +00:00
|
|
|
import sys
|
2015-01-02 10:44:41 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
2015-11-15 14:58:21 +00:00
|
|
|
import plac
|
2016-01-14 11:02:56 +00:00
|
|
|
import sputnik
|
|
|
|
|
|
|
|
from .. import about
|
2015-10-18 10:35:04 +00:00
|
|
|
|
2015-01-02 10:44:41 +00:00
|
|
|
|
2015-11-15 14:58:21 +00:00
|
|
|
def migrate(path):
|
|
|
|
data_path = os.path.join(path, 'data')
|
2015-12-18 08:49:45 +00:00
|
|
|
if os.path.isdir(data_path):
|
|
|
|
if os.path.islink(data_path):
|
|
|
|
os.unlink(data_path)
|
|
|
|
else:
|
|
|
|
shutil.rmtree(data_path)
|
2015-11-15 14:58:21 +00:00
|
|
|
for filename in os.listdir(path):
|
2015-11-18 16:35:21 +00:00
|
|
|
if filename.endswith('.tgz'):
|
2015-11-15 14:58:21 +00:00
|
|
|
os.unlink(os.path.join(path, filename))
|
2015-01-30 07:04:01 +00:00
|
|
|
|
2015-01-17 05:21:17 +00:00
|
|
|
|
2015-11-15 14:58:21 +00:00
|
|
|
def link(package, path):
|
|
|
|
if os.path.exists(path):
|
2015-12-22 22:25:38 +00:00
|
|
|
if os.path.isdir(path):
|
|
|
|
shutil.rmtree(path)
|
|
|
|
else:
|
|
|
|
os.unlink(path)
|
|
|
|
|
|
|
|
if not hasattr(os, 'symlink'): # not supported by win+py27
|
|
|
|
shutil.copytree(package.dir_path('data'), path)
|
|
|
|
else:
|
|
|
|
os.symlink(package.dir_path('data'), path)
|
2015-01-17 05:21:17 +00:00
|
|
|
|
|
|
|
|
2015-10-18 10:35:04 +00:00
|
|
|
@plac.annotations(
|
|
|
|
force=("Force overwrite", "flag", "f", bool),
|
|
|
|
)
|
2015-11-18 16:35:21 +00:00
|
|
|
def main(data_size='all', force=False):
|
2015-11-15 14:58:21 +00:00
|
|
|
path = os.path.dirname(os.path.abspath(__file__))
|
2015-10-21 05:59:34 +00:00
|
|
|
|
2015-11-15 14:58:21 +00:00
|
|
|
if force:
|
2016-01-15 17:01:02 +00:00
|
|
|
sputnik.purge('spacy', about.short_version)
|
2015-11-15 14:58:21 +00:00
|
|
|
|
2016-01-15 17:07:15 +00:00
|
|
|
package = sputnik.install('spacy', about.short_version, about.default_model)
|
2016-01-15 17:01:02 +00:00
|
|
|
|
|
|
|
try:
|
2016-01-15 17:07:15 +00:00
|
|
|
sputnik.package('spacy', about.short_version, about.default_model)
|
2016-01-15 17:01:02 +00:00
|
|
|
except PackageNotFoundException, CompatiblePackageNotFoundException:
|
|
|
|
print("Model failed to install. Please run 'python -m "
|
|
|
|
"spacy.en.download --force'.", file=sys.stderr)
|
|
|
|
sys.exit(1)
|
2015-10-20 17:11:29 +00:00
|
|
|
|
2015-11-15 14:58:21 +00:00
|
|
|
# FIXME clean up old-style packages
|
|
|
|
migrate(path)
|
2015-10-18 10:35:04 +00:00
|
|
|
|
2016-01-15 17:01:02 +00:00
|
|
|
print("Model successfully installed.", file=sys.stderr)
|
|
|
|
|
2015-01-02 10:44:41 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2015-01-31 02:51:56 +00:00
|
|
|
plac.call(main)
|