summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richard.ipsum@codethink.co.uk>2014-12-01 15:17:00 +0000
committerRichard Ipsum <richard.ipsum@codethink.co.uk>2014-12-01 15:17:00 +0000
commite5070dbe6ae22d7d81d89c57700992e9a1e15d19 (patch)
treed369cb7303cb40b6ca7ddfbb6c05a4d82b954a5f
parent3ebca1e99b7de4556ea7bc59c508d5205870486f (diff)
downloadimport-e5070dbe6ae22d7d81d89c57700992e9a1e15d19.tar.gz
Improve error msg on failure to find runtime deps
-rwxr-xr-xexts/pip.find_deps39
-rwxr-xr-xexts/pip.to_lorry3
2 files changed, 39 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))
diff --git a/exts/pip.to_lorry b/exts/pip.to_lorry
index be207f7..d537851 100755
--- a/exts/pip.to_lorry
+++ b/exts/pip.to_lorry
@@ -64,6 +64,7 @@ def find_repo_type(url):
poll.register(p.stderr)
# Multiplex stdout and stderr
+ # TODO: replace this by setting stderr=stdout
while fdmap != {}:
fds = poll.poll()
@@ -75,6 +76,8 @@ def find_repo_type(url):
else:
logging.debug('%s' % line)
+ p.wait() # even with eof on both streams, we still wait
+
shutil.rmtree(tempdir)
if p.returncode == 0: