Repository: readthedocs/readthedocs.org

Issue:
Disable coloring of the build log output
## Details

* Read the Docs project URL: 
* Build URL (if applicable): https://readthedocs.org/projects/adaptive/builds/10795488/
* Read the Docs username (if applicable): basnijholt

On Gitter @agjohnson, recommended me to open an issue.

## Expected Result

The logs below without the terminal color tags (e.g., `[0;32`).

## Actual Result

The logs look like:
```
sphinx.errors.ExtensionError: Cell raised uncaught exception:
[0;31m---------------------------------------------------------------------------[0m
[0;31mValueError[0m                                Traceback (most recent call last)
[0;32m<ipython-input-4-ab5a0b966deb>[0m in [0;36m<module>[0;34m[0m
[1;32m     11[0m     [0;32mreturn[0m [0mlearner[0m[0;34m.[0m[0mplot[0m[0;34m([0m[0;34m)[0m[0;34m.[0m[0mrelabel[0m[0;34m([0m[0;34mf'loss={learner.loss():.2f}'[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
[1;32m     12[0m [0;34m[0m[0m
[0;32m---> 13[0;31m [0mplots[0m [0;34m=[0m [0;34m{[0m[0mn[0m[0;34m:[0m [0mplot[0m[0;34m([0m[0mlearner[0m[0;34m,[0m [0mn[0m[0;34m)[0m [0;32mfor[0m [0mn[0m [0;32min[0m [0mrange[0m[0;34m([0m[0;36m10[0m[0;34m,[0m [0;36m10000[0m[0;34m,[0m [0;36m200[0m[0;34m)[0m[0;34m}[0m[0;34m[0m[0;34m[0m[0m
[0m[1;32m     14[0m [0mhv[0m[0;34m.[0m[0mHoloMap[0m[0;34m([0m[0mplots[0m[0;34m,[0m [0mkdims[0m[0;34m=[0m[0;34m[[0m[0;34m'npoints'[0m[0;34m][0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
```


Discussion:
@basnijholt just for confirmation do you know if this is actually from sphinx or from a sphinx extension? In the later case, don't think we can do much. I think we can set the `NO_COLOR` env https://no-color.org (in case sphinx doesn't respect that, we need to check if sphinx has an option)
It's actually coming from a Sphinx extension: https://github.com/jupyter/jupyter-sphinx
So, I think the extension should detect if it's running on a interactive terminal or not or respect the `NO_COLOR` env var. Don't think we are going to implement something to remove the color escape codes from the output.
@jbweston and @akhmerov, do you know if you could fix this in Jupyter Sphinx? 
@basnijholt have you tried setting `NO_COLOR` in Read the Docs as @stsewd suggested?
@humitos I don't think that package respects that env var, and we should set that env var by default for other tools who respect it.
@basnijholt this should be fairly simple. We just need to strip out the coloring from the traceback [here](https://github.com/jupyter/jupyter-sphinx/blob/master/jupyter_sphinx/execute.py#L148).

I've opened an issue for this upstream: https://github.com/jupyter/jupyter-sphinx/issues/115

Resolving patch:
diff --git a/readthedocs/projects/tasks.py b/readthedocs/projects/tasks.py
--- a/readthedocs/projects/tasks.py
+++ b/readthedocs/projects/tasks.py
@@ -882,6 +882,9 @@ def get_env_vars(self):
         """Get bash environment variables used for all builder commands."""
         env = self.get_rtd_env_vars()
 
+        # https://no-color.org/
+        env['NO_COLOR'] = '1'
+
         if self.config.conda is not None:
             env.update({
                 'CONDA_ENVS_PATH': os.path.join(self.project.doc_path, 'conda'),


Test patch:
diff --git a/readthedocs/rtd_tests/tests/test_builds.py b/readthedocs/rtd_tests/tests/test_builds.py
--- a/readthedocs/rtd_tests/tests/test_builds.py
+++ b/readthedocs/rtd_tests/tests/test_builds.py
@@ -349,6 +349,7 @@ def test_get_env_vars(self):
         task.config = mock.Mock(conda=None)
 
         env = {
+            'NO_COLOR': '1',
             'READTHEDOCS': 'True',
             'READTHEDOCS_VERSION': version.slug,
             'READTHEDOCS_PROJECT': project.slug,