diff options
author | Nicolas van Kempen <nvankemp@gmail.com> | 2024-08-30 14:26:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-30 19:26:49 +0100 |
commit | c49770c60f26e449379447109f7d915bd8de0384 (patch) | |
tree | 6ccadd331d1da78ee85c0f11f12a47b6a3187035 /llvm | |
parent | 07178981246c56e8beafe7fe49f0f442436f08c4 (diff) | |
download | llvm-c49770c60f26e449379447109f7d915bd8de0384.zip llvm-c49770c60f26e449379447109f7d915bd8de0384.tar.gz llvm-c49770c60f26e449379447109f7d915bd8de0384.tar.bz2 |
[NFC] Prefer subprocess.DEVNULL over os.devnull (#106500)
There is no need to support Python 2.7 anymore, Python 3.3+ has
`subprocess.DEVNULL`. This is good practice and also prevents file
handles from
staying open unnecessarily.
Also remove a couple unused or unneeded `__future__` imports.
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/utils/UpdateTestChecks/common.py | 16 | ||||
-rwxr-xr-x | llvm/utils/git/pre-push.py | 15 | ||||
-rwxr-xr-x | llvm/utils/gn/gn.py | 2 |
3 files changed, 10 insertions, 23 deletions
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py index c5e4ad4..9b9be69 100644 --- a/llvm/utils/UpdateTestChecks/common.py +++ b/llvm/utils/UpdateTestChecks/common.py @@ -1,11 +1,8 @@ -from __future__ import print_function - import argparse import bisect import collections import copy import glob -import itertools import os import re import subprocess @@ -517,12 +514,13 @@ def invoke_tool(exe, cmd_args, ir, preprocess_cmd=None, verbose=False): sep="", file=sys.stderr, ) - # Python 2.7 doesn't have subprocess.DEVNULL: - with open(os.devnull, "w") as devnull: - pp = subprocess.Popen( - preprocess_cmd, shell=True, stdin=devnull, stdout=subprocess.PIPE - ) - ir_file = pp.stdout + pp = subprocess.Popen( + preprocess_cmd, + shell=True, + stdin=subprocess.DEVNULL, + stdout=subprocess.PIPE, + ) + ir_file = pp.stdout if isinstance(cmd_args, list): args = [applySubstitutions(a, substitutions) for a in cmd_args] diff --git a/llvm/utils/git/pre-push.py b/llvm/utils/git/pre-push.py index d7ae376..dfa009d 100755 --- a/llvm/utils/git/pre-push.py +++ b/llvm/utils/git/pre-push.py @@ -27,7 +27,6 @@ From the git doc: """ import argparse -import os import shutil import subprocess import sys @@ -70,14 +69,6 @@ def ask_confirm(prompt): return query.lower() == "y" -def get_dev_null(): - """Lazily create a /dev/null fd for use in shell()""" - global dev_null_fd - if dev_null_fd is None: - dev_null_fd = open(os.devnull, "w") - return dev_null_fd - - def shell( cmd, strip=True, @@ -95,10 +86,8 @@ def shell( cwd_msg = " in %s" % cwd log_verbose("Running%s: %s" % (cwd_msg, " ".join(quoted_cmd))) - err_pipe = subprocess.PIPE - if ignore_errors: - # Silence errors if requested. - err_pipe = get_dev_null() + # Silence errors if requested. + err_pipe = subprocess.DEVNULL if ignore_errors else subprocess.PIPE start = time.time() p = subprocess.Popen( diff --git a/llvm/utils/gn/gn.py b/llvm/utils/gn/gn.py index 290c694..6b7919b 100755 --- a/llvm/utils/gn/gn.py +++ b/llvm/utils/gn/gn.py @@ -42,7 +42,7 @@ def main(): if ( subprocess.call( "gn --version", - stdout=open(os.devnull, "w"), + stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, shell=True, ) |