summaryrefslogtreecommitdiff
path: root/fabfile.py
blob: 88921550b3a01675c32617ee1ebc7506e80e4f2e (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# coding=utf-8
from fabric.api import env, task, local
import os
import errno

env.projname = local("python setup.py --name", capture=True)
env.version = local("python setup.py --version", capture=True)


def mkdirs(path):
    try:
        os.makedirs(path)
    except OSError as exc:
        if exc.errno == errno.EEXIST and os.path.isdir(path):
            pass
        else:
            raise


@task
def clean():
    local("python setup.py clean")
    local("find . -name '*.pyc' -delete")


@task
def build():
    local("python setup.py sdist")


@task
def rebuild():
    clean()
    build()


@task
def prepare_cover_dir():
    # If there isn't a cover symlink, create and link the directory
    if os.path.isdir('cover'):
        return

    mkdirs('docs/_build/html/cover')
    local("ln -s docs/_build/html/cover")
    local("rm -rf cover/*")


@task
def coverage():
    prepare_cover_dir()
    local("py.test -n4 --cov=%s --cov-report=term-missing "
          "--cov-report=html" % env.projname)


@task
def pylint():
    local("pylint %s tests" % env.projname)


@task
def doc():
    local("sphinx-build -b html docs  docs/_build/html")


@task
def docwithcoverage():
    coverage()
    doc()


@task
def tox():
    local('tox')


@task
def release_check():
    tags = local("git tag", capture=True)
    tags = set(tags.splitlines())
    if 'a' in env.version:
        print("WARNING: alpha release %s" % env.version)

    # hacky CHANGES.md check
    with open("CHANGES.md") as f:
        raw_changes = f.read()
    assert "%s\n---" % env.version in raw_changes, \
        "The current version %s is not in CHANGES.md" % env.version
    if env.version in tags:
        raise Exception("Already released v. %r" % env.version)


@task
def release():
    release_check()
    clean()
    build()
    print("Releasing", env.projname, "version", env.version)
    local("git tag %s" % env.version)
    local("python setup.py sdist upload")
    local("git push --tags")


@task
def test_pip_install():
    local("d=$(mktemp -d) && cd $d && virtualenv . && . "
          "bin/activate && pip install -v %s" % env.projname)