diff options
Diffstat (limited to 'exts/pip.find_deps')
-rwxr-xr-x | exts/pip.find_deps | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/exts/pip.find_deps b/exts/pip.find_deps new file mode 100755 index 0000000..db0e71e --- /dev/null +++ b/exts/pip.find_deps @@ -0,0 +1,76 @@ +#!/usr/bin/env python +# +# Find the build and runtime dependencies for a given Python package +# +# Copyright (C) 2014 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +from __future__ import print_function + +import sys +import subprocess +import os + +import requirements + +DEBUG = False + +# TODO: I'm guessing these things are probably standard somewhere +def warn(*args, **kwargs): + print('%s:' % sys.argv[0], *args, file=sys.stderr, **kwargs) + +def error(*args, **kwargs): + warn(*args, **kwargs) + sys.exit(1) + +def debug(s): + if DEBUG: + print(s) + +def find_build_deps(source, name, version=None): + debug('source: %s' % source) + debug('name: %s' % name) + debug('version: %s' % version) + + # This amounts to running python setup.py egg_info and checking + # the resulting egg_info dir for a file called setup_requires.txt + + # So it's $name.egg_info + p = subprocess.Popen(['python', 'setup.py', 'egg_info'], cwd=source, + stdout=subprocess.PIPE) + + if p.wait() != 0: + error('egg_info command failed') + + egg_dir = '%s.egg_info' % name + build_deps_file = os.path.join(source, egg_dir, 'setup_requires.txt') + + # Check whether there's a setup_requires.txt + if not os.path.isfile(build_deps_file): + print('%s has no build dependencies' % name) + else: + with open(build_deps_file) as f: + print(list(f.read())) + #json = parse_requirements(...) + +if len(sys.argv) not in [3, 4]: + print('usage: %s PACKAGE_SOURCE_DIR NAME [VERSION]' % sys.argv[0]) + sys.exit(1) + +# Ignore the issue of dependency conflicts for now + +# First, given a source return build dependencies in json from + +find_build_deps(*sys.argv[1:])
\ No newline at end of file |