Skip to content

Commit

Permalink
Refs #32355 -- Modernized subprocess.run() calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz authored and felixxm committed Sep 27, 2021
1 parent ca58378 commit 840ad06
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions 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
Expand All @@ -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 (
Expand Down
3 changes: 1 addition & 2 deletions django/utils/version.py
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions scripts/manage_translations.py
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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',
)
Expand Down
5 changes: 3 additions & 2 deletions tests/admin_scripts/tests.py
Expand Up @@ -120,9 +120,10 @@ def run_test(self, args, settings_file=None, apps=None):

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

Expand Down

0 comments on commit 840ad06

Please sign in to comment.