diff options
Diffstat (limited to 'exts')
-rwxr-xr-x | exts/pip.find_deps | 39 | ||||
-rwxr-xr-x | exts/pip.to_lorry | 3 |
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: |