mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72fa154f8f
commit
e68dc16c2c
39 changed files with 132 additions and 184 deletions
|
@ -38,7 +38,7 @@ def test_command_not_found(monkeypatch):
|
||||||
|
|
||||||
assert xexec([command]) == (
|
assert xexec([command]) == (
|
||||||
None,
|
None,
|
||||||
f"xonsh: exec: file not found: {dummy_error_msg}: {command}" "\n",
|
f"xonsh: exec: file not found: {dummy_error_msg}: {command}\n",
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ TREE1 = Question("wakka?", {"jawaka": Pass()})
|
||||||
|
|
||||||
|
|
||||||
def test_pretty_format_tree0():
|
def test_pretty_format_tree0():
|
||||||
exp = "Wizard(children=[\n" " Pass(),\n" " Message('yo')\n" "])"
|
exp = "Wizard(children=[\n Pass(),\n Message('yo')\n])"
|
||||||
obs = PrettyFormatter(TREE0).visit()
|
obs = PrettyFormatter(TREE0).visit()
|
||||||
assert exp == obs
|
assert exp == obs
|
||||||
assert exp == str(TREE0)
|
assert exp == str(TREE0)
|
||||||
|
@ -27,14 +27,7 @@ def test_pretty_format_tree0():
|
||||||
|
|
||||||
|
|
||||||
def test_pretty_format_tree1():
|
def test_pretty_format_tree1():
|
||||||
exp = (
|
exp = "Question(\n question='wakka?',\n responses={\n 'jawaka': Pass()\n }\n)"
|
||||||
"Question(\n"
|
|
||||||
" question='wakka?',\n"
|
|
||||||
" responses={\n"
|
|
||||||
" 'jawaka': Pass()\n"
|
|
||||||
" }\n"
|
|
||||||
")"
|
|
||||||
)
|
|
||||||
obs = PrettyFormatter(TREE1).visit()
|
obs = PrettyFormatter(TREE1).visit()
|
||||||
assert exp == obs
|
assert exp == obs
|
||||||
assert exp == str(TREE1)
|
assert exp == str(TREE1)
|
||||||
|
|
|
@ -408,7 +408,7 @@ def history_files_list(gen_count) -> (float, int, str, int):
|
||||||
# first day in sec + #days * 24hr + #hr * 60min + # sec * 60sec + sec= sec to date.
|
# first day in sec + #days * 24hr + #hr * 60min + # sec * 60sec + sec= sec to date.
|
||||||
HF_FIRST_DAY + (((((i * 24) + 9) * 60) + 0) * 60) + 0, # mod dt,
|
HF_FIRST_DAY + (((((i * 24) + 9) * 60) + 0) * 60) + 0, # mod dt,
|
||||||
100,
|
100,
|
||||||
f".argle/xonsh-{2*i:05n}.json",
|
f".argle/xonsh-{2 * i:05n}.json",
|
||||||
10000,
|
10000,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -417,7 +417,7 @@ def history_files_list(gen_count) -> (float, int, str, int):
|
||||||
# first day in sec + #days * 24hr + #hr * 60min + # sec * 60sec + sec= sec to date.
|
# first day in sec + #days * 24hr + #hr * 60min + # sec * 60sec + sec= sec to date.
|
||||||
HF_FIRST_DAY + (((((i * 24) + 23) * 60) + 0) * 60) + 0, # mod dt,
|
HF_FIRST_DAY + (((((i * 24) + 23) * 60) + 0) * 60) + 0, # mod dt,
|
||||||
50,
|
50,
|
||||||
f".argle/xonsh-{2*i+1:05n}.json",
|
f".argle/xonsh-{2 * i + 1:05n}.json",
|
||||||
2500,
|
2500,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -246,11 +246,7 @@ def test_not_really_or_pre_post():
|
||||||
|
|
||||||
|
|
||||||
def test_subproc_line_cont_space():
|
def test_subproc_line_cont_space():
|
||||||
inp = (
|
inp = "![echo --option1 value1 \\\n --option2 value2 \\\n --optionZ valueZ]"
|
||||||
"![echo --option1 value1 \\\n"
|
|
||||||
" --option2 value2 \\\n"
|
|
||||||
" --optionZ valueZ]"
|
|
||||||
)
|
|
||||||
exp = [
|
exp = [
|
||||||
("BANG_LBRACKET", "![", 0),
|
("BANG_LBRACKET", "![", 0),
|
||||||
("NAME", "echo", 2),
|
("NAME", "echo", 2),
|
||||||
|
@ -278,11 +274,7 @@ def test_subproc_line_cont_space():
|
||||||
|
|
||||||
|
|
||||||
def test_subproc_line_cont_nospace():
|
def test_subproc_line_cont_nospace():
|
||||||
inp = (
|
inp = "![echo --option1 value1\\\n --option2 value2\\\n --optionZ valueZ]"
|
||||||
"![echo --option1 value1\\\n"
|
|
||||||
" --option2 value2\\\n"
|
|
||||||
" --optionZ valueZ]"
|
|
||||||
)
|
|
||||||
exp = [
|
exp = [
|
||||||
("BANG_LBRACKET", "![", 0),
|
("BANG_LBRACKET", "![", 0),
|
||||||
("NAME", "echo", 2),
|
("NAME", "echo", 2),
|
||||||
|
|
|
@ -1736,7 +1736,7 @@ def test_if_switch(check_stmts):
|
||||||
|
|
||||||
|
|
||||||
def test_if_switch_elif1_else(check_stmts):
|
def test_if_switch_elif1_else(check_stmts):
|
||||||
check_stmts("x = 42\nif x == 1:\n pass\n" "elif x == 2:\n pass\nelse:\n pass")
|
check_stmts("x = 42\nif x == 1:\n pass\nelif x == 2:\n pass\nelse:\n pass")
|
||||||
|
|
||||||
|
|
||||||
def test_if_switch_elif2_else(check_stmts):
|
def test_if_switch_elif2_else(check_stmts):
|
||||||
|
@ -1774,7 +1774,7 @@ def test_for_idx(check_stmts):
|
||||||
|
|
||||||
|
|
||||||
def test_for_zip_idx(check_stmts):
|
def test_for_zip_idx(check_stmts):
|
||||||
check_stmts('x = [42]\nfor x[0], y in zip(range(6), "123456"):\n' " pass")
|
check_stmts('x = [42]\nfor x[0], y in zip(range(6), "123456"):\n pass')
|
||||||
|
|
||||||
|
|
||||||
def test_for_attr(check_stmts):
|
def test_for_attr(check_stmts):
|
||||||
|
@ -1843,7 +1843,7 @@ def test_try_except_t_u_as_e(check_stmts):
|
||||||
|
|
||||||
def test_try_except_t_except_u(check_stmts):
|
def test_try_except_t_except_u(check_stmts):
|
||||||
check_stmts(
|
check_stmts(
|
||||||
"try:\n pass\nexcept TypeError:\n pass\n" "except SyntaxError as f:\n pass",
|
"try:\n pass\nexcept TypeError:\n pass\nexcept SyntaxError as f:\n pass",
|
||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1857,9 +1857,7 @@ def test_try_except_finally(check_stmts):
|
||||||
|
|
||||||
|
|
||||||
def test_try_except_else_finally(check_stmts):
|
def test_try_except_else_finally(check_stmts):
|
||||||
check_stmts(
|
check_stmts("try:\n pass\nexcept:\n pass\nelse:\n pass\nfinally: pass", False)
|
||||||
"try:\n pass\nexcept:\n pass\nelse:\n pass" "\nfinally: pass", False
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_try_finally(check_stmts):
|
def test_try_finally(check_stmts):
|
||||||
|
@ -2118,7 +2116,7 @@ def test_decorator_dot_dot_call_args(check_stmts):
|
||||||
|
|
||||||
|
|
||||||
def test_broken_prompt_func(check_stmts):
|
def test_broken_prompt_func(check_stmts):
|
||||||
code = "def prompt():\n" " return '{user}'.format(\n" " user='me')\n"
|
code = "def prompt():\n return '{user}'.format(\n user='me')\n"
|
||||||
check_stmts(code, False)
|
check_stmts(code, False)
|
||||||
|
|
||||||
|
|
||||||
|
@ -2134,12 +2132,7 @@ def test_class_with_methods(check_stmts):
|
||||||
|
|
||||||
|
|
||||||
def test_nested_functions(check_stmts):
|
def test_nested_functions(check_stmts):
|
||||||
code = (
|
code = "def test(x):\n def test2(y):\n return y+x\n return test2\n"
|
||||||
"def test(x):\n"
|
|
||||||
" def test2(y):\n"
|
|
||||||
" return y+x\n"
|
|
||||||
" return test2\n"
|
|
||||||
)
|
|
||||||
check_stmts(code, False)
|
check_stmts(code, False)
|
||||||
|
|
||||||
|
|
||||||
|
@ -2519,7 +2512,7 @@ def test_bang_git_quotes_space(check_xonsh_ast):
|
||||||
def test_bang_git_two_quotes_space(check_xonsh):
|
def test_bang_git_two_quotes_space(check_xonsh):
|
||||||
check_xonsh(
|
check_xonsh(
|
||||||
{},
|
{},
|
||||||
'![git commit -am "wakka jawaka"]\n' '![git commit -am "flock jawaka"]\n',
|
'![git commit -am "wakka jawaka"]\n![git commit -am "flock jawaka"]\n',
|
||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2612,7 +2605,7 @@ def test_git_quotes_space(check_xonsh_ast):
|
||||||
def test_git_two_quotes_space(check_xonsh):
|
def test_git_two_quotes_space(check_xonsh):
|
||||||
check_xonsh(
|
check_xonsh(
|
||||||
{},
|
{},
|
||||||
'$[git commit -am "wakka jawaka"]\n' '$[git commit -am "flock jawaka"]\n',
|
'$[git commit -am "wakka jawaka"]\n$[git commit -am "flock jawaka"]\n',
|
||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2959,7 +2952,7 @@ WITH_BANG_RAWSUITES = [
|
||||||
"pass\n",
|
"pass\n",
|
||||||
"x = 42\ny = 12\n",
|
"x = 42\ny = 12\n",
|
||||||
'export PATH="yo:momma"\necho $PATH\n',
|
'export PATH="yo:momma"\necho $PATH\n',
|
||||||
("with q as t:\n" " v = 10\n" "\n"),
|
("with q as t:\n v = 10\n\n"),
|
||||||
(
|
(
|
||||||
"with q as t:\n"
|
"with q as t:\n"
|
||||||
" v = 10\n"
|
" v = 10\n"
|
||||||
|
|
|
@ -288,7 +288,7 @@ def test_partial_string_arg(commandline, context):
|
||||||
assert_match(partial_commandline, partial_context, is_main_command=True)
|
assert_match(partial_commandline, partial_context, is_main_command=True)
|
||||||
|
|
||||||
|
|
||||||
CONT = "\\" "\n"
|
CONT = "\\\n"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
|
@ -8,7 +8,7 @@ from xonsh.contexts import Block, Functor
|
||||||
# helpers
|
# helpers
|
||||||
#
|
#
|
||||||
|
|
||||||
X1_WITH = "x = 1\n" "with! Block() as b:\n"
|
X1_WITH = "x = 1\nwith! Block() as b:\n"
|
||||||
SIMPLE_WITH = "with! Block() as b:\n"
|
SIMPLE_WITH = "with! Block() as b:\n"
|
||||||
FUNC_WITH = (
|
FUNC_WITH = (
|
||||||
"x = 1\n"
|
"x = 1\n"
|
||||||
|
@ -68,7 +68,7 @@ def block_checks_func(name, glbs, body, obsg=None, obsl=None):
|
||||||
|
|
||||||
|
|
||||||
def test_block_noexec(xonsh_execer_exec):
|
def test_block_noexec(xonsh_execer_exec):
|
||||||
s = "x = 1\n" "with! Block():\n" " x += 42\n"
|
s = "x = 1\nwith! Block():\n x += 42\n"
|
||||||
glbs = {"Block": Block}
|
glbs = {"Block": Block}
|
||||||
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
||||||
assert 1 == glbs["x"]
|
assert 1 == glbs["x"]
|
||||||
|
@ -83,7 +83,7 @@ def test_block_oneline(xonsh_execer_exec):
|
||||||
|
|
||||||
|
|
||||||
def test_block_manylines(xonsh_execer_exec):
|
def test_block_manylines(xonsh_execer_exec):
|
||||||
body = " ![echo wow mom]\n" "# bad place for a comment\n" " x += 42"
|
body = " ![echo wow mom]\n# bad place for a comment\n x += 42"
|
||||||
s = X1_WITH + body
|
s = X1_WITH + body
|
||||||
glbs = {"Block": Block}
|
glbs = {"Block": Block}
|
||||||
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
||||||
|
@ -92,7 +92,7 @@ def test_block_manylines(xonsh_execer_exec):
|
||||||
|
|
||||||
def test_block_leading_comment(xonsh_execer_exec):
|
def test_block_leading_comment(xonsh_execer_exec):
|
||||||
# leading comments do not show up in block lines
|
# leading comments do not show up in block lines
|
||||||
body = " # I am a leading comment\n" " x += 42\n"
|
body = " # I am a leading comment\n x += 42\n"
|
||||||
s = X1_WITH + body
|
s = X1_WITH + body
|
||||||
glbs = {"Block": Block}
|
glbs = {"Block": Block}
|
||||||
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
||||||
|
@ -101,7 +101,7 @@ def test_block_leading_comment(xonsh_execer_exec):
|
||||||
|
|
||||||
def test_block_trailing_comment(xonsh_execer_exec):
|
def test_block_trailing_comment(xonsh_execer_exec):
|
||||||
# trailing comments show up in block lines
|
# trailing comments show up in block lines
|
||||||
body = " x += 42\n" " # I am a trailing comment\n"
|
body = " x += 42\n # I am a trailing comment\n"
|
||||||
s = X1_WITH + body
|
s = X1_WITH + body
|
||||||
glbs = {"Block": Block}
|
glbs = {"Block": Block}
|
||||||
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
||||||
|
@ -109,7 +109,7 @@ def test_block_trailing_comment(xonsh_execer_exec):
|
||||||
|
|
||||||
|
|
||||||
def test_block_trailing_line_continuation(xonsh_execer_exec):
|
def test_block_trailing_line_continuation(xonsh_execer_exec):
|
||||||
body = " x += \\\n" " 42\n"
|
body = " x += \\\n 42\n"
|
||||||
s = X1_WITH + body
|
s = X1_WITH + body
|
||||||
glbs = {"Block": Block}
|
glbs = {"Block": Block}
|
||||||
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
||||||
|
@ -117,7 +117,7 @@ def test_block_trailing_line_continuation(xonsh_execer_exec):
|
||||||
|
|
||||||
|
|
||||||
def test_block_trailing_close_paren(xonsh_execer_exec):
|
def test_block_trailing_close_paren(xonsh_execer_exec):
|
||||||
body = ' x += int("42"\n' " )\n"
|
body = ' x += int("42"\n )\n'
|
||||||
s = X1_WITH + body
|
s = X1_WITH + body
|
||||||
glbs = {"Block": Block}
|
glbs = {"Block": Block}
|
||||||
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
||||||
|
@ -138,7 +138,7 @@ def test_block_trailing_close_many(xonsh_execer_exec):
|
||||||
|
|
||||||
|
|
||||||
def test_block_trailing_triple_string(xonsh_execer_exec):
|
def test_block_trailing_triple_string(xonsh_execer_exec):
|
||||||
body = ' x = """This\n' "is\n" '"probably"\n' "'not' what I meant.\n" '"""\n'
|
body = ' x = """This\nis\n"probably"\n\'not\' what I meant.\n"""\n'
|
||||||
s = SIMPLE_WITH + body
|
s = SIMPLE_WITH + body
|
||||||
glbs = {"Block": Block}
|
glbs = {"Block": Block}
|
||||||
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
||||||
|
@ -154,7 +154,7 @@ def test_block_func_oneline(xonsh_execer_exec):
|
||||||
|
|
||||||
|
|
||||||
def test_block_func_manylines(xonsh_execer_exec):
|
def test_block_func_manylines(xonsh_execer_exec):
|
||||||
body = " ![echo wow mom]\n" "# bad place for a comment\n" " x += 42\n"
|
body = " ![echo wow mom]\n# bad place for a comment\n x += 42\n"
|
||||||
s = FUNC_WITH.format(body=body)
|
s = FUNC_WITH.format(body=body)
|
||||||
glbs = {"Block": Block}
|
glbs = {"Block": Block}
|
||||||
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
||||||
|
@ -163,7 +163,7 @@ def test_block_func_manylines(xonsh_execer_exec):
|
||||||
|
|
||||||
def test_block_func_leading_comment(xonsh_execer_exec):
|
def test_block_func_leading_comment(xonsh_execer_exec):
|
||||||
# leading comments do not show up in block lines
|
# leading comments do not show up in block lines
|
||||||
body = " # I am a leading comment\n" " x += 42\n"
|
body = " # I am a leading comment\n x += 42\n"
|
||||||
s = FUNC_WITH.format(body=body)
|
s = FUNC_WITH.format(body=body)
|
||||||
glbs = {"Block": Block}
|
glbs = {"Block": Block}
|
||||||
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
||||||
|
@ -172,7 +172,7 @@ def test_block_func_leading_comment(xonsh_execer_exec):
|
||||||
|
|
||||||
def test_block_func_trailing_comment(xonsh_execer_exec):
|
def test_block_func_trailing_comment(xonsh_execer_exec):
|
||||||
# trailing comments show up in block lines
|
# trailing comments show up in block lines
|
||||||
body = " x += 42\n" " # I am a trailing comment\n"
|
body = " x += 42\n # I am a trailing comment\n"
|
||||||
s = FUNC_WITH.format(body=body)
|
s = FUNC_WITH.format(body=body)
|
||||||
glbs = {"Block": Block}
|
glbs = {"Block": Block}
|
||||||
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
||||||
|
@ -180,7 +180,7 @@ def test_block_func_trailing_comment(xonsh_execer_exec):
|
||||||
|
|
||||||
|
|
||||||
def test_blockfunc__trailing_line_continuation(xonsh_execer_exec):
|
def test_blockfunc__trailing_line_continuation(xonsh_execer_exec):
|
||||||
body = " x += \\\n" " 42\n"
|
body = " x += \\\n 42\n"
|
||||||
s = FUNC_WITH.format(body=body)
|
s = FUNC_WITH.format(body=body)
|
||||||
glbs = {"Block": Block}
|
glbs = {"Block": Block}
|
||||||
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
||||||
|
@ -188,7 +188,7 @@ def test_blockfunc__trailing_line_continuation(xonsh_execer_exec):
|
||||||
|
|
||||||
|
|
||||||
def test_block_func_trailing_close_paren(xonsh_execer_exec):
|
def test_block_func_trailing_close_paren(xonsh_execer_exec):
|
||||||
body = ' x += int("42"\n' " )\n"
|
body = ' x += int("42"\n )\n'
|
||||||
s = FUNC_WITH.format(body=body)
|
s = FUNC_WITH.format(body=body)
|
||||||
glbs = {"Block": Block}
|
glbs = {"Block": Block}
|
||||||
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
||||||
|
@ -209,7 +209,7 @@ def test_block_func_trailing_close_many(xonsh_execer_exec):
|
||||||
|
|
||||||
|
|
||||||
def test_block_func_trailing_triple_string(xonsh_execer_exec):
|
def test_block_func_trailing_triple_string(xonsh_execer_exec):
|
||||||
body = ' x = """This\n' "is\n" '"probably"\n' "'not' what I meant.\n" '"""\n'
|
body = ' x = """This\nis\n"probably"\n\'not\' what I meant.\n"""\n'
|
||||||
s = FUNC_WITH.format(body=body)
|
s = FUNC_WITH.format(body=body)
|
||||||
glbs = {"Block": Block}
|
glbs = {"Block": Block}
|
||||||
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
||||||
|
@ -220,11 +220,11 @@ def test_block_func_trailing_triple_string(xonsh_execer_exec):
|
||||||
# Functor tests
|
# Functor tests
|
||||||
#
|
#
|
||||||
|
|
||||||
X2_WITH = "{var} = 1\n" "with! Functor() as f:\n" "{body}" "{var} += 1\n" "{calls}\n"
|
X2_WITH = "{var} = 1\nwith! Functor() as f:\n{body}{var} += 1\n{calls}\n"
|
||||||
|
|
||||||
|
|
||||||
def test_functor_oneline_onecall_class(xonsh_execer_exec):
|
def test_functor_oneline_onecall_class(xonsh_execer_exec):
|
||||||
body = " global y\n" " y += 42\n"
|
body = " global y\n y += 42\n"
|
||||||
calls = "f()"
|
calls = "f()"
|
||||||
s = X2_WITH.format(body=body, calls=calls, var="y")
|
s = X2_WITH.format(body=body, calls=calls, var="y")
|
||||||
glbs = {"Functor": Functor}
|
glbs = {"Functor": Functor}
|
||||||
|
@ -233,7 +233,7 @@ def test_functor_oneline_onecall_class(xonsh_execer_exec):
|
||||||
|
|
||||||
|
|
||||||
def test_functor_oneline_onecall_func(xonsh_execer_exec):
|
def test_functor_oneline_onecall_func(xonsh_execer_exec):
|
||||||
body = " global z\n" " z += 42\n"
|
body = " global z\n z += 42\n"
|
||||||
calls = "f.func()"
|
calls = "f.func()"
|
||||||
s = X2_WITH.format(body=body, calls=calls, var="z")
|
s = X2_WITH.format(body=body, calls=calls, var="z")
|
||||||
glbs = {"Functor": Functor}
|
glbs = {"Functor": Functor}
|
||||||
|
@ -242,7 +242,7 @@ def test_functor_oneline_onecall_func(xonsh_execer_exec):
|
||||||
|
|
||||||
|
|
||||||
def test_functor_oneline_onecall_both(xonsh_execer_exec):
|
def test_functor_oneline_onecall_both(xonsh_execer_exec):
|
||||||
body = " global x\n" " x += 42\n"
|
body = " global x\n x += 42\n"
|
||||||
calls = "f()\nf.func()"
|
calls = "f()\nf.func()"
|
||||||
s = X2_WITH.format(body=body, calls=calls, var="x")
|
s = X2_WITH.format(body=body, calls=calls, var="x")
|
||||||
glbs = {"Functor": Functor}
|
glbs = {"Functor": Functor}
|
||||||
|
@ -250,7 +250,7 @@ def test_functor_oneline_onecall_both(xonsh_execer_exec):
|
||||||
block_checks_glb("f", glbs, body, {"x": 86})
|
block_checks_glb("f", glbs, body, {"x": 86})
|
||||||
|
|
||||||
|
|
||||||
XA_WITH = "x = [1]\n" "with! Functor() as f:\n" "{body}" "x.append(2)\n" "{calls}\n"
|
XA_WITH = "x = [1]\nwith! Functor() as f:\n{body}x.append(2)\n{calls}\n"
|
||||||
|
|
||||||
|
|
||||||
def test_functor_oneline_append(xonsh_execer_exec):
|
def test_functor_oneline_append(xonsh_execer_exec):
|
||||||
|
@ -264,7 +264,7 @@ def test_functor_oneline_append(xonsh_execer_exec):
|
||||||
|
|
||||||
def test_functor_return(xonsh_execer_exec):
|
def test_functor_return(xonsh_execer_exec):
|
||||||
body = " x = 42"
|
body = " x = 42"
|
||||||
t = "res = 0\n" 'with! Functor(rtn="x") as f:\n' "{body}\n" "res = f()\n"
|
t = 'res = 0\nwith! Functor(rtn="x") as f:\n{body}\nres = f()\n'
|
||||||
s = t.format(body=body)
|
s = t.format(body=body)
|
||||||
glbs = {"Functor": Functor}
|
glbs = {"Functor": Functor}
|
||||||
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
||||||
|
@ -273,12 +273,7 @@ def test_functor_return(xonsh_execer_exec):
|
||||||
|
|
||||||
def test_functor_args(xonsh_execer_exec):
|
def test_functor_args(xonsh_execer_exec):
|
||||||
body = " x = 42 + a"
|
body = " x = 42 + a"
|
||||||
t = (
|
t = 'res = 0\nwith! Functor(args=("a",), rtn="x") as f:\n{body}\nres = f(2)\n'
|
||||||
"res = 0\n"
|
|
||||||
'with! Functor(args=("a",), rtn="x") as f:\n'
|
|
||||||
"{body}\n"
|
|
||||||
"res = f(2)\n"
|
|
||||||
)
|
|
||||||
s = t.format(body=body)
|
s = t.format(body=body)
|
||||||
glbs = {"Functor": Functor}
|
glbs = {"Functor": Functor}
|
||||||
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
xonsh_execer_exec(s, glbs=glbs, locs=None)
|
||||||
|
|
|
@ -58,9 +58,9 @@ def test_cdpath_expansion(xession):
|
||||||
for d in test_dirs:
|
for d in test_dirs:
|
||||||
if not os.path.exists(d):
|
if not os.path.exists(d):
|
||||||
os.mkdir(d)
|
os.mkdir(d)
|
||||||
assert os.path.exists(
|
assert os.path.exists(dirstack._try_cdpath(d)), (
|
||||||
dirstack._try_cdpath(d)
|
f"dirstack._try_cdpath: could not resolve {d}"
|
||||||
), f"dirstack._try_cdpath: could not resolve {d}"
|
)
|
||||||
finally:
|
finally:
|
||||||
for d in test_dirs:
|
for d in test_dirs:
|
||||||
if os.path.exists(d):
|
if os.path.exists(d):
|
||||||
|
|
|
@ -150,9 +150,9 @@ def test_uncpushd_push_to_same_share(xession, shares_setup):
|
||||||
assert len(DIRSTACK) == 2
|
assert len(DIRSTACK) == 2
|
||||||
|
|
||||||
dirstack.popd([])
|
dirstack.popd([])
|
||||||
assert os.path.isdir(
|
assert os.path.isdir(TEMP_DRIVE[0] + "\\"), (
|
||||||
TEMP_DRIVE[0] + "\\"
|
"Temp drive not unmapped till last reference removed"
|
||||||
), "Temp drive not unmapped till last reference removed"
|
)
|
||||||
dirstack.popd([])
|
dirstack.popd([])
|
||||||
assert owd.casefold() == os.getcwd().casefold(), "popd returned cwd to expected dir"
|
assert owd.casefold() == os.getcwd().casefold(), "popd returned cwd to expected dir"
|
||||||
assert len(_unc_tempDrives) == 0
|
assert len(_unc_tempDrives) == 0
|
||||||
|
|
|
@ -370,9 +370,9 @@ def test_lscolors_events(key_in, old_in, new_in, test, xession):
|
||||||
@xession.builtins.events.on_lscolors_change
|
@xession.builtins.events.on_lscolors_change
|
||||||
def handler(key, oldvalue, newvalue, **kwargs):
|
def handler(key, oldvalue, newvalue, **kwargs):
|
||||||
nonlocal old_in, new_in, key_in, event_fired
|
nonlocal old_in, new_in, key_in, event_fired
|
||||||
assert (
|
assert key == key_in and oldvalue == old_in and newvalue == new_in, (
|
||||||
key == key_in and oldvalue == old_in and newvalue == new_in
|
"Old and new event values match"
|
||||||
), "Old and new event values match"
|
)
|
||||||
event_fired = True
|
event_fired = True
|
||||||
|
|
||||||
xession.env["LS_COLORS"] = lsc
|
xession.env["LS_COLORS"] = lsc
|
||||||
|
|
|
@ -60,12 +60,12 @@ def test_echo_star_with_semi(xonsh_execer_parse):
|
||||||
|
|
||||||
|
|
||||||
def test_simple_func(xonsh_execer_parse):
|
def test_simple_func(xonsh_execer_parse):
|
||||||
code = "def prompt():\n" " return '{user}'.format(user='me')\n"
|
code = "def prompt():\n return '{user}'.format(user='me')\n"
|
||||||
assert xonsh_execer_parse(code)
|
assert xonsh_execer_parse(code)
|
||||||
|
|
||||||
|
|
||||||
def test_lookup_alias(xonsh_execer_parse):
|
def test_lookup_alias(xonsh_execer_parse):
|
||||||
code = "def foo(a, s=None):\n" ' return "bar"\n' "@(foo)\n"
|
code = 'def foo(a, s=None):\n return "bar"\n@(foo)\n'
|
||||||
assert xonsh_execer_parse(code)
|
assert xonsh_execer_parse(code)
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,12 +75,12 @@ def test_lookup_anon_alias(xonsh_execer_parse):
|
||||||
|
|
||||||
|
|
||||||
def test_simple_func_broken(xonsh_execer_parse):
|
def test_simple_func_broken(xonsh_execer_parse):
|
||||||
code = "def prompt():\n" " return '{user}'.format(\n" " user='me')\n"
|
code = "def prompt():\n return '{user}'.format(\n user='me')\n"
|
||||||
assert xonsh_execer_parse(code)
|
assert xonsh_execer_parse(code)
|
||||||
|
|
||||||
|
|
||||||
def test_bad_indent(xonsh_execer_parse):
|
def test_bad_indent(xonsh_execer_parse):
|
||||||
code = "if True:\n" "x = 1\n"
|
code = "if True:\nx = 1\n"
|
||||||
with pytest.raises(SyntaxError):
|
with pytest.raises(SyntaxError):
|
||||||
xonsh_execer_parse(code)
|
xonsh_execer_parse(code)
|
||||||
|
|
||||||
|
@ -104,17 +104,17 @@ def test_bad_rhs_subproc(xonsh_execer_parse):
|
||||||
|
|
||||||
|
|
||||||
def test_indent_with_empty_line(xonsh_execer_parse):
|
def test_indent_with_empty_line(xonsh_execer_parse):
|
||||||
code = "if True:\n" "\n" " some_command for_sub_process_mode\n"
|
code = "if True:\n\n some_command for_sub_process_mode\n"
|
||||||
assert xonsh_execer_parse(code)
|
assert xonsh_execer_parse(code)
|
||||||
|
|
||||||
|
|
||||||
def test_command_in_func(xonsh_execer_parse):
|
def test_command_in_func(xonsh_execer_parse):
|
||||||
code = "def f():\n" " echo hello\n"
|
code = "def f():\n echo hello\n"
|
||||||
assert xonsh_execer_parse(code)
|
assert xonsh_execer_parse(code)
|
||||||
|
|
||||||
|
|
||||||
def test_command_in_func_with_comment(xonsh_execer_parse):
|
def test_command_in_func_with_comment(xonsh_execer_parse):
|
||||||
code = "def f():\n" " echo hello # comment\n"
|
code = "def f():\n echo hello # comment\n"
|
||||||
assert xonsh_execer_parse(code)
|
assert xonsh_execer_parse(code)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,7 @@ from xonsh.pytest.tools import skip_if_on_unix, skip_if_on_windows
|
||||||
|
|
||||||
def test_parse_env():
|
def test_parse_env():
|
||||||
exp = {"X": "YES", "Y": "NO"}
|
exp = {"X": "YES", "Y": "NO"}
|
||||||
s = (
|
s = "some garbage\n__XONSH_ENV_BEG__\nY=NO\nX=YES\n__XONSH_ENV_END__\nmore filth"
|
||||||
"some garbage\n"
|
|
||||||
"__XONSH_ENV_BEG__\n"
|
|
||||||
"Y=NO\n"
|
|
||||||
"X=YES\n"
|
|
||||||
"__XONSH_ENV_END__\n"
|
|
||||||
"more filth"
|
|
||||||
)
|
|
||||||
obs = parse_env(s)
|
obs = parse_env(s)
|
||||||
assert exp == obs
|
assert exp == obs
|
||||||
|
|
||||||
|
|
|
@ -759,9 +759,9 @@ def test_script(case):
|
||||||
out, err, rtn = run_xonsh(script)
|
out, err, rtn = run_xonsh(script)
|
||||||
out = out.replace("bash: no job control in this shell\n", "")
|
out = out.replace("bash: no job control in this shell\n", "")
|
||||||
if callable(exp_out):
|
if callable(exp_out):
|
||||||
assert exp_out(
|
assert exp_out(out), (
|
||||||
out
|
f"CASE:\nscript=***\n{script}\n***,\nExpected: {exp_out!r},\nActual: {out!r}"
|
||||||
), f"CASE:\nscript=***\n{script}\n***,\nExpected: {exp_out!r},\nActual: {out!r}"
|
)
|
||||||
else:
|
else:
|
||||||
assert exp_out == out
|
assert exp_out == out
|
||||||
assert exp_rtn == rtn
|
assert exp_rtn == rtn
|
||||||
|
@ -1280,9 +1280,9 @@ echo f1f1f1 ; f ; echo f2f2f2
|
||||||
def test_aliases_print(case):
|
def test_aliases_print(case):
|
||||||
cmd, match = case
|
cmd, match = case
|
||||||
out, err, ret = run_xonsh(cmd=cmd, single_command=False)
|
out, err, ret = run_xonsh(cmd=cmd, single_command=False)
|
||||||
assert re.match(
|
assert re.match(match, out, re.MULTILINE | re.DOTALL), (
|
||||||
match, out, re.MULTILINE | re.DOTALL
|
f"\nFailed:\n```\n{cmd.strip()}\n```,\nresult: {out!r}\nexpected: {match!r}."
|
||||||
), f"\nFailed:\n```\n{cmd.strip()}\n```,\nresult: {out!r}\nexpected: {match!r}."
|
)
|
||||||
|
|
||||||
|
|
||||||
@skip_if_on_windows
|
@skip_if_on_windows
|
||||||
|
@ -1420,9 +1420,9 @@ def test_suspended_captured_process_pipeline():
|
||||||
cmd=None, stdin_cmd=stdin_cmd, interactive=True, single_command=False, timeout=5
|
cmd=None, stdin_cmd=stdin_cmd, interactive=True, single_command=False, timeout=5
|
||||||
)
|
)
|
||||||
match = ".*suspended=True.*"
|
match = ".*suspended=True.*"
|
||||||
assert re.match(
|
assert re.match(match, out, re.MULTILINE | re.DOTALL), (
|
||||||
match, out, re.MULTILINE | re.DOTALL
|
f"\nFailed:\n```\n{stdin_cmd.strip()}\n```,\nresult: {out!r}\nexpected: {match!r}."
|
||||||
), f"\nFailed:\n```\n{stdin_cmd.strip()}\n```,\nresult: {out!r}\nexpected: {match!r}."
|
)
|
||||||
|
|
||||||
|
|
||||||
@skip_if_on_windows
|
@skip_if_on_windows
|
||||||
|
@ -1462,9 +1462,9 @@ def test_captured_subproc_is_not_affected_next_command():
|
||||||
single_command=False,
|
single_command=False,
|
||||||
timeout=10,
|
timeout=10,
|
||||||
)
|
)
|
||||||
assert not re.match(
|
assert not re.match(".*FAIL_TEST.*", out, re.MULTILINE | re.DOTALL), (
|
||||||
".*FAIL_TEST.*", out, re.MULTILINE | re.DOTALL
|
"The second command after running captured subprocess shouldn't wait the end of the first one."
|
||||||
), "The second command after running captured subprocess shouldn't wait the end of the first one."
|
)
|
||||||
|
|
||||||
|
|
||||||
@skip_if_on_windows
|
@skip_if_on_windows
|
||||||
|
|
|
@ -511,18 +511,14 @@ mom"""
|
||||||
),
|
),
|
||||||
# test from start
|
# test from start
|
||||||
(
|
(
|
||||||
"echo --option1 value1 \\\n"
|
"echo --option1 value1 \\\n --option2 value2 \\\n --optionZ valueZ",
|
||||||
" --option2 value2 \\\n"
|
|
||||||
" --optionZ valueZ",
|
|
||||||
0,
|
0,
|
||||||
"echo --option1 value1 --option2 value2 --optionZ valueZ",
|
"echo --option1 value1 --option2 value2 --optionZ valueZ",
|
||||||
3,
|
3,
|
||||||
),
|
),
|
||||||
# test from second line
|
# test from second line
|
||||||
(
|
(
|
||||||
"echo --option1 value1 \\\n"
|
"echo --option1 value1 \\\n --option2 value2 \\\n --optionZ valueZ",
|
||||||
" --option2 value2 \\\n"
|
|
||||||
" --optionZ valueZ",
|
|
||||||
1,
|
1,
|
||||||
"echo --option1 value1 --option2 value2 --optionZ valueZ",
|
"echo --option1 value1 --option2 value2 --optionZ valueZ",
|
||||||
3,
|
3,
|
||||||
|
@ -575,7 +571,7 @@ def test_is_balanced_parens(inp):
|
||||||
assert obs
|
assert obs
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("inp", ["f(x.", "f(1,x." "f((1,10),x.y"])
|
@pytest.mark.parametrize("inp", ["f(x.", "f(1,x.f((1,10),x.y"])
|
||||||
def test_is_not_balanced_parens(inp):
|
def test_is_not_balanced_parens(inp):
|
||||||
obs = is_balanced(inp, "(", ")")
|
obs = is_balanced(inp, "(", ")")
|
||||||
assert not obs
|
assert not obs
|
||||||
|
|
|
@ -944,7 +944,7 @@ def xexec_fn(
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
return (
|
return (
|
||||||
None,
|
None,
|
||||||
f"xonsh: exec: file not found: {e.args[1]}: {command[0]}" "\n",
|
f"xonsh: exec: file not found: {e.args[1]}: {command[0]}\n",
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1124,9 +1124,7 @@ def make_default_aliases():
|
||||||
|
|
||||||
def sudo(args):
|
def sudo(args):
|
||||||
if len(args) < 1:
|
if len(args) < 1:
|
||||||
print(
|
print("You need to provide an executable to run as Administrator.")
|
||||||
"You need to provide an executable to run as " "Administrator."
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
cmd = args[0]
|
cmd = args[0]
|
||||||
if locate_binary(cmd):
|
if locate_binary(cmd):
|
||||||
|
|
|
@ -373,7 +373,7 @@ def convert_macro_arg(raw_arg, kind, glbs, locs, *, name="<arg>", macroname="<ma
|
||||||
elif kind is type:
|
elif kind is type:
|
||||||
arg = type(execer.eval(raw_arg, glbs=glbs, locs=locs, filename=filename))
|
arg = type(execer.eval(raw_arg, glbs=glbs, locs=locs, filename=filename))
|
||||||
else:
|
else:
|
||||||
msg = "kind={0!r} and mode={1!r} was not recognized for macro " "argument {2!r}"
|
msg = "kind={0!r} and mode={1!r} was not recognized for macro argument {2!r}"
|
||||||
raise TypeError(msg.format(kind, mode, name))
|
raise TypeError(msg.format(kind, mode, name))
|
||||||
return arg
|
return arg
|
||||||
|
|
||||||
|
|
|
@ -94,12 +94,7 @@ def RE_XONSH_COLOR():
|
||||||
r"INTENSE_RED|INTENSE_GREEN|INTENSE_YELLOW|INTENSE_BLUE|INTENSE_PURPLE|"
|
r"INTENSE_RED|INTENSE_GREEN|INTENSE_YELLOW|INTENSE_BLUE|INTENSE_PURPLE|"
|
||||||
r"INTENSE_CYAN|INTENSE_WHITE|#" + hex + "{3}|#" + hex + "{6}|DEFAULT)"
|
r"INTENSE_CYAN|INTENSE_WHITE|#" + hex + "{3}|#" + hex + "{6}|DEFAULT)"
|
||||||
)
|
)
|
||||||
bghex = (
|
bghex = "bg#" + hex + "{3}|bg#" + hex + "{6}|BG#" + hex + "{3}|BG#" + hex + "{6}"
|
||||||
"bg#" + hex + "{3}|"
|
|
||||||
"bg#" + hex + "{6}|"
|
|
||||||
"BG#" + hex + "{3}|"
|
|
||||||
"BG#" + hex + "{6}"
|
|
||||||
)
|
|
||||||
s = "^((?P<reset>RESET|NO_COLOR)|(?P<bghex>" + bghex + ")|" + s + ")$"
|
s = "^((?P<reset>RESET|NO_COLOR)|(?P<bghex>" + bghex + ")|" + s + ")$"
|
||||||
return re.compile(s)
|
return re.compile(s)
|
||||||
|
|
||||||
|
|
|
@ -89,9 +89,9 @@ def _bash_completion_paths_default():
|
||||||
gfwp = _git_for_windows_path()
|
gfwp = _git_for_windows_path()
|
||||||
if gfwp:
|
if gfwp:
|
||||||
bcd = (
|
bcd = (
|
||||||
os.path.join(gfwp, "usr\\share\\bash-completion\\" "bash_completion"),
|
os.path.join(gfwp, "usr\\share\\bash-completion\\bash_completion"),
|
||||||
os.path.join(
|
os.path.join(
|
||||||
gfwp, "mingw64\\share\\git\\completion\\" "git-completion.bash"
|
gfwp, "mingw64\\share\\git\\completion\\git-completion.bash"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1870,7 +1870,7 @@ This is to reduce the noise in generated completions.""",
|
||||||
)
|
)
|
||||||
CASE_SENSITIVE_COMPLETIONS = Var.with_default(
|
CASE_SENSITIVE_COMPLETIONS = Var.with_default(
|
||||||
ON_LINUX,
|
ON_LINUX,
|
||||||
"Sets whether completions should be case sensitive or case " "insensitive.",
|
"Sets whether completions should be case sensitive or case insensitive.",
|
||||||
doc_default="True on Linux, False otherwise.",
|
doc_default="True on Linux, False otherwise.",
|
||||||
)
|
)
|
||||||
COMPLETIONS_BRACKETS = Var.with_default(
|
COMPLETIONS_BRACKETS = Var.with_default(
|
||||||
|
|
|
@ -212,7 +212,7 @@ class Execer:
|
||||||
):
|
):
|
||||||
"""print some debugging info if asked for."""
|
"""print some debugging info if asked for."""
|
||||||
if self.debug_level >= 1:
|
if self.debug_level >= 1:
|
||||||
msg = "{0}:{1}:{2}{3} - {4}\n" "{0}:{1}:{2}{3} + {5}"
|
msg = "{0}:{1}:{2}{3} - {4}\n{0}:{1}:{2}{3} + {5}"
|
||||||
mstr = "" if maxcol is None else ":" + str(maxcol)
|
mstr = "" if maxcol is None else ":" + str(maxcol)
|
||||||
msg = msg.format(
|
msg = msg.format(
|
||||||
self.filename, last_error_line, last_error_col, mstr, line, sbpline
|
self.filename, last_error_line, last_error_col, mstr, line, sbpline
|
||||||
|
|
|
@ -277,7 +277,7 @@ def foreign_shell_data(
|
||||||
|
|
||||||
@lazyobject
|
@lazyobject
|
||||||
def ENV_RE():
|
def ENV_RE():
|
||||||
return re.compile("__XONSH_ENV_BEG__\n(.*)" "__XONSH_ENV_END__", flags=re.DOTALL)
|
return re.compile("__XONSH_ENV_BEG__\n(.*)__XONSH_ENV_END__", flags=re.DOTALL)
|
||||||
|
|
||||||
|
|
||||||
@lazyobject
|
@lazyobject
|
||||||
|
@ -298,9 +298,7 @@ def parse_env(s):
|
||||||
|
|
||||||
@lazyobject
|
@lazyobject
|
||||||
def ALIAS_RE():
|
def ALIAS_RE():
|
||||||
return re.compile(
|
return re.compile("__XONSH_ALIAS_BEG__\n(.*)__XONSH_ALIAS_END__", flags=re.DOTALL)
|
||||||
"__XONSH_ALIAS_BEG__\n(.*)" "__XONSH_ALIAS_END__", flags=re.DOTALL
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@lazyobject
|
@lazyobject
|
||||||
|
@ -355,9 +353,7 @@ def parse_aliases(s, shell, sourcer=None, files=(), extra_args=()):
|
||||||
|
|
||||||
@lazyobject
|
@lazyobject
|
||||||
def FUNCS_RE():
|
def FUNCS_RE():
|
||||||
return re.compile(
|
return re.compile("__XONSH_FUNCS_BEG__\n(.+)\n__XONSH_FUNCS_END__", flags=re.DOTALL)
|
||||||
"__XONSH_FUNCS_BEG__\n(.+)\n" "__XONSH_FUNCS_END__", flags=re.DOTALL
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def parse_funcs(s, shell, sourcer=None, files=(), extra_args=()):
|
def parse_funcs(s, shell, sourcer=None, files=(), extra_args=()):
|
||||||
|
|
|
@ -109,13 +109,11 @@ class History:
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
"history indices must be integers " f"or slices, not {type(item)}"
|
f"history indices must be integers or slices, not {type(item)}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def __setitem__(self, *args):
|
def __setitem__(self, *args):
|
||||||
raise PermissionError(
|
raise PermissionError("You cannot change history! you can create new though.")
|
||||||
"You cannot change history! " "you can create new though."
|
|
||||||
)
|
|
||||||
|
|
||||||
def append(self, cmd):
|
def append(self, cmd):
|
||||||
"""Append a command item into history.
|
"""Append a command item into history.
|
||||||
|
|
|
@ -118,7 +118,7 @@ class HistoryDiffer:
|
||||||
|
|
||||||
def header(self):
|
def header(self):
|
||||||
"""Computes a header string difference."""
|
"""Computes a header string difference."""
|
||||||
s = "{red}--- {aline}{reset}\n" "{green}+++ {bline}{reset}"
|
s = "{red}--- {aline}{reset}\n{green}+++ {bline}{reset}"
|
||||||
s = s.format(
|
s = s.format(
|
||||||
aline=self._header_line(self.a),
|
aline=self._header_line(self.a),
|
||||||
bline=self._header_line(self.b),
|
bline=self._header_line(self.b),
|
||||||
|
|
|
@ -276,8 +276,7 @@ class SqliteHistoryGC(threading.Thread):
|
||||||
hsize, units = envs.get("XONSH_HISTORY_SIZE")
|
hsize, units = envs.get("XONSH_HISTORY_SIZE")
|
||||||
if units != "commands":
|
if units != "commands":
|
||||||
print(
|
print(
|
||||||
"sqlite backed history gc currently only supports "
|
'sqlite backed history gc currently only supports "commands" as units',
|
||||||
'"commands" as units',
|
|
||||||
file=sys.stderr,
|
file=sys.stderr,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
|
@ -668,7 +668,7 @@ class Inspector:
|
||||||
if fname.endswith((".so", ".dll", ".pyd")):
|
if fname.endswith((".so", ".dll", ".pyd")):
|
||||||
binary_file = True
|
binary_file = True
|
||||||
elif fname.endswith("<string>"):
|
elif fname.endswith("<string>"):
|
||||||
fname = "Dynamically generated function. " "No source code available."
|
fname = "Dynamically generated function. No source code available."
|
||||||
out["file"] = fname
|
out["file"] = fname
|
||||||
|
|
||||||
# Docstrings only in detail 0 mode, since source contains them (we
|
# Docstrings only in detail 0 mode, since source contains them (we
|
||||||
|
|
|
@ -481,7 +481,7 @@ class CtxAwareTransformer(NodeTransformer):
|
||||||
increment_lineno(newnode, n=node.lineno - 1)
|
increment_lineno(newnode, n=node.lineno - 1)
|
||||||
newnode.col_offset = node.col_offset
|
newnode.col_offset = node.col_offset
|
||||||
if self.debug_level >= 1:
|
if self.debug_level >= 1:
|
||||||
msg = "{0}:{1}:{2}{3} - {4}\n" "{0}:{1}:{2}{3} + {5}"
|
msg = "{0}:{1}:{2}{3} - {4}\n{0}:{1}:{2}{3} + {5}"
|
||||||
mstr = "" if maxcol is None else ":" + str(maxcol)
|
mstr = "" if maxcol is None else ":" + str(maxcol)
|
||||||
msg = msg.format(self.filename, node.lineno, mincol, mstr, line, spline)
|
msg = msg.format(self.filename, node.lineno, mincol, mstr, line, spline)
|
||||||
print(msg, file=sys.stderr)
|
print(msg, file=sys.stderr)
|
||||||
|
|
|
@ -530,7 +530,7 @@ class BaseParser:
|
||||||
def optfunc(self, p):
|
def optfunc(self, p):
|
||||||
p[0] = p[1]
|
p[0] = p[1]
|
||||||
|
|
||||||
optfunc.__doc__ = f"{rulename}_opt : empty\n" f" | {rulename}"
|
optfunc.__doc__ = f"{rulename}_opt : empty\n | {rulename}"
|
||||||
optfunc.__name__ = "p_" + rulename + "_opt"
|
optfunc.__name__ = "p_" + rulename + "_opt"
|
||||||
setattr(self.__class__, optfunc.__name__, optfunc)
|
setattr(self.__class__, optfunc.__name__, optfunc)
|
||||||
|
|
||||||
|
@ -543,7 +543,7 @@ class BaseParser:
|
||||||
p[0] = p[1] if len(p) == 2 else p[1] + p[2]
|
p[0] = p[1] if len(p) == 2 else p[1] + p[2]
|
||||||
|
|
||||||
listfunc.__doc__ = (
|
listfunc.__doc__ = (
|
||||||
f"{rulename}_list : {rulename}\n" f" | {rulename}_list {rulename}"
|
f"{rulename}_list : {rulename}\n | {rulename}_list {rulename}"
|
||||||
)
|
)
|
||||||
listfunc.__name__ = "p_" + rulename + "_list"
|
listfunc.__name__ = "p_" + rulename + "_list"
|
||||||
setattr(self.__class__, listfunc.__name__, listfunc)
|
setattr(self.__class__, listfunc.__name__, listfunc)
|
||||||
|
|
|
@ -393,9 +393,9 @@ class CompletionContextParser:
|
||||||
self.error = None
|
self.error = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
assert self.cursor_in_span(
|
assert self.cursor_in_span(slice(0, len(multiline_text))), (
|
||||||
slice(0, len(multiline_text))
|
f"Bad cursor index: {cursor_index}"
|
||||||
), f"Bad cursor index: {cursor_index}"
|
)
|
||||||
|
|
||||||
context: Optional[CompletionContext] = self.parser.parse(
|
context: Optional[CompletionContext] = self.parser.parse(
|
||||||
input=multiline_text, lexer=self, debug=1 if self.debug else 0
|
input=multiline_text, lexer=self, debug=1 if self.debug else 0
|
||||||
|
@ -440,9 +440,9 @@ class CompletionContextParser:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
lineno = tok.lineno - 1 # tok.lineno is 1-indexed
|
lineno = tok.lineno - 1 # tok.lineno is 1-indexed
|
||||||
assert lineno < len(
|
assert lineno < len(self.line_indices), (
|
||||||
self.line_indices
|
f"Invalid lexer state for token {tok} - bad lineno"
|
||||||
), f"Invalid lexer state for token {tok} - bad lineno"
|
)
|
||||||
|
|
||||||
tok.lexpos = lexpos = self.line_indices[lineno] + tok.lexpos
|
tok.lexpos = lexpos = self.line_indices[lineno] + tok.lexpos
|
||||||
|
|
||||||
|
|
|
@ -269,9 +269,9 @@ class Parser(ThreeNineParser):
|
||||||
|
|
||||||
if build_complex:
|
if build_complex:
|
||||||
# TODO raise syntax error instead (see reason in p_literal_expr_number_or_string_literal_list)
|
# TODO raise syntax error instead (see reason in p_literal_expr_number_or_string_literal_list)
|
||||||
assert isinstance(
|
assert isinstance(right.value, complex), (
|
||||||
right.value, complex
|
"right part of complex literal must be imaginary"
|
||||||
), "right part of complex literal must be imaginary"
|
)
|
||||||
|
|
||||||
if negate_left_side:
|
if negate_left_side:
|
||||||
left = ast.UnaryOp(op=ast.USub(), operand=left, **loc)
|
left = ast.UnaryOp(op=ast.USub(), operand=left, **loc)
|
||||||
|
|
|
@ -507,7 +507,7 @@ def BASH_COMPLETIONS_DEFAULT():
|
||||||
),
|
),
|
||||||
os.path.join(
|
os.path.join(
|
||||||
git_for_windows_path(),
|
git_for_windows_path(),
|
||||||
"mingw64\\share\\git\\completion\\" "git-completion.bash",
|
"mingw64\\share\\git\\completion\\git-completion.bash",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -115,7 +115,7 @@ def proc_untraced_waitpid(proc, hang, task=None, raise_child_process_error=False
|
||||||
proc.signal = None
|
proc.signal = None
|
||||||
info["signal"] = None
|
info["signal"] = None
|
||||||
|
|
||||||
info["signal_name"] = f'{info["signal"]} {get_signal_name(info["signal"])}'.strip()
|
info["signal_name"] = f"{info['signal']} {get_signal_name(info['signal'])}".strip()
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ class PromptFormatter:
|
||||||
try:
|
try:
|
||||||
return self.fields.pick(field)
|
return self.fields.pick(field)
|
||||||
except Exception: # noqa
|
except Exception: # noqa
|
||||||
print(f"prompt: error: on field {field!r}" "", file=sys.stderr)
|
print(f"prompt: error: on field {field!r}", file=sys.stderr)
|
||||||
xt.print_exception()
|
xt.print_exception()
|
||||||
value = f"{{BACKGROUND_RED}}{{ERROR:{field}}}{{RESET}}"
|
value = f"{{BACKGROUND_RED}}{{ERROR:{field}}}{{RESET}}"
|
||||||
return value
|
return value
|
||||||
|
|
|
@ -105,29 +105,29 @@ class DummyHistory:
|
||||||
|
|
||||||
def nodes_equal(x, y):
|
def nodes_equal(x, y):
|
||||||
__tracebackhide__ = True
|
__tracebackhide__ = True
|
||||||
assert type(x) is type(
|
assert type(x) is type(y), (
|
||||||
y
|
f"Ast nodes do not have the same type: '{type(x)}' != '{type(y)}' "
|
||||||
), f"Ast nodes do not have the same type: '{type(x)}' != '{type(y)}' "
|
)
|
||||||
if isinstance(x, ast.Constant):
|
if isinstance(x, ast.Constant):
|
||||||
assert (
|
assert x.value == y.value, (
|
||||||
x.value == y.value
|
f"Constant ast nodes do not have the same value: {repr(x.value)} != {repr(y.value)}"
|
||||||
), f"Constant ast nodes do not have the same value: {repr(x.value)} != {repr(y.value)}"
|
)
|
||||||
if isinstance(x, (ast.Expr, ast.FunctionDef, ast.ClassDef)):
|
if isinstance(x, (ast.Expr, ast.FunctionDef, ast.ClassDef)):
|
||||||
assert (
|
assert x.lineno == y.lineno, (
|
||||||
x.lineno == y.lineno
|
f"Ast nodes do not have the same line number : {x.lineno} != {y.lineno}"
|
||||||
), f"Ast nodes do not have the same line number : {x.lineno} != {y.lineno}"
|
)
|
||||||
assert (
|
assert x.col_offset == y.col_offset, (
|
||||||
x.col_offset == y.col_offset
|
f"Ast nodes do not have the same column offset number : {x.col_offset} != {y.col_offset}"
|
||||||
), f"Ast nodes do not have the same column offset number : {x.col_offset} != {y.col_offset}"
|
)
|
||||||
for (xname, xval), (yname, yval) in zip(ast.iter_fields(x), ast.iter_fields(y)):
|
for (xname, xval), (yname, yval) in zip(ast.iter_fields(x), ast.iter_fields(y)):
|
||||||
assert (
|
assert xname == yname, (
|
||||||
xname == yname
|
f"Ast nodes field names differ : {xname} (of type {type(xval)}) != {yname} (of type {type(yval)})"
|
||||||
), f"Ast nodes field names differ : {xname} (of type {type(xval)}) != {yname} (of type {type(yval)})"
|
)
|
||||||
if isinstance(x, ast.Constant) and xname == "kind":
|
if isinstance(x, ast.Constant) and xname == "kind":
|
||||||
continue
|
continue
|
||||||
assert (
|
assert type(xval) is type(yval), (
|
||||||
type(xval) is type(yval)
|
f"Ast nodes fields differ : {xname} (of type {type(xval)}) != {yname} (of type {type(yval)})"
|
||||||
), f"Ast nodes fields differ : {xname} (of type {type(xval)}) != {yname} (of type {type(yval)})"
|
)
|
||||||
for xchild, ychild in zip(ast.iter_child_nodes(x), ast.iter_child_nodes(y)):
|
for xchild, ychild in zip(ast.iter_child_nodes(x), ast.iter_child_nodes(y)):
|
||||||
assert nodes_equal(xchild, ychild), "Ast node children differs"
|
assert nodes_equal(xchild, ychild), "Ast node children differs"
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -577,7 +577,7 @@ class ReadlineShell(BaseShell, cmd.Cmd):
|
||||||
line = self.singleline()
|
line = self.singleline()
|
||||||
except EOFError:
|
except EOFError:
|
||||||
if XSH.env.get("IGNOREEOF"):
|
if XSH.env.get("IGNOREEOF"):
|
||||||
self.stdout.write('Use "exit" to leave the shell.' "\n")
|
self.stdout.write('Use "exit" to leave the shell.\n')
|
||||||
line = ""
|
line = ""
|
||||||
else:
|
else:
|
||||||
line = "EOF"
|
line = "EOF"
|
||||||
|
|
|
@ -956,7 +956,7 @@ def print_warning(msg):
|
||||||
# Notify about the traceback output possibility if neither of
|
# Notify about the traceback output possibility if neither of
|
||||||
# the two options have been manually set
|
# the two options have been manually set
|
||||||
sys.stderr.write(
|
sys.stderr.write(
|
||||||
"xonsh: For full traceback set: " "$XONSH_SHOW_TRACEBACK = True\n"
|
"xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True\n"
|
||||||
)
|
)
|
||||||
# convert show_trace to bool if necessary
|
# convert show_trace to bool if necessary
|
||||||
if not is_bool(show_trace):
|
if not is_bool(show_trace):
|
||||||
|
@ -1033,7 +1033,7 @@ def print_exception(msg=None, exc_info=None, source_msg=None):
|
||||||
# Notify about the traceback output possibility if neither of
|
# Notify about the traceback output possibility if neither of
|
||||||
# the two options have been manually set
|
# the two options have been manually set
|
||||||
sys.stderr.write(
|
sys.stderr.write(
|
||||||
"xonsh: For full traceback set: " "$XONSH_SHOW_TRACEBACK = True\n"
|
"xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True\n"
|
||||||
)
|
)
|
||||||
# convert show_trace to bool if necessary
|
# convert show_trace to bool if necessary
|
||||||
if not is_bool(show_trace):
|
if not is_bool(show_trace):
|
||||||
|
|
|
@ -162,7 +162,7 @@ class TracerType:
|
||||||
tracer = LazyObject(TracerType, globals(), "tracer")
|
tracer = LazyObject(TracerType, globals(), "tracer")
|
||||||
|
|
||||||
COLORLESS_LINE = "{fname}:{lineno}:{line}"
|
COLORLESS_LINE = "{fname}:{lineno}:{line}"
|
||||||
COLOR_LINE = "{{PURPLE}}{fname}{{BLUE}}:" "{{GREEN}}{lineno}{{BLUE}}:" "{{RESET}}"
|
COLOR_LINE = "{{PURPLE}}{fname}{{BLUE}}:{{GREEN}}{lineno}{{BLUE}}:{{RESET}}"
|
||||||
|
|
||||||
|
|
||||||
def tracer_format_line(fname, lineno, line, color=True, lexer=None, formatter=None):
|
def tracer_format_line(fname, lineno, line, color=True, lexer=None, formatter=None):
|
||||||
|
|
|
@ -695,7 +695,7 @@ class StateVisitor(Visitor):
|
||||||
|
|
||||||
|
|
||||||
YN = "{GREEN}yes{RESET} or {RED}no{RESET} [default: no]? "
|
YN = "{GREEN}yes{RESET} or {RED}no{RESET} [default: no]? "
|
||||||
YNB = "{GREEN}yes{RESET}, {RED}no{RESET}, or " "{YELLOW}break{RESET} [default: no]? "
|
YNB = "{GREEN}yes{RESET}, {RED}no{RESET}, or {YELLOW}break{RESET} [default: no]? "
|
||||||
|
|
||||||
|
|
||||||
class PromptVisitor(StateVisitor):
|
class PromptVisitor(StateVisitor):
|
||||||
|
@ -748,9 +748,7 @@ class PromptVisitor(StateVisitor):
|
||||||
raise
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
if node.retry:
|
if node.retry:
|
||||||
msg = (
|
msg = "{{BOLD_RED}}Invalid{{RESET}} input {0!r}, please retry."
|
||||||
"{{BOLD_RED}}Invalid{{RESET}} input {0!r}, " "please retry."
|
|
||||||
)
|
|
||||||
print_color(msg.format(raw))
|
print_color(msg.format(raw))
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
@ -829,7 +827,9 @@ class PromptVisitor(StateVisitor):
|
||||||
self.state = json.load(f)
|
self.state = json.load(f)
|
||||||
print_color(f"{{GREEN}}{fname!r} loaded.{{RESET}}")
|
print_color(f"{{GREEN}}{fname!r} loaded.{{RESET}}")
|
||||||
else:
|
else:
|
||||||
print_color(f"{{RED}}{fname!r} could not be found, " "continuing.{{RESET}}")
|
print_color(
|
||||||
|
f"{{RED}}{fname!r} could not be found, continuing.{{{{RESET}}}}"
|
||||||
|
)
|
||||||
return fname
|
return fname
|
||||||
|
|
||||||
def visit_fileinserter(self, node):
|
def visit_fileinserter(self, node):
|
||||||
|
|
|
@ -238,7 +238,7 @@ def make_fs_wiz():
|
||||||
path="/foreign_shells/{idx}/aliascmd",
|
path="/foreign_shells/{idx}/aliascmd",
|
||||||
),
|
),
|
||||||
wiz.StoreNonEmpty(
|
wiz.StoreNonEmpty(
|
||||||
("extra command line arguments [list of str, " "default=[]]: "),
|
("extra command line arguments [list of str, default=[]]: "),
|
||||||
converter=ast.literal_eval,
|
converter=ast.literal_eval,
|
||||||
show_conversion=True,
|
show_conversion=True,
|
||||||
path="/foreign_shells/{idx}/extra_args",
|
path="/foreign_shells/{idx}/extra_args",
|
||||||
|
@ -494,7 +494,7 @@ def _xonfig_format_human(data):
|
||||||
if isinstance(val, list) and val:
|
if isinstance(val, list) and val:
|
||||||
for i, subval in enumerate(val):
|
for i, subval in enumerate(val):
|
||||||
s += row.format(
|
s += row.format(
|
||||||
key=f"{key} {i+1}", wcol1=wcol1, val=subval, wcol2=wcol2
|
key=f"{key} {i + 1}", wcol1=wcol1, val=subval, wcol2=wcol2
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
s += row.format(key=key, wcol1=wcol1, val=val, wcol2=wcol2)
|
s += row.format(key=key, wcol1=wcol1, val=val, wcol2=wcol2)
|
||||||
|
|
|
@ -37,14 +37,14 @@ def _which_create_parser():
|
||||||
"--version",
|
"--version",
|
||||||
action="version",
|
action="version",
|
||||||
version=f"{_which.__version__}",
|
version=f"{_which.__version__}",
|
||||||
help="Display the version of the python which module " "used by xonsh",
|
help="Display the version of the python which module used by xonsh",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-v",
|
"-v",
|
||||||
"--verbose",
|
"--verbose",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
dest="verbose",
|
dest="verbose",
|
||||||
help="Print out how matches were located and show " "near misses on stderr",
|
help="Print out how matches were located and show near misses on stderr",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-p",
|
"-p",
|
||||||
|
|
Loading…
Add table
Reference in a new issue