Improve fabfile

This commit is contained in:
Matthew Honnibal 2018-02-28 12:04:38 +01:00
parent 64e53f1b1b
commit 7cf6b1c7a4

11
fabfile.py vendored
View File

@ -14,23 +14,24 @@ VENV_DIR = Path(PWD) / ENV
@contextlib.contextmanager @contextlib.contextmanager
def virtualenv(name, create=False, python='/usr/bin/python3.6'): def virtualenv(name, create=False, python='/usr/bin/python3.6', capture=False):
python = Path(python).resolve() python = Path(python).resolve()
env_path = VENV_DIR env_path = VENV_DIR
if create: if create:
if env_path.exists(): if env_path.exists():
shutil.rmtree(str(env_path)) shutil.rmtree(str(env_path))
local('{python} -m venv {env_path}'.format(python=python, local('{python} -m venv {env_path}'.format(python=python, env_path=VENV_DIR),
env_path=VENV_DIR)) capture=capture)
def wrapped_local(cmd, env_vars=[]): def wrapped_local(cmd, env_vars=[]):
env_py = env_path / 'bin' / 'python' env_py = env_path / 'bin' / 'python'
env_vars = ' '.join(env_vars) env_vars = ' '.join(env_vars)
if cmd.split()[0] == 'python': if cmd.split()[0] == 'python':
cmd = cmd.replace('python', str(env_py)) cmd = cmd.replace('python', str(env_py))
return local(env_vars + ' ' + cmd) return local(env_vars + ' ' + cmd, capture=capture)
else: else:
return local('{env_vars} {env_py} -m {cmd}'.format( return local('{env_vars} {env_py} -m {cmd}'.format(
env_py=env_py, cmd=cmd, env_vars=env_vars)) env_py=env_py, cmd=cmd, env_vars=env_vars),
capture=capture)
yield wrapped_local yield wrapped_local