Skip to content

Commit 11cf58b

Browse files
kinowmr-c
authored andcommitted
USe CWLTOOL_OPTIONS to disable terminal colors (thanks @mr-c !)
1 parent 4489d99 commit 11cf58b

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

cwl/sphinx/runcmd.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import csv
2+
import os
23
import re
34
import shlex
45
import subprocess
@@ -57,13 +58,21 @@ def run_command(command, working_directory):
5758
# The subprocess Popen function takes a ``cwd`` argument that
5859
# conveniently changes the working directory to run the command.
5960
#
60-
# Furthermore, we also patched the stderr to redirect to STDOUT,
61+
# We also patched the stderr to redirect to STDOUT,
6162
# so that stderr and stdout appear in order, as you would see in
6263
# 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``.
6369
# TODO: PATCHED
70+
env = os.environ
71+
env['CWLTOOL_OPTIONS'] = '--disable-color'
6472
subp = subprocess.Popen(
6573
true_cmd,
6674
cwd=working_directory,
75+
env=env,
6776
stdout=subprocess.PIPE,
6877
stderr=subprocess.STDOUT
6978
)
@@ -135,11 +144,7 @@ def run(self):
135144

136145
# Grab our custom commands
137146
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", '')
143148
reader = csv.reader([replace], delimiter=",", escapechar="\\")
144149
# prompt = "prompt" in self.options
145150
# We patched this so that the prompt is displayed by default, similar

0 commit comments

Comments
 (0)