|
1 | 1 | #!/usr/bin/env python |
2 | 2 | # -*- coding: utf-8 -*- |
3 | | -from __future__ import absolute_import, print_function, unicode_literals |
| 3 | +from __future__ import absolute_import |
| 4 | +from __future__ import print_function |
| 5 | +from __future__ import unicode_literals |
4 | 6 |
|
5 | 7 | import os |
| 8 | +import subprocess |
6 | 9 | import sys |
7 | 10 | from collections import defaultdict |
8 | 11 | from os.path import abspath |
9 | 12 | from os.path import dirname |
10 | 13 | from os.path import exists |
11 | 14 | from os.path import join |
12 | 15 |
|
13 | | -if __name__ == "__main__": |
14 | | - base_path = dirname(dirname(abspath(__file__))) |
15 | | - print("Project path: {0}".format(base_path)) |
| 16 | +base_path = dirname(dirname(abspath(__file__))) |
| 17 | + |
| 18 | + |
| 19 | +def check_call(args): |
| 20 | + print("+", *args) |
| 21 | + subprocess.check_call(args) |
| 22 | + |
| 23 | +def exec_in_env(): |
16 | 24 | env_path = join(base_path, ".tox", "bootstrap") |
17 | 25 | if sys.platform == "win32": |
18 | 26 | bin_path = join(env_path, "Scripts") |
|
23 | 31 |
|
24 | 32 | print("Making bootstrap env in: {0} ...".format(env_path)) |
25 | 33 | try: |
26 | | - subprocess.check_call(["virtualenv", env_path]) |
| 34 | + check_call([sys.executable, "-m", "venv", env_path]) |
27 | 35 | except subprocess.CalledProcessError: |
28 | | - subprocess.check_call([sys.executable, "-m", "virtualenv", env_path]) |
| 36 | + try: |
| 37 | + check_call([sys.executable, "-m", "virtualenv", env_path]) |
| 38 | + except subprocess.CalledProcessError: |
| 39 | + check_call(["virtualenv", env_path]) |
29 | 40 | print("Installing `jinja2` into bootstrap environment...") |
30 | | - subprocess.check_call([join(bin_path, "pip"), "install", "jinja2"]) |
| 41 | + check_call([join(bin_path, "pip"), "install", "jinja2", "tox"]) |
31 | 42 | 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__]) |
| 43 | + if not os.path.exists(python_executable): |
| 44 | + python_executable += '.exe' |
| 45 | + |
| 46 | + print("Re-executing with: {0}".format(python_executable)) |
| 47 | + print("+ exec", python_executable, __file__, "--no-env") |
| 48 | + os.execv(python_executable, [python_executable, __file__, "--no-env"]) |
35 | 49 |
|
| 50 | +def main(): |
36 | 51 | import jinja2 |
37 | 52 |
|
38 | | - import subprocess |
| 53 | + print("Project path: {0}".format(base_path)) |
39 | 54 |
|
40 | 55 | jinja = jinja2.Environment( |
41 | 56 | loader=jinja2.FileSystemLoader(join(base_path, "ci", "templates")), |
|
63 | 78 | fh.write(jinja.get_template(name).render(**template_vars)) |
64 | 79 | print("Wrote {}".format(name)) |
65 | 80 | print("DONE.") |
| 81 | + |
| 82 | +if __name__ == "__main__": |
| 83 | + args = sys.argv[1:] |
| 84 | + if args == ["--no-env"]: |
| 85 | + main() |
| 86 | + elif not args: |
| 87 | + exec_in_env() |
| 88 | + else: |
| 89 | + print("Unexpected arguments {0}".format(args), file=sys.stderr) |
| 90 | + sys.exit(1) |
| 91 | + |
0 commit comments