[subprocess2] Replace VOID with DEVNULL

subprocess.DEVNULL was introduced in Python3 to serve same purpose
as subprocess2.VOID, so rename VOID to DEVNULL in subprocess2.

Change-Id: I6dade3306ffc3bc2441ac6083f362b099c2427e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2587758
Reviewed-by: Anthony Polito <apolito@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
This commit is contained in:
Edward Lesmes
2020-12-14 22:03:23 +00:00
committed by LUCI CQ
parent 9c7f6c25c0
commit cf06cad1be
7 changed files with 29 additions and 29 deletions

View File

@@ -21,18 +21,18 @@ import threading
if sys.version_info.major == 2:
import Queue
codecs.lookup('string-escape')
# Sends stdout or stderr to os.devnull.
DEVNULL = open(os.devnull, 'r+')
else:
import queue as Queue
# pylint: disable=redefined-builtin
basestring = (str, bytes)
DEVNULL = subprocess.DEVNULL
# Constants forwarded from subprocess.
PIPE = subprocess.PIPE
STDOUT = subprocess.STDOUT
# Sends stdout or stderr to os.devnull.
VOID = open(os.devnull, 'w')
VOID_INPUT = open(os.devnull, 'r')
class CalledProcessError(subprocess.CalledProcessError):
@@ -107,7 +107,7 @@ class Popen(subprocess.Popen):
in English.
- Sets shell=True on windows by default. You can override this by forcing
shell parameter to a value.
- Adds support for VOID to not buffer when not needed.
- Adds support for DEVNULL to not buffer when not needed.
- Adds self.start property.
Note: Popen() can throw OSError when cwd or args[0] doesn't exist. Translate
@@ -197,16 +197,16 @@ def communicate(args, **kwargs):
def call(args, **kwargs):
"""Emulates subprocess.call().
Automatically convert stdout=PIPE or stderr=PIPE to VOID.
Automatically convert stdout=PIPE or stderr=PIPE to DEVNULL.
In no case they can be returned since no code path raises
subprocess2.CalledProcessError.
Returns exit code.
"""
if kwargs.get('stdout') == PIPE:
kwargs['stdout'] = VOID
kwargs['stdout'] = DEVNULL
if kwargs.get('stderr') == PIPE:
kwargs['stderr'] = VOID
kwargs['stderr'] = DEVNULL
return communicate(args, **kwargs)[1]
@@ -236,7 +236,7 @@ def capture(args, **kwargs):
- Discards returncode.
- Blocks stdin by default if not specified since no output will be visible.
"""
kwargs.setdefault('stdin', VOID_INPUT)
kwargs.setdefault('stdin', DEVNULL)
# Like check_output, deny the caller from using stdout arg.
return communicate(args, stdout=PIPE, **kwargs)[0][0]
@@ -252,7 +252,7 @@ def check_output(args, **kwargs):
- Blocks stdin by default if not specified since no output will be visible.
- As per doc, "The stdout argument is not allowed as it is used internally."
"""
kwargs.setdefault('stdin', VOID_INPUT)
kwargs.setdefault('stdin', DEVNULL)
if 'stdout' in kwargs:
raise ValueError('stdout argument not allowed, it would be overridden.')
return check_call_out(args, stdout=PIPE, **kwargs)[0]