mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
prev/post for seterr
This commit is contained in:
parent
6c2940d8cf
commit
08d8bcf149
4 changed files with 61 additions and 26 deletions
|
@ -16,16 +16,16 @@ Current Developments
|
|||
* Added an option to update ``os.environ`` every time the xonsh environment changes.
|
||||
This is disabled by default but can be enabled by setting ``$UPDATE_OS_ENVIRON`` to
|
||||
True.
|
||||
* Added Windows 'cmd.exe' as a foreign shell. This gives xonsh the ability to source
|
||||
Windows Batch files (.bat and .cmd). Calling ``source-cmd script.bat`` or the
|
||||
alias ``source-bat script.bat`` will call the bat file and changes to the
|
||||
* Added Windows 'cmd.exe' as a foreign shell. This gives xonsh the ability to source
|
||||
Windows Batch files (.bat and .cmd). Calling ``source-cmd script.bat`` or the
|
||||
alias ``source-bat script.bat`` will call the bat file and changes to the
|
||||
environment variables will be reflected in xonsh.
|
||||
* Added an alias for the conda environment activate/deactivate batch scripts when
|
||||
* Added an alias for the conda environment activate/deactivate batch scripts when
|
||||
running the Anaconda python distribution on Windows.
|
||||
* Added a menu entry to launch xonsh when installing xonsh from a conda package
|
||||
* Added a new ``which`` alias that supports both regular ``which`` and also searches
|
||||
through xonsh aliases
|
||||
* Add support for prompt_toolkit_1.0.0
|
||||
* Added support for prompt toolkit v1.0.0.
|
||||
|
||||
|
||||
**Changed:**
|
||||
|
@ -40,7 +40,9 @@ Current Developments
|
|||
environments
|
||||
* Regexpath matching with backticks, now returns an empty list in python mode.
|
||||
* Pygments added as a dependency for the conda package
|
||||
|
||||
* Foreign shells now allow for setting exit-on-error commands before and after
|
||||
all other commands via the ``seterrprevcmd`` and ``seterrpostcmd`` arguments.
|
||||
Sensinble defaults are provided for existing shells.
|
||||
|
||||
|
||||
**Deprecated:** None
|
||||
|
@ -54,11 +56,13 @@ Current Developments
|
|||
the line.
|
||||
* Aliases will now evaluate enviornment variables and other expansions
|
||||
at execution time rather than passing through a literal string.
|
||||
* Fixed environment variables from os.environ not beeing loaded when a running
|
||||
* Fixed environment variables from os.environ not beeing loaded when a running
|
||||
a script
|
||||
* Fixed bug that prevented `source-alias` from working.
|
||||
* Fixed bug that prevented `source-alias` from working.
|
||||
* Fixed deadlock on Windows when runing subprocess that generates enough output
|
||||
to fill the OS pipe buffer
|
||||
to fill the OS pipe buffer.
|
||||
* Sourcing foreign shells will now return a non-zero exit code if the
|
||||
source operation failed for some reason.
|
||||
|
||||
**Security:** None
|
||||
|
||||
|
|
|
@ -66,9 +66,14 @@ dictionaries have the following structure:
|
|||
:runcmd : *str or None, optional* - Command line switches to use when
|
||||
running the script, such as ``-c`` for Bash and ``/C`` for cmd.exe.
|
||||
``default=null``
|
||||
:seterrcmd : *str or None, optional* - Command that enables exit-on-error
|
||||
for the shell. For example, this is "set -e" in Bash. To disable
|
||||
exit-on-error behavior, simply pass in an empty string. ``default=null``
|
||||
:seterrprevcmd : *str or None, optional* - Command that enables exit-on-error
|
||||
for the shell before all other commands. For example, this is "set -e" in Bash.
|
||||
To disable this exit-on-error behavior, simply pass in an empty string.
|
||||
``default=null``
|
||||
:seterrpostcmd : *str or None, optional* - Command that enables exit-on-error
|
||||
for the shell after all other commands. For example, this is "set -e" in Bash.
|
||||
To disable this exit-on-error behavior, simply pass in an empty string.
|
||||
``default=null``
|
||||
|
||||
|
||||
Some examples can be seen below:
|
||||
|
|
|
@ -192,6 +192,12 @@ def _ensure_source_foreign_parser():
|
|||
help='whether the commands for source shell should be '
|
||||
'written to a temporary file.',
|
||||
dest='use_tmpfile')
|
||||
parser.add_argument('--seterrprevcmd', default=None, dest='seterrprevcmd',
|
||||
help='command(s) to set exit-on-error before any'
|
||||
'other commands.')
|
||||
parser.add_argument('--seterrpostcmd', default=None, dest='seterrpostcmd',
|
||||
help='command(s) to set exit-on-error after all'
|
||||
'other commands.')
|
||||
_SOURCE_FOREIGN_PARSER = parser
|
||||
return parser
|
||||
|
||||
|
@ -217,7 +223,9 @@ def source_foreign(args, stdin=None):
|
|||
postcmd=ns.postcmd,
|
||||
funcscmd=ns.funcscmd,
|
||||
sourcer=ns.sourcer,
|
||||
use_tmpfile=ns.use_tmpfile)
|
||||
use_tmpfile=ns.use_tmpfile,
|
||||
seterrprevcmd=ns.seterrprevcmd,
|
||||
seterrpostcmd=ns.seterrpostcmd)
|
||||
if fsenv is None:
|
||||
return (None, 'xonsh: error: Source failed: '
|
||||
'{}\n'.format(ns.prevcmd), 1)
|
||||
|
@ -267,7 +275,7 @@ def source_cmd(args, stdin=None):
|
|||
args.append('--interactive=0')
|
||||
args.append('--sourcer=call')
|
||||
args.append('--envcmd=set')
|
||||
args.append('--postcmd=if errorlevel 1 exit 1')
|
||||
args.append('--seterrpostcmd=if errorlevel 1 exit 1')
|
||||
args.append('--use-tmpfile=1')
|
||||
return source_foreign(args, stdin=stdin)
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ from xonsh.tools import to_bool, ensure_string
|
|||
|
||||
|
||||
COMMAND = """
|
||||
{seterrcmd}
|
||||
{seterrprevcmd}
|
||||
{prevcmd}
|
||||
echo __XONSH_ENV_BEG__
|
||||
{envcmd}
|
||||
|
@ -27,6 +27,7 @@ echo __XONSH_FUNCS_BEG__
|
|||
{funcscmd}
|
||||
echo __XONSH_FUNCS_END__
|
||||
{postcmd}
|
||||
{seterrpostcmd}
|
||||
""".strip()
|
||||
|
||||
DEFAULT_BASH_FUNCSCMD = """
|
||||
|
@ -122,11 +123,16 @@ DEFAULT_RUNCMD = {
|
|||
'zsh': '-c',
|
||||
'cmd': '/C',
|
||||
}
|
||||
DEFAULT_SETERRCMD = {
|
||||
DEFAULT_SETERRPREVCMD = {
|
||||
'bash': 'set -e',
|
||||
'zsh': 'set -e',
|
||||
'cmd': '',
|
||||
}
|
||||
DEFAULT_SETERRPOSTCMD = {
|
||||
'bash': '',
|
||||
'zsh': '',
|
||||
'cmd': 'if errorlevel 1 exit 1',
|
||||
}
|
||||
|
||||
|
||||
@lru_cache()
|
||||
|
@ -134,7 +140,7 @@ def foreign_shell_data(shell, interactive=True, login=False, envcmd=None,
|
|||
aliascmd=None, extra_args=(), currenv=None,
|
||||
safe=True, prevcmd='', postcmd='', funcscmd=None,
|
||||
sourcer=None, use_tmpfile=False, tmpfile_ext=None,
|
||||
runcmd=None, seterrcmd=None):
|
||||
runcmd=None, seterrprevcmd=None, seterrpostcmd=None):
|
||||
"""Extracts data from a foreign (non-xonsh) shells. Currently this gets
|
||||
the environment, aliases, and functions but may be extended in the future.
|
||||
|
||||
|
@ -182,10 +188,15 @@ def foreign_shell_data(shell, interactive=True, login=False, envcmd=None,
|
|||
runcmd : str or None, optional
|
||||
Command line switches to use when running the script, such as
|
||||
-c for Bash and /C for cmd.exe.
|
||||
seterrcmd : str or None, optional
|
||||
Command that enables exit-on-error for the shell. For example, this
|
||||
is "set -e" in Bash. To disable exit-on-error behavior, simply pass
|
||||
in an empty string.
|
||||
seterrprevcmd : str or None, optional
|
||||
Command that enables exit-on-error for the shell that is run at the
|
||||
start of the script. For example, this is "set -e" in Bash. To disable
|
||||
exit-on-error behavior, simply pass in an empty string.
|
||||
seterrpostcmd : str or None, optional
|
||||
Command that enables exit-on-error for the shell that is run at the end
|
||||
of the script. For example, this is "if errorlevel 1 exit 1" in
|
||||
cmd.exe. To disable exit-on-error behavior, simply pass in an
|
||||
empty string.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
@ -207,10 +218,14 @@ def foreign_shell_data(shell, interactive=True, login=False, envcmd=None,
|
|||
funcscmd = DEFAULT_FUNCSCMDS.get(shkey, 'echo {}') if funcscmd is None else funcscmd
|
||||
tmpfile_ext = DEFAULT_TMPFILE_EXT.get(shkey, 'sh') if tmpfile_ext is None else tmpfile_ext
|
||||
runcmd = DEFAULT_RUNCMD.get(shkey, '-c') if runcmd is None else runcmd
|
||||
seterrcmd = DEFAULT_SETERRCMD.get(shkey, '') if seterrcmd is None else seterrcmd
|
||||
seterrprevcmd = DEFAULT_SETERRPREVCMD.get(shkey, '') \
|
||||
if seterrprevcmd is None else seterrprevcmd
|
||||
seterrpostcmd = DEFAULT_SETERRPOSTCMD.get(shkey, '') \
|
||||
if seterrpostcmd is None else seterrpostcmd
|
||||
command = COMMAND.format(envcmd=envcmd, aliascmd=aliascmd, prevcmd=prevcmd,
|
||||
postcmd=postcmd, funcscmd=funcscmd,
|
||||
seterrcmd=seterrcmd).strip()
|
||||
seterrprevcmd=seterrprevcmd,
|
||||
seterrpostcmd=seterrpostcmd).strip()
|
||||
|
||||
cmd.append(runcmd)
|
||||
|
||||
|
@ -433,9 +448,12 @@ def ensure_shell(shell):
|
|||
if 'sourcer' in shell_keys:
|
||||
shell['sourcer'] = None if shell['sourcer'] is None \
|
||||
else ensure_string(shell['sourcer'])
|
||||
if 'seterrcmd' in shell_keys:
|
||||
shell['seterrcmd'] = None if shell['seterrcmd'] is None \
|
||||
else ensure_string(shell['seterrcmd'])
|
||||
if 'seterrprevcmd' in shell_keys:
|
||||
shell['seterrprevcmd'] = None if shell['seterrprevcmd'] is None \
|
||||
else ensure_string(shell['seterrprevcmd'])
|
||||
if 'seterrpostcmd' in shell_keys:
|
||||
shell['seterrpostcmd'] = None if shell['seterrpostcmd'] is None \
|
||||
else ensure_string(shell['seterrpostcmd'])
|
||||
return shell
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue