@@ -47,7 +47,7 @@ def execute_code_with_pipe(command, code_in, post_process=[]):
4747 out = f (out )
4848
4949 # Log any stderr.
50- if err is not None and err .strip () != "" :
50+ if err is not None and len ( err .strip ()) > 0 :
5151 print (err )
5252
5353 return out
@@ -71,6 +71,8 @@ def execute_code_with_pipe(command, code_in, post_process=[]):
7171 runner ['with' ] = 'runghc' # default is runghc, no hooks
7272
7373 if runner ['with' ] == 'ghci' :
74+ # TODO: properly add in an args argument to execute_code_with_pipe
75+ runner ['with' ] = 'ghci -ignore-dot-ghci' .split ()
7476 # if running with ghci then we post process the output to remove
7577 # ghci specific text
7678 post_process += [lambda s : s .replace ("ghci>" ,"" ),
@@ -87,18 +89,26 @@ def execute_code_with_pipe(command, code_in, post_process=[]):
8789 out = comp_proc .stdout
8890 err = comp_proc .stderr
8991 code_out = out
90- found = False
9192
93+ ## control the output
9294 out_stream = code_out .splitlines ()
95+ linking_index = 0
9396 for index , line in enumerate (out_stream ):
9497 if "Linking" in line :
95- i = index + 1
96- code_out = '\n ' .join (out_stream [i :])
97- break # only want first hit, and we are guarenteed
98- # that linking is in the list because you
99- # cannot run a binary without linking! Log
100-
101- if err is not None and err .strip () != "" :
98+ linking_index = index
99+ break
100+ if runner ['output' ] == 'all' :
101+ ## then we want the whole of stdout including the program
102+ code_out = '\n ' .join (out_stream )
103+ elif runner ['output' ] == 'comp' :
104+ ## then we only want ghc's output and not the program
105+ code_out = '\n ' .join (out_stream [:linking_index ])
106+ else :
107+ ## the default case, we only want the program output
108+ code_out = '\n ' .join (out_stream [linking_index :])
109+
110+ # Log
111+ if err is not None and len (err .strip ()) > 0 :
102112 print (err ) # should use sphinx logger
103113
104114 else :
@@ -120,7 +130,7 @@ def execute_code_with_pipe(command, code_in, post_process=[]):
120130 out = comp_proc .stdout .decode ('utf-8' )
121131 err = comp_proc .stderr
122132 # Log any stderr.
123- if err is not None and err .strip () != "" :
133+ if err is not None and len ( err .strip ()) > 0 :
124134 print (err )
125135 code_out = out
126136
@@ -164,6 +174,7 @@ class Exec(Directive):
164174 'context' : _option_boolean ,
165175 'cache' : _option_boolean ,
166176 'process' : _option_process ,
177+ 'output' : _option_str ,
167178 'intertext' : _option_str ,
168179 'project_dir' : _option_str ,
169180 'with' : _option_str ,
@@ -192,6 +203,7 @@ def run(self):
192203 project_dir = self .options .get ('project_dir' , '' )
193204 opt_with = self .options .get ('with' , '' )
194205 args = self .options .get ('args' ,'' ).split ()
206+ output = self .options .get ('output' ,'' )
195207
196208 # A runner is "that which runs the code", i.e., a dictionary that
197209 # defines the entire external process
@@ -204,7 +216,8 @@ def run(self):
204216 # the contents of source_file,
205217 # if not then its the contents
206218 # of a literal code block
207- 'args' : args } # args to run with, with
219+ 'args' : args , # args to run with, with
220+ 'output' : output } # how much output to display
208221
209222 # Determine whether input is to be read from a file, or directly from
210223 # the exec block's contents.
0 commit comments