summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richard.ipsum@codethink.co.uk>2014-11-04 17:41:03 +0000
committerRichard Ipsum <richard.ipsum@codethink.co.uk>2014-11-04 17:42:12 +0000
commit25793d7b188504ff6e4646c7166860f8d3c41a0f (patch)
treedf18bad6b5bde966f12d7b1ddf0bca7f10c9ff14
parentd585a1ef9fb77510c37d3c7ad942eb12f47847db (diff)
downloadimport-25793d7b188504ff6e4646c7166860f8d3c41a0f.tar.gz
Add the beginnings of pip.find_deps
-rwxr-xr-xexts/pip.find_deps76
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