Commit acf7e91d authored by Kirill Smelkov's avatar Kirill Smelkov

setup/runcmd: Properly report errors, if running command is missing

We currently use subprocess.check_output() for running external command
(git), and check_output() checks running command status code, as its
name promises:

    https://github.com/python/cpython/blob/2.7/Lib/subprocess.py#L569

and reports it appropriately to user:

    https://github.com/python/cpython/blob/2.7/Lib/subprocess.py#L411

but if the command is not found, it is just single

    error: [Errno 2] No such file or directory

which gets output to the log and it is not clear what command failed, or
evern if it is from runcmd() call.

Redo our runcmd() manually, so that it always report erros with context
- what command it was trying to run. The error now becomes:

   RuntimeError: (['missing-command'],): [Errno 2] No such file or directory

/cc @Tyagov
parent 7a0b30fa
......@@ -19,7 +19,7 @@ from setuptools import setup, Extension, Command, find_packages
from setuptools.command.build_py import build_py as _build_py
from setuptools.command.build_ext import build_ext as _build_ext
from distutils.errors import DistutilsExecError
from subprocess import check_output as runcmd
from subprocess import Popen, PIPE
import os
import sys
......@@ -165,6 +165,24 @@ def register_as_entrypoint(func, entryname, groupname, distname):
assert entryname not in group
group[entryname] = entrypoint
# like subprocess.check_output(), but properly report errors, if e.g. commands is not found
# check_output(['missing-command']) -> error: [Errno 2] No such file or directory
# runcmd (['missing-command']) -> error: ['missing-command']: [Errno 2] No such file or directory
def runcmd(argv):
try:
process = Popen(argv, stdout=PIPE)
except Exception, e:
raise RuntimeError("%s: %s" % (argv, e))
output, _err = process.communicate()
retcode = process.poll()
if retcode:
raise RuntimeError("%s -> failed (status %s)" % (argv, retcode))
return output
def git_lsfiles(dirname):
# FIXME dirname is currently ignored
# XXX non-ascii names, etc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment