Navigation Menu

Skip to content

Commit

Permalink
fix: xonfig web is not upto-date (#4606)
Browse files Browse the repository at this point in the history
* fix: xonfig web is not upto-date

it should load data from backend

* refactor: update elm-compile module

* feat: update `xonfig web`

* todo:

* style:

* tmp

* feat: implements colors page

* feat: implement prompts page

* feat: implement xontribs page

* refactor: remove elm from project

* fix: qa errors

* docs:

* test: add test for xonfig.web

* fix: lru-cache call

* feat: add env variable for sys level config dir

* refactor: add method to handle post

* feat: implement updating prompts

* feat: implement xontribs update page

* style:

* fix: tests failure

* feat: add variables page

* feat: add abbrevs,aliases pages

* feat: run xonfig web in main process

this way we can update the current session

* style: optimize imports

* docs:

* refactor: write .xonshrc as the old code

* refactor: split file write functions
  • Loading branch information
jnoortheen committed Jan 18, 2022
1 parent a00b601 commit 0ea9dd8
Show file tree
Hide file tree
Showing 19 changed files with 4,952 additions and 835 deletions.
36 changes: 0 additions & 36 deletions .github/workflows/elm.yml

This file was deleted.

10 changes: 0 additions & 10 deletions ci/environment-elm.yml

This file was deleted.

23 changes: 23 additions & 0 deletions news/webconfig.rst
@@ -0,0 +1,23 @@
**Added:**

* ``xonfig web`` can now update ``abbrevs/aliases/env-variables``.

**Changed:**

* ``xonfig web`` now shows latest xontribs available from ``xonsh.xontribs_meta``

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
62 changes: 61 additions & 1 deletion tests/test_xonfig.py
Expand Up @@ -10,9 +10,10 @@
import sys
import json
import pytest # noqa F401

import io
from xonsh.tools import ON_WINDOWS
from xonsh.xonfig import xonfig_main
from xonsh.webconfig import main as web_main


def test_xonfg_help(capsys, xession):
Expand Down Expand Up @@ -132,3 +133,62 @@ def mock_get_kernel_spec(*args, **kwargs):
def test_xonfig_kernel_no_jupyter(capsys, xession):
with pytest.raises(ImportError):
rc = xonfig_main(["jupyter-kernel"]) # noqa F841


@pytest.fixture
def request_factory():
class MockSocket:
def getsockname(self):
return ("sockname",)

def sendall(self, data):
self.data = data

class MockRequest:
_sock = MockSocket()

def __init__(self, path: str, method: str):
self._path = path
self.data = b""
self.method = method.upper()

def makefile(self, *args, **kwargs):
if args[0] == "rb":
return io.BytesIO(f"{self.method} {self._path} HTTP/1.0".encode())
elif args[0] == "wb":
return io.BytesIO(b"")
else:
raise ValueError("Unknown file type to make", args, kwargs)

def sendall(self, data):
self.data = data

return MockRequest


@pytest.fixture
def get_req(request_factory):
from urllib import parse

def factory(path, data: "dict[str, str]|None" = None):
if data:
path = path + "?" + parse.urlencode(data)
request = request_factory(path, "get")
handle = web_main.XonshConfigHTTPRequestHandler(request, (0, 0), None)
return request, handle, request.data.decode()

return factory


class TestXonfigWeb:
def test_colors_get(self, get_req):
_, _, resp = get_req("/")
assert "Colors" in resp

def test_xontribs_get(self, get_req):
_, _, resp = get_req("/xontribs")
assert "Xontribs" in resp

def test_prompts_get(self, get_req):
_, _, resp = get_req("/prompts")
assert "Prompts" in resp
16 changes: 10 additions & 6 deletions xonsh/environ.py
Expand Up @@ -667,12 +667,6 @@ def default_completer_dirs(env):
]


@default_value
def xonfig_data_files(env):
"""``['$XONSH_SYS_CONFIG_DIR/xonfig-data.json', '$XONSH_CONFIG_DIR/xonfig-data.json']``\n"""
return get_config_paths(env, "xonfig-data.json")


@default_value
def xonsh_append_newline(env):
"""Appends a newline if we are in interactive mode"""
Expand Down Expand Up @@ -2156,6 +2150,11 @@ def get(self, key, default=None):
else:
return default

def get_stringified(self, key, default=None):
value = self.get(key, default)
detyper = self.get_detyper(key)
return detyper(value)

def rawkeys(self):
"""An iterator that returns all environment keys in their original form.
This include string & compiled regular expression keys.
Expand Down Expand Up @@ -2281,6 +2280,11 @@ def deregister(self, name):
"""
self._vars.pop(name)

def is_configurable(self, name):
if name not in self._vars:
return False
return self._vars[name].is_configurable


class InternalEnvironDict(ChainMap):
"""A dictionary which supports thread-local overrides.
Expand Down

0 comments on commit 0ea9dd8

Please sign in to comment.