@@ -47,7 +47,7 @@ def execute_code_with_pipe(command, code_in, post_process=[]):
47
47
out = f (out )
48
48
49
49
# Log any stderr.
50
- if err is not None and err .strip () != "" :
50
+ if err is not None and len ( err .strip ()) > 0 :
51
51
print (err )
52
52
53
53
return out
@@ -71,6 +71,8 @@ def execute_code_with_pipe(command, code_in, post_process=[]):
71
71
runner ['with' ] = 'runghc' # default is runghc, no hooks
72
72
73
73
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 ()
74
76
# if running with ghci then we post process the output to remove
75
77
# ghci specific text
76
78
post_process += [lambda s : s .replace ("ghci>" ,"" ),
@@ -87,18 +89,26 @@ def execute_code_with_pipe(command, code_in, post_process=[]):
87
89
out = comp_proc .stdout
88
90
err = comp_proc .stderr
89
91
code_out = out
90
- found = False
91
92
93
+ ## control the output
92
94
out_stream = code_out .splitlines ()
95
+ linking_index = 0
93
96
for index , line in enumerate (out_stream ):
94
97
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 :
102
112
print (err ) # should use sphinx logger
103
113
104
114
else :
@@ -120,7 +130,7 @@ def execute_code_with_pipe(command, code_in, post_process=[]):
120
130
out = comp_proc .stdout .decode ('utf-8' )
121
131
err = comp_proc .stderr
122
132
# Log any stderr.
123
- if err is not None and err .strip () != "" :
133
+ if err is not None and len ( err .strip ()) > 0 :
124
134
print (err )
125
135
code_out = out
126
136
@@ -164,6 +174,7 @@ class Exec(Directive):
164
174
'context' : _option_boolean ,
165
175
'cache' : _option_boolean ,
166
176
'process' : _option_process ,
177
+ 'output' : _option_str ,
167
178
'intertext' : _option_str ,
168
179
'project_dir' : _option_str ,
169
180
'with' : _option_str ,
@@ -192,6 +203,7 @@ def run(self):
192
203
project_dir = self .options .get ('project_dir' , '' )
193
204
opt_with = self .options .get ('with' , '' )
194
205
args = self .options .get ('args' ,'' ).split ()
206
+ output = self .options .get ('output' ,'' )
195
207
196
208
# A runner is "that which runs the code", i.e., a dictionary that
197
209
# defines the entire external process
@@ -204,7 +216,8 @@ def run(self):
204
216
# the contents of source_file,
205
217
# if not then its the contents
206
218
# 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
208
221
209
222
# Determine whether input is to be read from a file, or directly from
210
223
# the exec block's contents.
0 commit comments