summaryrefslogtreecommitdiff
path: root/exts/pip.find_deps
blob: db0e71e513f14361be6622ec1a68f426e3e02081 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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:])