Repository: xonsh/xonsh

Issue:
xonfig web fails with AssertionError
Steps to reproduce on macOS 12.5.1:

* brew install xonsh
* xonfig web

Webpage doesn't load for long time. Then error in console appears: `Failed to parse color-display ParseError('syntax error: line 1, column 0')`

Details:

<details>

```
(base) maye@Michaels-Mini ~/.config $ xonfig web
Web config started at 'http://localhost:8421'. Hit Crtl+C to stop.
ERROR:root:Failed to format Xonsh code AssertionError("wrong color format 'noinherit'"). 'bw'
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/xonsh_data.py", line 194, in render_colors
    display = html_format(token_stream, style=style)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/xonsh_data.py", line 51, in html_format
    proxy_style = xonsh_style_proxy(XonshStyle(style))
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/pyghooks.py", line 453, in xonsh_style_proxy
    class XonshStyleProxy(Style):
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/pygments/style.py", line 112, in __new__
    ndef[4] = colorformat(styledef[3:])
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/pygments/style.py", line 79, in colorformat
    assert False, "wrong color format %r" % text
AssertionError: wrong color format 'noinherit'
ERROR:root:Failed to parse color-display ParseError('syntax error: line 1, column 0'). 'import sys\necho "Welcome $USER on" @(sys.platform)\n\ndef func(x=42):\n    d = {"xonsh": True}\n    return d.get("xonsh") and you\n\n# This is a comment\n![env | uniq | sort | grep PATH]\n'
127.0.0.1 - - [08/Sep/2022 20:52:46] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [08/Sep/2022 20:52:47] "GET /js/bootstrap.min.css HTTP/1.1" 200 -
127.0.0.1 - - [08/Sep/2022 20:52:47] code 404, message File not found
127.0.0.1 - - [08/Sep/2022 20:52:47] "GET /js/xonsh_sticker.svg HTTP/1.1" 404 -
127.0.0.1 - - [08/Sep/2022 20:52:47] code 404, message File not found
127.0.0.1 - - [08/Sep/2022 20:52:47] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [08/Sep/2022 20:52:47] code 404, message File not found
127.0.0.1 - - [08/Sep/2022 20:52:47] "GET /apple-touch-icon-precomposed.png HTTP/1.1" 404 -
127.0.0.1 - - [08/Sep/2022 20:52:47] code 404, message File not found
127.0.0.1 - - [08/Sep/2022 20:52:47] "GET /apple-touch-icon.png HTTP/1.1" 404 -
```
and then wepage loads visually, but any interaction get's a "Safari can't load server" because the process died in the terminal.

A 2nd launch of `xonsh web` throws now a huge error:

