From 840ad06300ac38e0e0e18ea36d6969cc03c875a9 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 25 Sep 2021 09:18:25 +0100 Subject: [PATCH] Refs #32355 -- Modernized subprocess.run() calls. --- django/core/management/utils.py | 4 ++-- django/utils/version.py | 3 +-- scripts/manage_translations.py | 6 +++--- tests/admin_scripts/tests.py | 5 +++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/django/core/management/utils.py b/django/core/management/utils.py index 43addf8bdd..c6901aa3d5 100644 --- a/django/core/management/utils.py +++ b/django/core/management/utils.py @@ -1,7 +1,7 @@ import fnmatch import os from pathlib import Path -from subprocess import PIPE, run +from subprocess import run from django.apps import apps as installed_apps from django.utils.crypto import get_random_string @@ -17,7 +17,7 @@ def popen_wrapper(args, stdout_encoding='utf-8'): Return stdout output, stderr output, and OS status code. """ try: - p = run(args, stdout=PIPE, stderr=PIPE, close_fds=os.name != 'nt') + p = run(args, capture_output=True, close_fds=os.name != 'nt') except OSError as err: raise CommandError('Error executing %s' % args[0]) from err return ( diff --git a/django/utils/version.py b/django/utils/version.py index a72d3202fa..3ce6f465bd 100644 --- a/django/utils/version.py +++ b/django/utils/version.py @@ -85,8 +85,7 @@ def get_git_changeset(): repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) git_log = subprocess.run( 'git log --pretty=format:%ct --quiet -1 HEAD', - stdout=subprocess.PIPE, stderr=subprocess.PIPE, - shell=True, cwd=repo_dir, universal_newlines=True, + capture_output=True, shell=True, cwd=repo_dir, text=True, ) timestamp = git_log.stdout tz = datetime.timezone.utc diff --git a/scripts/manage_translations.py b/scripts/manage_translations.py index e67bf6e74d..fd394e10ab 100644 --- a/scripts/manage_translations.py +++ b/scripts/manage_translations.py @@ -20,7 +20,7 @@ import os from argparse import ArgumentParser -from subprocess import PIPE, run +from subprocess import run import django from django.conf import settings @@ -74,7 +74,7 @@ def _check_diff(cat_name, base_path): po_path = '%(path)s/en/LC_MESSAGES/django%(ext)s.po' % { 'path': base_path, 'ext': 'js' if cat_name.endswith('-js') else ''} p = run("git diff -U0 %s | egrep '^[-+]msgid' | wc -l" % po_path, - stdout=PIPE, stderr=PIPE, shell=True) + capture_output=True, shell=True) num_changes = int(p.stdout.strip()) print("%d changed/added messages in '%s' catalog." % (num_changes, cat_name)) @@ -123,7 +123,7 @@ def lang_stats(resources=None, languages=None): ) p = run( ['msgfmt', '-vc', '-o', '/dev/null', po_path], - stdout=PIPE, stderr=PIPE, + capture_output=True, env={'LANG': 'C'}, encoding='utf-8', ) diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index 9467bf32c3..2c3f365c74 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -120,9 +120,10 @@ class AdminScriptTestCase(SimpleTestCase): p = subprocess.run( [sys.executable, *args], - stdout=subprocess.PIPE, stderr=subprocess.PIPE, + capture_output=True, cwd=self.test_dir, - env=test_environ, universal_newlines=True, + env=test_environ, + text=True, ) return p.stdout, p.stderr