diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-01-11 01:32:08 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-01-11 02:02:37 +0900 |
commit | 041da498aa230a5d7a508858dac00e3741bfcd10 (patch) | |
tree | 2e23e95cb4c13ca5e8c3a3cd7fb6cb32fa11ac73 /sphinx/builders/applehelp.py | |
parent | bf62a968319be9bdc735b3e855f505b4b1bdbedc (diff) | |
download | sphinx-git-041da498aa230a5d7a508858dac00e3741bfcd10.tar.gz |
refactor applehelp: Use subprocess.run() instead of Popen
Diffstat (limited to 'sphinx/builders/applehelp.py')
-rw-r--r-- | sphinx/builders/applehelp.py | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/sphinx/builders/applehelp.py b/sphinx/builders/applehelp.py index f1db441b9..43969a7eb 100644 --- a/sphinx/builders/applehelp.py +++ b/sphinx/builders/applehelp.py @@ -12,6 +12,7 @@ import plistlib import shlex import subprocess from os import path, environ +from subprocess import CalledProcessError, PIPE, STDOUT from sphinx import package_dir from sphinx.builders.html import StandaloneHTMLBuilder @@ -207,18 +208,12 @@ class AppleHelpBuilder(StandaloneHTMLBuilder): ' '.join([shlex.quote(arg) for arg in args])) else: try: - p = subprocess.Popen(args, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT) - - output = p.communicate()[0] - - if p.returncode != 0: - raise AppleHelpIndexerFailed(output) - else: - logger.info(__('done')) + subprocess.run(args, stdout=PIPE, stderr=STDOUT, check=True) + logger.info(__('done')) except OSError: raise AppleHelpIndexerFailed(__('Command not found: %s') % args[0]) + except CalledProcessError as exc: + raise AppleHelpCodeSigningFailed(exc.stdout) def do_codesign(self): # type: () -> None @@ -242,18 +237,12 @@ class AppleHelpBuilder(StandaloneHTMLBuilder): ' '.join([shlex.quote(arg) for arg in args])) else: try: - p = subprocess.Popen(args, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT) - - output = p.communicate()[0] - - if p.returncode != 0: - raise AppleHelpCodeSigningFailed(output) - else: - logger.info(__('done')) + subprocess.run(args, stdout=PIPE, stderr=STDOUT, check=True) + logger.info(__('done')) except OSError: raise AppleHelpCodeSigningFailed(__('Command not found: %s') % args[0]) + except CalledProcessError as exc: + raise AppleHelpCodeSigningFailed(exc.stdout) def setup(app): |