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