Passed
Branch master (459d08)
by Max
46s
created

bootstrap   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 51
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 0
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
from __future__ import absolute_import, print_function, unicode_literals
4
5
import os
6
import sys
7
from os.path import abspath
8
from os.path import dirname
9
from os.path import exists
10
from os.path import join
11
12
13
if __name__ == "__main__":
14
    base_path = dirname(dirname(abspath(__file__)))
15
    print("Project path: {0}".format(base_path))
16
    env_path = join(base_path, ".tox", "bootstrap")
17
    if sys.platform == "win32":
18
        bin_path = join(env_path, "Scripts")
19
    else:
20
        bin_path = join(env_path, "bin")
21
    if not exists(env_path):
22
        import subprocess
23
24
        print("Making bootstrap env in: {0} ...".format(env_path))
25
        try:
26
            subprocess.check_call(["virtualenv", env_path])
27
        except subprocess.CalledProcessError:
28
            subprocess.check_call([sys.executable, "-m", "virtualenv", env_path])
29
        print("Installing `jinja2` and `matrix` into bootstrap environment...")
30
        subprocess.check_call([join(bin_path, "pip"), "install", "jinja2", "matrix"])
31
    activate = join(bin_path, "activate_this.py")
32
    # noinspection PyCompatibility
33
    exec(compile(open(activate, "rb").read(), activate, "exec"), dict(__file__=activate))
34
35
    import jinja2
36
37
    import matrix
38
39
    jinja = jinja2.Environment(
40
        loader=jinja2.FileSystemLoader(join(base_path, "ci", "templates")),
41
        trim_blocks=True,
42
        lstrip_blocks=True,
43
        keep_trailing_newline=True
44
    )
45
46
    tox_environments = {}
47
    for (alias, conf) in matrix.from_file(join(base_path, "setup.cfg")).items():
48
        python = conf["python_versions"]
49
        deps = conf["dependencies"]
50
        tox_environments[alias] = {
51
            "python": "python" + python if "py" not in python else python,
52
            "deps": deps.split(),
53
        }
54
        if "coverage_flags" in conf:
55
            cover = {"false": False, "true": True}[conf["coverage_flags"].lower()]
56
            tox_environments[alias].update(cover=cover)
57
        if "environment_variables" in conf:
58
            env_vars = conf["environment_variables"]
59
            tox_environments[alias].update(env_vars=env_vars.split())
60
61
    for name in os.listdir(join("ci", "templates")):
62
        with open(join(base_path, name), "w") as fh:
63
            fh.write(jinja.get_template(name).render(tox_environments=tox_environments))
64
        print("Wrote {}".format(name))
65
    print("DONE.")
66