2015-10-18 13:35:04 +03:00
|
|
|
import sys
|
2015-01-02 13:44:41 +03:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
2015-11-15 17:58:21 +03:00
|
|
|
import plac
|
|
|
|
from sputnik import Sputnik
|
2015-10-18 13:35:04 +03:00
|
|
|
|
2015-01-02 13:44:41 +03:00
|
|
|
|
2015-11-15 17:58:21 +03:00
|
|
|
def migrate(path):
|
|
|
|
data_path = os.path.join(path, 'data')
|
|
|
|
if os.path.isdir(data_path) and not os.path.islink(data_path):
|
|
|
|
shutil.rmtree(data_path)
|
|
|
|
for filename in os.listdir(path):
|
2015-11-18 19:35:21 +03:00
|
|
|
if filename.endswith('.tgz'):
|
2015-11-15 17:58:21 +03:00
|
|
|
os.unlink(os.path.join(path, filename))
|
2015-01-30 10:04:01 +03:00
|
|
|
|
2015-01-17 08:21:17 +03:00
|
|
|
|
2015-11-15 17:58:21 +03:00
|
|
|
def link(package, path):
|
|
|
|
if os.path.exists(path):
|
2015-12-23 01:25:38 +03: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 08:21:17 +03:00
|
|
|
|
|
|
|
|
2015-10-18 13:35:04 +03:00
|
|
|
@plac.annotations(
|
|
|
|
force=("Force overwrite", "flag", "f", bool),
|
|
|
|
)
|
2015-11-18 19:35:21 +03:00
|
|
|
def main(data_size='all', force=False):
|
2015-11-15 17:58:21 +03:00
|
|
|
# TODO read version from the same source as the setup
|
|
|
|
sputnik = Sputnik('spacy', '0.99.0', console=sys.stdout)
|
2015-10-21 08:59:34 +03:00
|
|
|
|
2015-11-15 17:58:21 +03:00
|
|
|
path = os.path.dirname(os.path.abspath(__file__))
|
2015-10-21 08:59:34 +03:00
|
|
|
|
2015-12-13 13:49:17 +03:00
|
|
|
data_path = os.path.abspath(os.path.join(path, '..', 'data'))
|
|
|
|
if not os.path.isdir(data_path):
|
|
|
|
os.mkdir(data_path)
|
|
|
|
|
2015-12-13 16:46:08 +03:00
|
|
|
command = sputnik.command(
|
2015-12-13 13:49:17 +03:00
|
|
|
data_path=data_path,
|
2015-11-18 20:09:46 +03:00
|
|
|
repository_url='https://index.spacy.io')
|
2015-11-15 17:58:21 +03:00
|
|
|
|
|
|
|
if force:
|
|
|
|
command.purge()
|
|
|
|
|
|
|
|
package = command.install('en_default')
|
2015-10-20 20:11:29 +03:00
|
|
|
|
2015-11-15 17:58:21 +03:00
|
|
|
# FIXME clean up old-style packages
|
|
|
|
migrate(path)
|
2015-10-18 13:35:04 +03:00
|
|
|
|
2015-11-15 17:58:21 +03:00
|
|
|
# FIXME supply spacy with an old-style data dir
|
|
|
|
link(package, os.path.join(path, 'data'))
|
2015-01-02 13:44:41 +03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2015-01-31 05:51:56 +03:00
|
|
|
plac.call(main)
|