-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfabfile.py
50 lines (39 loc) · 1.52 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# pylint: disable=not-context-manager
import os
from fabric.colors import green, yellow
from fabric.context_managers import hide
from fabric.decorators import task, hosts
from fabric.operations import local
from fabric.utils import abort, puts
def _ensure_venv():
if "VIRTUAL_ENV" not in os.environ:
abort("No active virtualenv found. Please create / activate one before continuing.")
def _pre_check():
_ensure_venv()
_ensure_pip_tools()
def _ensure_pip_tools():
try:
# pylint: disable-next=unused-import, import-outside-toplevel
import piptools # noqa
except ImportError:
with hide("running", "stdout"):
puts(yellow("Installing 'pip-tools'"), show_prefix=True)
local("pip install pip-tools")
@task
@hosts("localhost")
def compile(): # pylint: disable=redefined-builtin
"""Compile the requirements files (useful to bump dependencies)."""
_pre_check()
with hide("running", "stdout"):
puts(green("Generating package requirement file."), show_prefix=True)
local("pip-compile --output-file=requirements/base.txt requirements/base.in")
local("pip-compile --output-file=requirements/tests.txt requirements/tests.in")
@task(default=True)
@hosts("localhost")
def sync():
"""Ensure installed packages match requirements"""
_pre_check()
with hide("running", "stdout"):
puts(green("Syncing requirements to local packages."), show_prefix=True)
local("pip-sync requirements/base.txt")
local("pip install -e .")