bootstrap   A
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 52
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` into bootstrap environment...")
30
        subprocess.check_call([join(bin_path, "pip"), "install", "jinja2"])
31
    python_executable = join(bin_path, "python")
32
    if not os.path.samefile(python_executable, sys.executable):
33
        print("Re-executing with: {0}".format(python_executable))
34
        os.execv(python_executable, [python_executable, __file__])
35
36
    import jinja2
37
38
    import matrix
39
40
    jinja = jinja2.Environment(
41
        loader=jinja2.FileSystemLoader(join(base_path, "ci", "templates")),
42
        trim_blocks=True,
43
        lstrip_blocks=True,
44
        keep_trailing_newline=True
45
    )
46
47
    tox_environments = {}
48
    for (alias, conf) in matrix.from_file(join(base_path, "setup.cfg")).items():
49
        python = conf["python_versions"]
50
        deps = conf["dependencies"]
51
        tox_environments[alias] = {
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