Skip to content

Commit

Permalink
Disable coconut in xonsh execx
Browse files Browse the repository at this point in the history
Refs   #724.
  • Loading branch information
evhub committed Mar 31, 2023
1 parent 0b4cc09 commit cb36931
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ user@computer ~ $ $(ls -la) |> .splitlines() |> len
30
```

Note that the way that Coconut integrates with `xonsh`, `@(<code>)` syntax will only work with Python code, not Coconut code.
Note that the way that Coconut integrates with `xonsh`, `@(<code>)` syntax and the `execx` command will only work with Python code, not Coconut code.

Additionally, Coconut will only compile individual commands—Coconut will not touch the `.xonshrc` or any other `.xsh` files.

Expand Down
2 changes: 2 additions & 0 deletions coconut/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,8 @@ def get_bool_env_var(env_var, default=False):

conda_build_env_var = "CONDA_BUILD"

disabled_xonsh_modes = ("exec", "eval")

# -----------------------------------------------------------------------------------------------------------------------
# DOCUMENTATION CONSTANTS:
# -----------------------------------------------------------------------------------------------------------------------
Expand Down
30 changes: 16 additions & 14 deletions coconut/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@

from types import MethodType

from coconut.constants import coconut_kernel_kwargs
from coconut.constants import (
coconut_kernel_kwargs,
disabled_xonsh_modes,
)

# -----------------------------------------------------------------------------------------------------------------------
# IPYTHON:
Expand Down Expand Up @@ -88,9 +91,7 @@ class CoconutXontribLoader(object):
"""Implements Coconut's _load_xontrib_."""
compiler = None
runner = None

def __init__(self):
self.timing_info = []
timing_info = []

def __call__(self, xsh, **kwargs):
# hide imports to avoid circular dependencies
Expand All @@ -111,16 +112,17 @@ def __call__(self, xsh, **kwargs):

self.runner.update_vars(xsh.ctx)

def new_parse(execer, s, *args, **kwargs):
def new_parse(execer, code, mode="exec", *args, **kwargs):
"""Coconut-aware version of xonsh's _parse."""
parse_start_time = get_clock_time()
try:
s = self.compiler.parse_xonsh(s, keep_state=True)
except CoconutException as err:
err_str = format_error(err).splitlines()[0]
s += " #" + err_str
self.timing_info.append(("parse", get_clock_time() - parse_start_time))
return execer.__class__.parse(execer, s, *args, **kwargs)
if mode not in disabled_xonsh_modes:
parse_start_time = get_clock_time()
try:
code = self.compiler.parse_xonsh(code, keep_state=True)
except CoconutException as err:
err_str = format_error(err).splitlines()[0]
code += " #" + err_str
self.timing_info.append(("parse", get_clock_time() - parse_start_time))
return execer.__class__.parse(execer, code, mode=mode, *args, **kwargs)

main_parser = xsh.execer.parser
main_parser._coconut_old_parse = main_parser.parse
Expand All @@ -140,7 +142,7 @@ def unload(self, xsh):

main_parser = xsh.execer.parser
if not hasattr(main_parser, "_coconut_old_parse"):
raise CoconutException("attempting to unldoad Coconut xontrib but it was never loaded")
raise CoconutException("attempting to unload Coconut xontrib but it was never loaded")
main_parser.parser = main_parser._coconut_old_parse

ctx_parser = xsh.execer.ctxtransformer.parser
Expand Down
2 changes: 1 addition & 1 deletion coconut/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
VERSION = "3.0.0"
VERSION_NAME = None
# False for release, int >= 1 for develop
DEVELOP = 18
DEVELOP = 19
ALPHA = True # for pre releases rather than post releases

# -----------------------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit cb36931

Please sign in to comment.