mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
chore: update libs
This commit is contained in:
parent
63bdaee626
commit
8e4cba5176
3 changed files with 25 additions and 27 deletions
|
@ -1,8 +1,9 @@
|
|||
"""Tests for subprocess lib"""
|
||||
import tempfile
|
||||
from subprocess import CalledProcessError
|
||||
|
||||
from xonsh.lib.os import indir
|
||||
from xonsh.lib.subprocess import run, check_call, check_output, CalledProcessError
|
||||
from xonsh.lib.subprocess import run, check_call, check_output
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -39,7 +40,7 @@ def test_check_call_raises():
|
|||
if ON_WINDOWS:
|
||||
pytest.skip("On Windows")
|
||||
try:
|
||||
check_call('false')
|
||||
check_call(['false'])
|
||||
got_raise = False
|
||||
except CalledProcessError:
|
||||
got_raise = True
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
"""Xonsh extension of the standard library os module, using xonsh for
|
||||
subprocess calls"""
|
||||
from contextlib import contextmanager
|
||||
import sys
|
||||
|
||||
from xonsh.built_ins import subproc_uncaptured
|
||||
from xonsh.dirstack import with_pushd
|
||||
|
||||
@contextmanager
|
||||
def indir(d):
|
||||
"""Context manager for temporarily entering into a directory."""
|
||||
![pushd @(d)]
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
![popd]
|
||||
indir = with_pushd
|
||||
"""alias to push_d context manager"""
|
||||
|
||||
|
||||
def rmtree(dirname, force=False):
|
||||
|
@ -27,10 +22,10 @@ def rmtree(dirname, force=False):
|
|||
If True force removal, defaults to False
|
||||
"""
|
||||
if sys.platform == "win32":
|
||||
cmd_args = '/S/Q'
|
||||
![rmdir @(cmd_args) @(dirname)]
|
||||
cmd_args = "/S/Q"
|
||||
subproc_uncaptured(["rmdir", cmd_args, dirname])
|
||||
else:
|
||||
cmd_args = '-r'
|
||||
cmd_args = "-r"
|
||||
if force:
|
||||
cmd_args += 'f'
|
||||
![rm @(cmd_args) @(dirname)]
|
||||
cmd_args += "f"
|
||||
subproc_uncaptured(["rm", cmd_args, dirname])
|
|
@ -1,19 +1,19 @@
|
|||
"""Xonsh extension of the standard library subprocess module, using xonsh for
|
||||
subprocess calls"""
|
||||
from subprocess import CalledProcessError
|
||||
|
||||
from xonsh.tools import XonshCalledProcessError
|
||||
from xonsh.built_ins import XSH, subproc_captured_hiddenobject, subproc_captured_stdout
|
||||
from xonsh.lib.os import indir
|
||||
|
||||
|
||||
def run(cmd, cwd=None, check=False):
|
||||
"""Drop in replacement for ``subprocess.run`` like functionality"""
|
||||
env = XSH.env
|
||||
if cwd is None:
|
||||
with ${...}.swap(RAISE_SUBPROC_ERROR=check):
|
||||
p = ![@(cmd)]
|
||||
with env.swap(RAISE_SUBPROC_ERROR=check):
|
||||
p = subproc_captured_hiddenobject(cmd)
|
||||
else:
|
||||
with indir(cwd), ${...}.swap(RAISE_SUBPROC_ERROR=check):
|
||||
p = ![@(cmd)]
|
||||
with indir(cwd), env.swap(RAISE_SUBPROC_ERROR=check):
|
||||
p = subproc_captured_hiddenobject(cmd)
|
||||
return p
|
||||
|
||||
|
||||
|
@ -25,10 +25,12 @@ def check_call(cmd, cwd=None):
|
|||
|
||||
def check_output(cmd, cwd=None):
|
||||
"""Drop in replacement for ``subprocess.check_output`` like functionality"""
|
||||
env = XSH.env
|
||||
|
||||
if cwd is None:
|
||||
with ${...}.swap(RAISE_SUBPROC_ERROR=True):
|
||||
output = $(@(cmd))
|
||||
with env.swap(RAISE_SUBPROC_ERROR=True):
|
||||
output = subproc_captured_stdout(cmd)
|
||||
else:
|
||||
with indir(cwd), ${...}.swap(RAISE_SUBPROC_ERROR=True):
|
||||
output = $(@(cmd))
|
||||
return output.encode('utf-8')
|
||||
with indir(cwd), env.swap(RAISE_SUBPROC_ERROR=True):
|
||||
output = subproc_captured_stdout(cmd)
|
||||
return output.encode("utf-8")
|
Loading…
Add table
Reference in a new issue