2017-01-14 23:30:36 +03:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals, print_function
|
2015-10-25 15:15:51 +03:00
|
|
|
|
2018-02-27 20:03:57 +03:00
|
|
|
import contextlib
|
|
|
|
from pathlib import Path
|
2015-07-26 23:40:04 +03:00
|
|
|
from fabric.api import local, lcd, env, settings, prefix
|
2017-01-14 23:30:36 +03:00
|
|
|
from os import path, environ
|
2018-02-27 20:20:39 +03:00
|
|
|
import shutil
|
2014-09-11 14:28:38 +04:00
|
|
|
|
2015-01-03 13:02:21 +03:00
|
|
|
|
|
|
|
PWD = path.dirname(__file__)
|
2017-01-14 23:30:36 +03:00
|
|
|
ENV = environ['VENV_DIR'] if 'VENV_DIR' in environ else '.env'
|
2018-02-27 20:03:57 +03:00
|
|
|
VENV_DIR = Path(PWD) / ENV
|
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
2018-02-28 14:07:19 +03:00
|
|
|
def virtualenv(name, create=False, python='/usr/bin/python3.6'):
|
2018-02-27 20:03:57 +03:00
|
|
|
python = Path(python).resolve()
|
|
|
|
env_path = VENV_DIR
|
|
|
|
if create:
|
|
|
|
if env_path.exists():
|
|
|
|
shutil.rmtree(str(env_path))
|
2018-02-28 14:07:19 +03:00
|
|
|
local('{python} -m venv {env_path}'.format(python=python, env_path=VENV_DIR))
|
2018-03-02 05:51:09 +03:00
|
|
|
def wrapped_local(cmd, env_vars=[], capture=False, direct=False):
|
2018-02-27 20:03:57 +03:00
|
|
|
env_py = env_path / 'bin' / 'python'
|
|
|
|
env_vars = ' '.join(env_vars)
|
|
|
|
if cmd.split()[0] == 'python':
|
|
|
|
cmd = cmd.replace('python', str(env_py))
|
2018-02-28 14:04:38 +03:00
|
|
|
return local(env_vars + ' ' + cmd, capture=capture)
|
2018-03-02 05:51:09 +03:00
|
|
|
elif direct:
|
|
|
|
cmd, args = cmd.split(' ', 1)
|
|
|
|
env_cmd = str(env_py).replace('python', cmd)
|
|
|
|
return local('{env_vars} {env_cmd} {args}'.format(
|
|
|
|
env_cmd=env_cmd, args=args, env_vars=env_vars),
|
|
|
|
capture=capture)
|
2018-02-27 20:03:57 +03:00
|
|
|
else:
|
|
|
|
return local('{env_vars} {env_py} -m {cmd}'.format(
|
2018-02-28 14:04:38 +03:00
|
|
|
env_py=env_py, cmd=cmd, env_vars=env_vars),
|
|
|
|
capture=capture)
|
2018-02-27 20:03:57 +03:00
|
|
|
yield wrapped_local
|
2015-01-03 13:02:21 +03:00
|
|
|
|
|
|
|
|
2018-02-28 03:45:19 +03:00
|
|
|
def env(lang='python3.6'):
|
2018-02-28 01:29:48 +03:00
|
|
|
if VENV_DIR.exists():
|
2017-01-14 19:49:32 +03:00
|
|
|
local('rm -rf {env}'.format(env=VENV_DIR))
|
2018-02-28 14:01:52 +03:00
|
|
|
local('{lang} -m pip install virtualenv --no-cache-dir'.format(lang=lang))
|
2018-02-28 03:45:19 +03:00
|
|
|
if lang.startswith('python3'):
|
|
|
|
local('{lang} -m venv {env}'.format(lang=lang, env=VENV_DIR))
|
|
|
|
else:
|
2018-02-28 14:01:52 +03:00
|
|
|
local('{lang} -m virtualenv {env} --no-cache-dir'.format(lang=lang, env=VENV_DIR))
|
2018-02-28 13:56:09 +03:00
|
|
|
with virtualenv(VENV_DIR) as venv_local:
|
2018-02-28 14:01:52 +03:00
|
|
|
print(venv_local('python --version', capture=True))
|
|
|
|
venv_local('pip install --upgrade setuptools --no-cache-dir')
|
|
|
|
venv_local('pip install pytest --no-cache-dir')
|
2018-02-28 14:09:53 +03:00
|
|
|
venv_local('pip install wheel')
|
2015-01-03 13:02:21 +03:00
|
|
|
|
|
|
|
|
|
|
|
def install():
|
2018-02-27 20:03:57 +03:00
|
|
|
with virtualenv(VENV_DIR) as venv_local:
|
|
|
|
venv_local('pip install dist/*.tar.gz')
|
2015-01-03 13:02:21 +03:00
|
|
|
|
2014-07-05 22:49:34 +04:00
|
|
|
|
|
|
|
def make():
|
2018-02-28 05:28:22 +03:00
|
|
|
with virtualenv(VENV_DIR) as venv_local:
|
|
|
|
with lcd(path.dirname(__file__)):
|
2018-02-27 20:03:57 +03:00
|
|
|
venv_local('pip install -r requirements.txt')
|
2018-03-02 05:51:09 +03:00
|
|
|
venv_local('pip install pex')
|
2018-02-28 05:30:44 +03:00
|
|
|
venv_local('python setup.py build_ext --inplace', env_vars=['PYTHONPATH=`pwd`'])
|
2015-01-03 13:02:21 +03:00
|
|
|
|
2017-11-07 14:11:08 +03:00
|
|
|
def sdist():
|
2018-02-28 05:28:22 +03:00
|
|
|
with virtualenv(VENV_DIR) as venv_local:
|
|
|
|
with lcd(path.dirname(__file__)):
|
2017-11-07 14:11:08 +03:00
|
|
|
local('python setup.py sdist')
|
2015-01-03 13:02:21 +03:00
|
|
|
|
2018-02-27 20:03:57 +03:00
|
|
|
def wheel():
|
2018-02-28 05:28:22 +03:00
|
|
|
with virtualenv(VENV_DIR) as venv_local:
|
|
|
|
with lcd(path.dirname(__file__)):
|
2018-02-27 20:03:57 +03:00
|
|
|
venv_local('python setup.py bdist_wheel')
|
2015-01-03 13:02:21 +03:00
|
|
|
|
2018-03-02 05:51:09 +03:00
|
|
|
def pex():
|
|
|
|
with virtualenv(VENV_DIR) as venv_local:
|
|
|
|
with lcd(path.dirname(__file__)):
|
|
|
|
venv_local('pex . -e spacy -o dist/spacy', direct=True)
|
|
|
|
|
2014-07-05 22:49:34 +04:00
|
|
|
|
2018-02-27 20:03:57 +03:00
|
|
|
def clean():
|
2018-02-28 05:28:22 +03:00
|
|
|
with lcd(path.dirname(__file__)):
|
|
|
|
with virtualenv(VENV_DIR) as venv_local:
|
2018-02-28 14:09:53 +03:00
|
|
|
venv_local('python setup.py clean --all')
|
2018-02-27 20:03:57 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test():
|
2018-02-28 05:28:22 +03:00
|
|
|
with virtualenv(VENV_DIR) as venv_local:
|
|
|
|
with lcd(path.dirname(__file__)):
|
2018-02-28 04:22:57 +03:00
|
|
|
venv_local('pytest -x spacy/tests')
|
2018-03-01 20:15:26 +03:00
|
|
|
|
|
|
|
def train():
|
|
|
|
args = environ.get('SPACY_TRAIN_ARGS', '')
|
|
|
|
with virtualenv(VENV_DIR) as venv_local:
|
|
|
|
venv_local('spacy train {args}'.format(args=args))
|