def make_envvar(name): """Makes a StoreNonEmpty node for an environment variable.""" env = builtins.__xonsh__.env vd = env.get_docs(name) if not vd.configurable: return default = vd.default if "\n" in default: default = "\n" + _wrap_paragraphs(default, width=69) curr = env.get(name) if is_string(curr) and is_template_string(curr): curr = curr.replace("{", "{{").replace("}", "}}") curr = pprint.pformat(curr, width=69) if "\n" in curr: curr = "\n" + curr msg = ENVVAR_MESSAGE.format( name=name, default=default, current=curr, docstr=_wrap_paragraphs(vd.docstr, width=69), ) mnode = wiz.Message(message=msg) ens = env.get_ensurer(name) path = "/env/" + name pnode = wiz.StoreNonEmpty( ENVVAR_PROMPT, converter=ens.convert, show_conversion=True, path=path, retry=True, store_raw=vd.store_as_str, ) return mnode, pnode
def make_envvar(name): """Makes a StoreNonEmpty node for an environment variable.""" env = builtins.__xonsh_env__ vd = env.get_docs(name) if not vd.configurable: return default = vd.default if '\n' in default: default = '\n' + _wrap_paragraphs(default, width=69) curr = env.get(name) if is_string(curr) and is_template_string(curr): curr = curr.replace('{', '{{').replace('}', '}}') curr = pprint.pformat(curr, width=69) if '\n' in curr: curr = '\n' + curr msg = ENVVAR_MESSAGE.format(name=name, default=default, current=curr, docstr=_wrap_paragraphs(vd.docstr, width=69)) mnode = wiz.Message(message=msg) ens = env.get_ensurer(name) path = '/env/' + name pnode = wiz.StoreNonEmpty(ENVVAR_PROMPT, converter=ens.convert, show_conversion=True, path=path, retry=True, store_raw=vd.store_as_str) return mnode, pnode
def make_envvar(name): """Makes a StoreNonEmpty node for an environment variable.""" env = builtins.__xonsh__.env vd = env.get_docs(name) if not vd.doc_configurable: return default = vd.doc_default if "\n" in default: default = "\n" + _wrap_paragraphs(default, width=69) curr = env.get(name) if is_string(curr) and is_template_string(curr): curr = curr.replace("{", "{{").replace("}", "}}") curr = pprint.pformat(curr, width=69) if "\n" in curr: curr = "\n" + curr msg = ENVVAR_MESSAGE.format( name=name, default=default, current=curr, docstr=_wrap_paragraphs(vd.doc, width=69), ) mnode = wiz.Message(message=msg) converter = env.get_converter(name) path = "/env/" + name pnode = wiz.StoreNonEmpty( ENVVAR_PROMPT, converter=converter, show_conversion=True, path=path, retry=True, store_raw=vd.doc_store_as_str, ) return mnode, pnode
def _cmd_filter(cmds, pat): if isinstance(pat, (int, slice)): s = xt.ensure_slice(pat) yield from xt.get_portions(cmds, s) elif xt.is_string(pat): for command in reversed(list(cmds)): if pat in command: yield command return else: raise TypeError('Command filter must be string, int or slice')
def make_envvar(name): """Makes a StoreNonEmpty node for an environment variable.""" env = builtins.__xonsh_env__ vd = env.get_docs(name) if not vd.configurable: return default = vd.default if '\n' in default: default = '\n' + _wrap_paragraphs(default, width=69) curr = env.get(name) if tools.is_string(curr) and is_template_string(curr): curr = curr.replace('{', '{{').replace('}', '}}') curr = pformat(curr, width=69) if '\n' in curr: curr = '\n' + curr prompt = ENVVAR_PROMPT.format(name=name, default=default, current=curr, docstr=_wrap_paragraphs(vd.docstr, width=69)) ens = env.get_ensurer(name) path = '/env/' + name node = StoreNonEmpty(prompt, converter=ens.convert, show_conversion=True, path=path) return node
def make_envvar(name): """Makes a StoreNonEmpty node for an environment variable.""" env = builtins.__xonsh_env__ vd = env.get_docs(name) if not vd.configurable: return default = vd.default if '\n' in default: default = '\n' + _wrap_paragraphs(default, width=69) curr = env.get(name) if is_string(curr) and is_template_string(curr): curr = curr.replace('{', '{{').replace('}', '}}') curr = pformat(curr, width=69) if '\n' in curr: curr = '\n' + curr msg = ENVVAR_MESSAGE.format(name=name, default=default, current=curr, docstr=_wrap_paragraphs(vd.docstr, width=69)) mnode = wiz.Message(message=msg) ens = env.get_ensurer(name) path = '/env/' + name pnode = wiz.StoreNonEmpty(ENVVAR_PROMPT, converter=ens.convert, show_conversion=True, path=path, retry=True, store_raw=vd.store_as_str) return mnode, pnode
def test_is_string_or_callable(): yield assert_true, is_string_or_callable('42.0') yield assert_true, is_string_or_callable(lambda: 42.0) yield assert_false, is_string(42.0)
def test_is_string_or_callable_false(): assert not is_string(42.0)
def test_is_string_false(): assert not is_string(42.0)
def test_is_string_true(): assert is_string("42.0")
def test_is_string(): yield assert_true, is_string('42.0') yield assert_false, is_string(42.0)
def test_is_string_true(): assert is_string('42.0')
def test_is_string_or_callable(): assert is_string_or_callable('42.0') assert is_string_or_callable(lambda: 42.0) assert not is_string(42.0)
def test_is_string(): assert is_string('42.0') assert not is_string(42.0)