```
/xonsh/webconfig stable $ xonfig web
Web config started at 'http://localhost:8421'. Hit Crtl+C to stop.
--- Logging error ---
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/xonsh_data.py", line 194, in render_colors
    display = html_format(token_stream, style=style)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/xonsh_data.py", line 51, in html_format
    proxy_style = xonsh_style_proxy(XonshStyle(style))
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/pyghooks.py", line 453, in xonsh_style_proxy
    class XonshStyleProxy(Style):
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/pygments/style.py", line 112, in __new__
    ndef[4] = colorformat(styledef[3:])
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/pygments/style.py", line 79, in colorformat
    assert False, "wrong color format %r" % text
AssertionError: wrong color format 'noinherit'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/logging/__init__.py", line 1103, in emit
    stream.write(msg + self.terminator)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/base_shell.py", line 182, in write
    self.mem.write(s)
ValueError: I/O operation on closed file.
Call stack:
  File "/opt/homebrew/bin/xonsh", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/main.py", line 468, in main
    sys.exit(main_xonsh(args))
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/main.py", line 512, in main_xonsh
    shell.shell.cmdloop()
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/ptk_shell/shell.py", line 407, in cmdloop
    self.default(line, raw_line)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/base_shell.py", line 389, in default
    exc_info = run_compiled_code(code, self.ctx, None, "single")
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/codecache.py", line 63, in run_compiled_code
    func(code, glb, loc)
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/built_ins.py", line 196, in subproc_captured_hiddenobject
    return xonsh.procs.specs.run_subproc(cmds, captured="hiddenobject", envs=envs)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/procs/specs.py", line 896, in run_subproc
    return _run_specs(specs, cmds)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/procs/specs.py", line 931, in _run_specs
    command.end()
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/procs/pipelines.py", line 458, in end
    self._end(tee_output=tee_output)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/procs/pipelines.py", line 466, in _end
    for _ in self.tee_stdout():
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/procs/pipelines.py", line 368, in tee_stdout
    for line in self.iterraw():
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/procs/pipelines.py", line 255, in iterraw
    proc.wait()
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/procs/proxies.py", line 820, in wait
    r = self.f(self.args, stdin, stdout, stderr, spec, spec.stack)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/lazyasd.py", line 80, in __call__
    return obj(*args, **kwargs)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/cli_utils.py", line 676, in __call__
    result = dispatch(
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/cli_utils.py", line 425, in dispatch
    return _dispatch_func(func, ns)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/cli_utils.py", line 398, in _dispatch_func
    return func(**kwargs)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/xonfig.py", line 703, in _web
    main.main(_args[1:])
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/main.py", line 183, in main
    serve(ns.browser)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/main.py", line 169, in serve
    httpd.serve_forever()
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socketserver.py", line 237, in serve_forever
    self._handle_request_noblock()
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socketserver.py", line 316, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socketserver.py", line 347, in process_request
    self.finish_request(request, client_address)
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/server.py", line 658, in __init__
    super().__init__(*args, **kwargs)
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socketserver.py", line 747, in __init__
    self.handle()
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/server.py", line 432, in handle
    self.handle_one_request()
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/server.py", line 420, in handle_one_request
    method()
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/main.py", line 87, in do_GET
    route = self._get_route("get")
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/main.py", line 84, in _get_route
    return route_cls(url=url, params=params, xsh=XSH)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/routes.py", line 91, in __init__
    self.colors = dict(xonsh_data.render_colors())
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/xonsh_data.py", line 196, in render_colors
    logging.error(
Message: 'Failed to format Xonsh code AssertionError("wrong color format \'noinherit\'"). \'bw\''
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/routes.py", line 74, in get_display
    display = t.etree.fromstring(display)
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/xml/etree/ElementTree.py", line 1342, in XML
    parser.feed(text)
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/logging/__init__.py", line 1103, in emit
    stream.write(msg + self.terminator)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/base_shell.py", line 182, in write
    self.mem.write(s)
ValueError: I/O operation on closed file.
Call stack:
  File "/opt/homebrew/bin/xonsh", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/main.py", line 468, in main
    sys.exit(main_xonsh(args))
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/main.py", line 512, in main_xonsh
    shell.shell.cmdloop()
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/ptk_shell/shell.py", line 407, in cmdloop
    self.default(line, raw_line)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/base_shell.py", line 389, in default
    exc_info = run_compiled_code(code, self.ctx, None, "single")
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/codecache.py", line 63, in run_compiled_code
    func(code, glb, loc)
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/built_ins.py", line 196, in subproc_captured_hiddenobject
    return xonsh.procs.specs.run_subproc(cmds, captured="hiddenobject", envs=envs)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/procs/specs.py", line 896, in run_subproc
    return _run_specs(specs, cmds)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/procs/specs.py", line 931, in _run_specs
    command.end()
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/procs/pipelines.py", line 458, in end
    self._end(tee_output=tee_output)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/procs/pipelines.py", line 466, in _end
    for _ in self.tee_stdout():
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/procs/pipelines.py", line 368, in tee_stdout
    for line in self.iterraw():
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/procs/pipelines.py", line 255, in iterraw
    proc.wait()
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/procs/proxies.py", line 820, in wait
    r = self.f(self.args, stdin, stdout, stderr, spec, spec.stack)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/lazyasd.py", line 80, in __call__
    return obj(*args, **kwargs)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/cli_utils.py", line 676, in __call__
    result = dispatch(
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/cli_utils.py", line 425, in dispatch
    return _dispatch_func(func, ns)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/cli_utils.py", line 398, in _dispatch_func
    return func(**kwargs)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/xonfig.py", line 703, in _web
    main.main(_args[1:])
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/main.py", line 183, in main
    serve(ns.browser)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/main.py", line 169, in serve
    httpd.serve_forever()
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socketserver.py", line 237, in serve_forever
    self._handle_request_noblock()
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socketserver.py", line 316, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socketserver.py", line 347, in process_request
    self.finish_request(request, client_address)
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/server.py", line 658, in __init__
    super().__init__(*args, **kwargs)
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socketserver.py", line 747, in __init__
    self.handle()
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/server.py", line 432, in handle
    self.handle_one_request()
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/server.py", line 420, in handle_one_request
    method()
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/main.py", line 89, in do_GET
    return self.render_get(route)
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/main.py", line 75, in render_get
    body = t.to_str(route.get())  # type: ignore
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/tags.py", line 125, in to_str
    txt = b"".join(_to_str()).decode()
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/tags.py", line 116, in _to_str
    for idx, el in enumerate(elems):
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/routes.py", line 145, in get
    cols = list(self.get_cols())
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/routes.py", line 107, in get_cols
    self.to_card(name, display),
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/routes.py", line 100, in to_card
    self.get_display(display),
  File "/opt/homebrew/Cellar/xonsh/0.13.1/libexec/lib/python3.10/site-packages/xonsh/webconfig/routes.py", line 76, in get_display
    logging.error(f"Failed to parse color-display {ex!r}. {display!r}")
Message: 'Failed to parse color-display ParseError(\'syntax error: line 1, column 0\'). \'import sys\\necho "Welcome $USER on" @(sys.platform)\\n\\ndef func(x=42):\\n    d = {"xonsh": True}\\n    return d.get("xonsh") and you\\n\\n# This is a comment\\n![env | uniq | sort | grep PATH]\\n\''
Arguments: ()
127.0.0.1 - - [08/Sep/2022 20:57:36] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [08/Sep/2022 20:57:36] code 404, message File not found
127.0.0.1 - - [08/Sep/2022 20:57:36] "GET /js/xonsh_sticker.svg HTTP/1.1" 404 -
```

Ok, so much for my yearly check-in with xonsh. See you next year! :)

</details>


Discussion:
Personally I prefer to install Python and xonsh using [xonsh-cheatsheet](https://github.com/anki-code/xonsh-cheatsheet#install-xonsh-on-mac-os-or-linux) and I'm not facing with this kind of errors. Using `brew` is not the good way to install Python and the packages on Mac.
I also have issues with `xonfig web` although the exact error is slightly different, I can get to the web page but it doesnt seem like it saves anything (and I don't have the save button the docs talk about). If I exit xonsh and restart it all my customizations are gone.

This is a fresh install of xonsh using `python -m pip install 'xonsh[full]'` i.e. the most recommended way to install it (on Arch Linux BTW).

The other issue I notice is 

```
$ xpip
xonsh: subprocess mode: permission denied: xpip
```
and the `xpip` alias is set to `None` according to `xonfig web`. 

Again this is a completely fresh install. 


xpip issue was #4922

You probably want to push out another release asap so that new people dont get a broken install, xpip is kind of important

also a little concerning that `.extend` bug was in there in the first place to be honest
@gforsyth it looks like we need a new release to rollout the fix for `xpip`.
Cut a new release, but it looks like the original traceback is coming from that `noinherit` style bug xref #4432 
Actually, I'm going to close this out as a duplicate of #4432 
Yes looks like a duplicate to me, my `xonfig web` shows the same `noinherit` error also. Thanks for the new release

Resolving patch:
diff --git a/xonsh/pyghooks.py b/xonsh/pyghooks.py
--- a/xonsh/pyghooks.py
+++ b/xonsh/pyghooks.py
@@ -177,7 +177,10 @@ def color_name_to_pygments_code(name, styles):
             fgcolor = color
         else:
             fgcolor = styles[getattr(Color, color)]
-        res = "bg:" + fgcolor
+        if fgcolor == "noinherit":
+            res = "noinherit"
+        else:
+            res = f"bg:{fgcolor}"
     else:
         # have regular, non-background color
         mods = parts["modifiers"]


Test patch: