Fix xonsh xontrib in .xsh scripts and execx#907
Open
anki-code wants to merge 1 commit into
Open
Conversation
Resolves xonsh/xonsh#5823 and refs evhub#883. Coconut's xontrib only preprocessed code in xonsh's "single" parse mode (interactive REPL), so |> in .xsh scripts and inside execx (both compiled with mode="exec") was left for xonsh to parse and got split into | and >, causing IndexError in run_subproc. Two changes are needed: * enabled_xonsh_modes now includes "exec" so the xontrib hooks run for scripts and execx. xonsh already caches compiled .xsh bytecode via run_script_with_cache, and Coconut already memoizes parse_xonsh per process, so the original .xonshrc slowness from evhub#724 stays mitigated. * unsafe_xonsh_parser was built from single_input, accepting only one statement. Scripts contain multiple statements, so switch to file_input. Single-statement input still parses correctly since file_input is a superset.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves xonsh/xonsh#5823 and refs #883.
The xonsh xontrib only preprocessed code in xonsh's
singleparse mode (interactive REPL). When a.xshscript orexecx(...)runs, xonsh compiles withmode="exec", so Coconut left|>alone and xonsh's parser then split it into|and>, eventually crashing inrun_subprocwithIndexError: list index out of range(xonsh/procs/specs.py:707).Changes
coconut/constants.py— add"exec"toenabled_xonsh_modesso the xontrib hooks run for scripts andexecx. xonsh already caches compiled.xshbytecode viarun_script_with_cache, and Coconut already memoizesparse_xonshper process, so the original.xonshrcslowness from coconut makes .xonshrc take an unreasonable amount of time to load #724 stays mitigated.coconut/compiler/grammar.py—unsafe_xonsh_parserwas built fromsingle_input, which accepts only one statement, so multi-statement scripts failed withCoconutParseError: Expected end of textonceexecwas enabled. Switch tofile_input(superset ofsingle_input); single-statement input still parses correctly.coconut/tests/main_test.py—execx("10 |> print")previously asserted failure (subprocess mode/IndexError); it now succeeds and prints10.DOCS.md— note that.xshscripts andexecxnow work; only@(<code>)andevalxremain Python-only.coconut/root.py— bumpDEVELOP.Test plan
$(ls) |> .splitlines() |> len |> printfrom a.xshscript — works.1 |> print,"hello" |> .upper() |> print,[1,2,3] |> sum |> print— all run.execx("10 |> print")— prints10..xshscripts and subprocess-mode commands (echo,ls) — no regression.!(ls -la) |> bool,'1; 2' |> print,len("""1\n3\n5""")) — unchanged.parse(..., "xonsh")inextras.coco(lines 326–327) — still pass.