|
1 | 1 | import csv |
| 2 | +import os |
2 | 3 | import re |
3 | 4 | import shlex |
4 | 5 | import subprocess |
@@ -57,13 +58,21 @@ def run_command(command, working_directory): |
57 | 58 | # The subprocess Popen function takes a ``cwd`` argument that |
58 | 59 | # conveniently changes the working directory to run the command. |
59 | 60 | # |
60 | | - # Furthermore, we also patched the stderr to redirect to STDOUT, |
| 61 | + # We also patched the stderr to redirect to STDOUT, |
61 | 62 | # so that stderr and stdout appear in order, as you would see in |
62 | 63 | # a terminal. |
| 64 | + # |
| 65 | + # Finally, note that ``cwltool`` by default emits ANSI colors in the |
| 66 | + # terminal, which are harder to be parsed and/or rendered in Sphinx. |
| 67 | + # For that reason, we define --disable-color in the CWLTOOL_OPTIONS |
| 68 | + # environment variable, which is used by ``cwltool``. |
63 | 69 | # TODO: PATCHED |
| 70 | + env = os.environ |
| 71 | + env['CWLTOOL_OPTIONS'] = '--disable-color' |
64 | 72 | subp = subprocess.Popen( |
65 | 73 | true_cmd, |
66 | 74 | cwd=working_directory, |
| 75 | + env=env, |
67 | 76 | stdout=subprocess.PIPE, |
68 | 77 | stderr=subprocess.STDOUT |
69 | 78 | ) |
@@ -135,11 +144,7 @@ def run(self): |
135 | 144 |
|
136 | 145 | # Grab our custom commands |
137 | 146 | syntax = self.options.get("syntax", "bash") # TODO: PATCHED |
138 | | - # N.B. ``cwltool`` by default emits output with colors, unless disabled |
139 | | - # via a command line flag. There is no way to disable via env-vars |
140 | | - # so we replace it via regexes. |
141 | | - # Source: https://superuser.com/questions/380772/removing-ansi-color-codes-from-text-stream |
142 | | - replace = self.options.get("replace", '"\\[[0-9;]+m/","\\x1b/"') # TODO: PATCHED |
| 147 | + replace = self.options.get("replace", '') |
143 | 148 | reader = csv.reader([replace], delimiter=",", escapechar="\\") |
144 | 149 | # prompt = "prompt" in self.options |
145 | 150 | # We patched this so that the prompt is displayed by default, similar |
|
0 commit comments