summaryrefslogtreecommitdiff
path: root/exts/pip.find_deps
diff options
context:
space:
mode:
Diffstat (limited to 'exts/pip.find_deps')
-rwxr-xr-xexts/pip.find_deps39
1 files changed, 36 insertions, 3 deletions
diff --git a/exts/pip.find_deps b/exts/pip.find_deps
index 8c4f432..d788143 100755
--- a/exts/pip.find_deps
+++ b/exts/pip.find_deps
@@ -25,6 +25,7 @@ import os
import json
import tempfile
import logging
+import select
import pkg_resources
import xmlrpclib
@@ -245,13 +246,45 @@ def find_runtime_deps(source, name, version=None):
# Some temporary file needed for storing the requirements
tmpfd, tmppath = tempfile.mkstemp()
+ logging.debug('Writing install requirements to: %s', tmppath)
p = subprocess.Popen(['pip', 'install', '.',
'--list-dependencies=%s' % tmppath], cwd=source,
- stdout=subprocess.PIPE)
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+ stdin=subprocess.PIPE)
- if p.wait() != 0:
- error('pip install --list-dependencies command failed')
+ # We close stdin on parent side to prevent the child from blocking
+ # if it reads on stdin
+ p.stdin.close()
+
+ poll = select.poll()
+
+ logging.debug('p.stdout: %s' % p.stdout)
+ logging.debug('p.stderr: %s' % p.stderr)
+
+ fdmap = {p.stdout.fileno(): p.stdout, p.stderr.fileno(): p.stderr}
+ poll.register(p.stdout)
+ poll.register(p.stderr)
+
+ # Multiplex stdout and stderr
+ # TODO: replace by setting stderr=stdout
+ while fdmap != {}:
+ fds = poll.poll()
+
+ for (fd, _) in fds:
+ line = fdmap[fd].readline()
+ if line == '':
+ poll.unregister(fd)
+ del fdmap[fd]
+ else:
+ logging.debug('%s' % line.rstrip())
+
+ p.wait() # even with eof on both streams, we still wait
+
+ logging.debug('pip exited with code: %d' % p.returncode)
+
+ if p.returncode != 0:
+ error('failed to get runtime dependencies')
with os.fdopen(tmpfd) as tmpfile:
ss = resolve_specs(pkg_resources.parse_requirements(tmpfile))