@@ -24,37 +24,51 @@ def setUpClass(cls):
24
24
cls .sg = sendgrid .SendGridAPIClient (
25
25
host = host , path = cls .path ,
26
26
api_key = os .environ .get ('SENDGRID_API_KEY' ))
27
- if os .path .isfile ('/usr/local/bin/prism' ) is False :
27
+ cls .devnull = open (os .devnull , 'w' )
28
+ prism_cmd = None
29
+ try :
30
+ # check for prism in the PATH
31
+ if subprocess .call ('prism version' .split (), stdout = cls .devnull ) == 0 :
32
+ prism_cmd = 'prism'
33
+ except OSError :
34
+ prism_cmd = None
35
+
36
+ if not prism_cmd :
37
+ # check for known prism locations
38
+ for path in ('/usr/local/bin/prism' , os .path .expanduser (os .path .join ('~' , 'bin' , 'prism' )),
39
+ os .path .abspath (os .path .join (os .getcwd (), 'prism' , 'bin' , 'prism' ))):
40
+ prism_cmd = path if os .path .isfile (path ) else None
41
+ if prism_cmd :
42
+ break
43
+
44
+ if not prism_cmd :
28
45
if sys .platform != 'win32' :
46
+ # try to install with prism.sh
29
47
try :
30
- p1 = subprocess .Popen (
31
- [
32
- "curl" ,
33
- "https://raw.githubusercontent.com/stoplightio/"
34
- "prism/master/install.sh" ],
35
- stdout = subprocess .PIPE )
36
- prisminstaller = subprocess .Popen (
37
- ["sh" ], stdin = p1 .stdout , stdout = subprocess .PIPE )
38
- prisminstaller .wait ()
48
+ print ("Warning: no prism detected, I will try to install it locally" )
49
+ prism_sh = os .path .abspath (os .path .join (cls .path , 'test' , 'prism.sh' ))
50
+ if subprocess .call (prism_sh ) == 0 :
51
+ prism_cmd = os .path .expanduser (os .path .join ('~' , 'bin' , 'prism' ))
52
+ else :
53
+ raise RuntimeError ()
39
54
except Exception as e :
40
55
print (
41
- "Error downloading the prism binary, you can try "
56
+ "Error installing the prism binary, you can try "
42
57
"downloading directly here "
43
58
"(https://github.com/stoplightio/prism/releases) "
44
- "and place in your /usr/local/bin directory" ,
45
- e .read ())
59
+ "and place in your $PATH" , e )
46
60
sys .exit ()
47
61
else :
48
62
print ("Please download the Windows binary "
49
63
"(https://github.com/stoplightio/prism/releases) "
50
- "and place it in your /usr/local/bin directory " )
64
+ "and place it in your %PATH% " )
51
65
sys .exit ()
66
+
52
67
print ("Activating Prism (~20 seconds)" )
53
- devnull = open (os .devnull , 'w' )
54
68
cls .p = subprocess .Popen ([
55
- "prism" , "run" , "-s" ,
69
+ prism_cmd , "run" , "-s" ,
56
70
"https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/"
57
- "oai_stoplight.json" ], stdout = devnull , stderr = subprocess .STDOUT )
71
+ "oai_stoplight.json" ], stdout = cls . devnull , stderr = subprocess .STDOUT )
58
72
time .sleep (15 )
59
73
print ("Prism Started" )
60
74
0 commit comments