spaCy/fabfile.py

82 lines
2.5 KiB
Python
Raw Normal View History

2017-01-14 20:30:36 +00:00
# coding: utf-8
from __future__ import unicode_literals, print_function
2015-10-25 12:15:51 +00:00
import contextlib
from pathlib import Path
from fabric.api import local, lcd, env, settings, prefix
2017-01-14 20:30:36 +00:00
from os import path, environ
2018-02-27 17:20:39 +00:00
import shutil
2015-01-03 10:02:21 +00:00
PWD = path.dirname(__file__)
2017-01-14 20:30:36 +00:00
ENV = environ['VENV_DIR'] if 'VENV_DIR' in environ else '.env'
VENV_DIR = Path(PWD) / ENV
@contextlib.contextmanager
def virtualenv(name, create=False, python='/usr/bin/python3.6'):
python = Path(python).resolve()
env_path = VENV_DIR
if create:
if env_path.exists():
shutil.rmtree(str(env_path))
local('{python} -m venv {env_path}'.format(python=python,
env_path=VENV_DIR))
def wrapped_local(cmd, env_vars=[]):
env_py = env_path / 'bin' / 'python'
env_vars = ' '.join(env_vars)
if cmd.split()[0] == 'python':
cmd = cmd.replace('python', str(env_py))
return local(env_vars + ' ' + cmd)
else:
return local('{env_vars} {env_py} -m {cmd}'.format(
env_py=env_py, cmd=cmd, env_vars=env_vars))
yield wrapped_local
2015-01-03 10:02:21 +00:00
2017-01-14 20:30:36 +00:00
def env(lang='python2.7'):
2018-02-27 22:29:48 +00:00
if VENV_DIR.exists():
local('rm -rf {env}'.format(env=VENV_DIR))
2017-11-07 11:11:08 +00:00
local('pip install virtualenv')
2017-04-15 13:43:38 +00:00
local('python -m virtualenv -p {lang} {env}'.format(lang=lang, env=VENV_DIR))
2015-01-03 10:02:21 +00:00
def install():
with virtualenv(VENV_DIR) as venv_local:
venv_local('pip install --upgrade setuptools')
venv_local('pip install dist/*.tar.gz')
venv_local('pip install pytest')
2015-01-03 10:02:21 +00:00
2014-07-05 18:49:34 +00:00
def make():
with lcd(path.dirname(__file__)):
with virtualenv(VENV_DIR) as venv_local:
venv_local('pip install cython')
venv_local('pip install murmurhash')
venv_local('pip install -r requirements.txt')
venv_local('python setup.py build_ext --inplace')
2015-01-03 10:02:21 +00:00
2017-11-07 11:11:08 +00:00
def sdist():
with lcd(path.dirname(__file__)):
with virtualenv(VENV_DIR) as venv_local:
2017-11-07 11:11:08 +00:00
local('python setup.py sdist')
2015-01-03 10:02:21 +00:00
def wheel():
2015-01-03 10:02:21 +00:00
with lcd(path.dirname(__file__)):
with virtualenv(VENV_DIR) as venv_local:
venv_local('pip install wheel')
venv_local('python setup.py bdist_wheel')
2015-01-03 10:02:21 +00:00
2014-07-05 18:49:34 +00:00
def clean():
with virtualenv(VENV_DIR) as venv_local:
2015-01-03 10:02:21 +00:00
with lcd(path.dirname(__file__)):
local('python setup.py clean --all')
def test():
with lcd(path.dirname(__file__)):
with virtualenv(VENV_DIR) as venv_local:
2018-02-27 22:42:22 +00:00
local('pip install pytest')
2015-11-03 05:39:30 +00:00
local('py.test -x spacy/tests')