@@ -24,37 +24,51 @@ def setUpClass(cls):
2424 cls .sg = sendgrid .SendGridAPIClient (
2525 host = host , path = cls .path ,
2626 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 :
2845 if sys .platform != 'win32' :
46+ # try to install with prism.sh
2947 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 ()
3954 except Exception as e :
4055 print (
41- "Error downloading the prism binary, you can try "
56+ "Error installing the prism binary, you can try "
4257 "downloading directly here "
4358 "(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 )
4660 sys .exit ()
4761 else :
4862 print ("Please download the Windows binary "
4963 "(https://github.com/stoplightio/prism/releases) "
50- "and place it in your /usr/local/bin directory " )
64+ "and place it in your %PATH% " )
5165 sys .exit ()
66+
5267 print ("Activating Prism (~20 seconds)" )
53- devnull = open (os .devnull , 'w' )
5468 cls .p = subprocess .Popen ([
55- "prism" , "run" , "-s" ,
69+ prism_cmd , "run" , "-s" ,
5670 "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 )
5872 time .sleep (15 )
5973 print ("Prism Started" )
6074
0 commit comments