summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/command/checkdep.py
blob: 729002c72514ec49adec496117d92cc930a83f8f (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
"""distutils.command.x

Implements the Distutils 'x' command.
"""

# created 2000/mm/dd, John Doe

__revision__ = "$Id$"

from distutils.core import Command

class DependencyFailure(Exception): pass

class VersionTooOld(DependencyFailure): pass

class VersionNotKnown(DependencyFailure): pass

class checkdep (Command):

    # Brief (40-50 characters) description of the command
    description = "check package dependencies"

    # List of option tuples: long name, short name (None if no short
    # name), and help string.
    # Later on, we might have auto-fetch and the like here. Feel free.
    user_options = []

    def initialize_options (self):
        self.debug = None

    # initialize_options()


    def finalize_options (self):
        pass
    # finalize_options()


    def run (self):
        from distutils.version import LooseVersion
        failed = []
        for pkg, ver in self.distribution.metadata.requires:
            if pkg == 'python':
                if ver is not None:
                    # Special case the 'python' package
                    import sys
                    thisver = LooseVersion('%d.%d.%d'%sys.version_info[:3])
                    if thisver < ver:
                        failed.append(((pkg,ver), VersionTooOld(thisver)))
                continue
            # Kinda hacky - we should do more here
            try:
                mod = __import__(pkg)
            except Exception, e:
                failed.append(((pkg,ver), e))
                continue
            if ver is not None:
                if hasattr(mod, '__version__'):
                    thisver = LooseVersion(mod.__version__)
                    if thisver < ver:
                        failed.append(((pkg,ver), VersionTooOld(thisver)))
                else:
                    failed.append(((pkg,ver), VersionNotKnown()))

        if failed:
            raise DependencyFailure, failed

    # run()

# class x