summaryrefslogtreecommitdiff
path: root/tasks.py
blob: 0fbb5e8352b15c56fea5aa643f5905b3e61c5d7f (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
import os
import shutil

from invoke import run, task


def _generate_keys():
    run("bash docker/stunnel/create_certs.sh")


with open("tox.ini") as fp:
    lines = fp.read().split("\n")
    dockers = [line.split("=")[1].strip() for line in lines if line.find("name") != -1]


@task
def devenv(c):
    """Builds a development environment: downloads, and starts all dockers
    specified in the tox.ini file.
    """
    clean(c)
    _generate_keys()
    cmd = "tox -e devenv"
    for d in dockers:
        cmd += f" --docker-dont-stop={d}"
    run(cmd)


@task
def build_docs(c):
    """Generates the sphinx documentation."""
    run("tox -e docs")


@task
def linters(c):
    """Run code linters"""
    _generate_keys()
    run("tox -e linters")


@task
def all_tests(c):
    """Run all linters, and tests in redis-py. This assumes you have all
    the python versions specified in the tox.ini file.
    """
    _generate_keys()
    linters(c)
    tests(c)


@task
def tests(c):
    """Run the redis-py test suite against the current python,
    with and without hiredis.
    """
    print("Starting Redis tests")
    _generate_keys()
    run("tox -e '{standalone,cluster}'-'{plain,hiredis}'")


@task
def standalone_tests(c):
    """Run all Redis tests against the current python,
    with and without hiredis."""
    print("Starting Redis tests")
    _generate_keys()
    run("tox -e standalone-'{plain,hiredis,cryptography}'")


@task
def cluster_tests(c):
    """Run all Redis Cluster tests against the current python,
    with and without hiredis."""
    print("Starting RedisCluster tests")
    _generate_keys()
    run("tox -e cluster-'{plain,hiredis}'")


@task
def clean(c):
    """Stop all dockers, and clean up the built binaries, if generated."""
    if os.path.isdir("build"):
        shutil.rmtree("build")
    if os.path.isdir("dist"):
        shutil.rmtree("dist")
    run(f"docker rm -f {' '.join(dockers)}")
    if os.path.isdir("docker/stunnel/keys"):
        shutil.rmtree("docker/stunnel/keys")


@task
def package(c):
    """Create the python packages"""
    run("python setup.py sdist bdist_wheel")