From 14c1f486cf510bf76ff903710ff892606b71726d Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Fri, 27 Mar 2020 11:24:34 -0400 Subject: setup.py: drop NIH check_output implementation (#282) We no longer need to support versions which don't have subprocess.check_output, so we can rely on its presence in the stdlib. --- setup.py | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/setup.py b/setup.py index 22b32f6f..cbacf48e 100755 --- a/setup.py +++ b/setup.py @@ -34,23 +34,6 @@ def is_f(p): def is_generator(p): return '-generator' in p -def tiny_p(cmd, capture=True): - # Darn python 2.6 doesn't have check_output (argggg) - stdout = subprocess.PIPE - stderr = subprocess.PIPE - if not capture: - stdout = None - stderr = None - sp = subprocess.Popen(cmd, stdout=stdout, - stderr=stderr, stdin=None, - universal_newlines=True) - (out, err) = sp.communicate() - ret = sp.returncode - if ret not in [0]: - raise RuntimeError("Failed running %s [rc=%s] (%s, %s)" % - (cmd, ret, out, err)) - return (out, err) - def pkg_config_read(library, var): fallbacks = { @@ -61,7 +44,7 @@ def pkg_config_read(library, var): } cmd = ['pkg-config', '--variable=%s' % var, library] try: - (path, err) = tiny_p(cmd) + path = subprocess.check_output(cmd).decode('utf-8') path = path.strip() except Exception: path = fallbacks[library][var] @@ -83,14 +66,14 @@ def in_virtualenv(): def get_version(): cmd = [sys.executable, 'tools/read-version'] - (ver, _e) = tiny_p(cmd) - return str(ver).strip() + ver = subprocess.check_output(cmd) + return ver.decode('utf-8').strip() def read_requires(): cmd = [sys.executable, 'tools/read-dependencies'] - (deps, _e) = tiny_p(cmd) - return str(deps).splitlines() + deps = subprocess.check_output(cmd) + return deps.decode('utf-8').splitlines() def render_tmpl(template, mode=None): @@ -118,10 +101,11 @@ def render_tmpl(template, mode=None): bname = os.path.basename(template).rstrip(tmpl_ext) fpath = os.path.join(tmpd, bname) if VARIANT: - tiny_p([sys.executable, './tools/render-cloudcfg', '--variant', - VARIANT, template, fpath]) + subprocess.run([sys.executable, './tools/render-cloudcfg', '--variant', + VARIANT, template, fpath]) else: - tiny_p([sys.executable, './tools/render-cloudcfg', template, fpath]) + subprocess.run( + [sys.executable, './tools/render-cloudcfg', template, fpath]) if mode: os.chmod(fpath, mode) # return path relative to setup.py -- cgit v1.2.3