Repository: xonsh/xonsh

Issue:
doc builds failing on 0.11.0 (KeyError in tracer)
Attempting to release 0.11.0, doc builds were failing with:

```
make html
sphinx-build -b html -d _build/doctrees   . _build/html
Running Sphinx v4.0.0
/opt/miniconda3/envs/xonshdocs/lib/python3.9/site-packages/cloud_sptheme/__init__.py:78: DeprecationWarning: get_theme_dir() is deprecated, and will be removed in version 2.0
  warn("get_theme_dir() is deprecated, and will be removed in version 2.0",
WARNING: The config value `autosummary_generate' has type `list'; expected `bool'.
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 134 source files that are out of date
updating environment: [new config] 134 added, 0 changed, 0 removed
reading sources... [  1%] aliases                                                                                                                                                                                    
Exception occurred:
  File "/home/gil/github.com/xonsh/xonsh/xonsh/tracer.py", line 225, in __call__
    spec = kwargs["spec"]
KeyError: 'spec'
The full traceback has been saved in /tmp/sphinx-err-f691khg5.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
make: *** [Makefile:39: html] Error 2
```

Until I hack-patched it thus:
```
diff --git a/xonsh/tracer.py b/xonsh/tracer.py
index 3457f241..fb53f0fe 100644
--- a/xonsh/tracer.py
+++ b/xonsh/tracer.py
@@ -222,11 +222,14 @@ class TracerAlias(ArgParserAlias):
         return parser
 
     def __call__(self, *args, **kwargs):
-        spec = kwargs["spec"]
-        usecolor = (
-            spec.captured not in xpp.STDOUT_CAPTURE_KINDS
-        ) and sys.stdout.isatty()
-        tracer.color_output(usecolor)
+        try:
+            spec = kwargs["spec"]
+            usecolor = (
+                spec.captured not in xpp.STDOUT_CAPTURE_KINDS
+            ) and sys.stdout.isatty()
+            tracer.color_output(usecolor)
+        except KeyError:
+            pass
         return super().__call__(*args, **kwargs)
 ```


Discussion:
I have the same error but my traceback is a bit different:
```
reading sources... [  1%] aliases                                                                                                                                                                                                            
Exception occurred:
  File "/home/abuild/rpmbuild/BUILD/xonsh-0.11.0/xonsh/__amalgam__.py", line 22876, in __call__
    spec = kwargs["spec"]
KeyError: 'spec'
```
In my case the error is not thrown in `tracer.py`, but in `__amalgam__.py`. Still the proposed patch solves the problem.
@gforsyth Do you want to create a Pull Request?
@sebix -- `__amalgam__.py` is created at install time to save a _very tiny bit_ of startup time.  If you ever want to track down the _actual_ location of the code, you can start `xonsh` with `XONSH_DEBUG=1` and it will "de-amalgamate"

I'll PR something in if no one else gets to it
cc @jnoortheen who I think made the changes to the tracer and may have some insight on the root cause
@gforsyth I will check it later. It is called without all the required parameters of calling an alias function. I am not sure why it gets called during docs build though. 

Resolving patch:
diff --git a/xonsh/tracer.py b/xonsh/tracer.py
--- a/xonsh/tracer.py
+++ b/xonsh/tracer.py
@@ -222,9 +222,9 @@ def build(self):
         return parser
 
     def __call__(self, *args, **kwargs):
-        spec = kwargs["spec"]
+        spec = kwargs.get("spec")
         usecolor = (
-            spec.captured not in xpp.STDOUT_CAPTURE_KINDS
+            spec and (spec.captured not in xpp.STDOUT_CAPTURE_KINDS)
         ) and sys.stdout.isatty()
         tracer.color_output(usecolor)
         return super().__call__(*args, **kwargs)


Test patch: