Anthony Baxter | 05f842b | 2004-03-22 22:22:05 +0000 | [diff] [blame^] | 1 | """distutils.command.x |
| 2 | |
| 3 | Implements the Distutils 'x' command. |
| 4 | """ |
| 5 | |
| 6 | # created 2000/mm/dd, John Doe |
| 7 | |
| 8 | __revision__ = "$Id$" |
| 9 | |
| 10 | from distutils.core import Command |
| 11 | |
| 12 | class DependencyFailure(Exception): pass |
| 13 | |
| 14 | class VersionTooOld(DependencyFailure): pass |
| 15 | |
| 16 | class VersionNotKnown(DependencyFailure): pass |
| 17 | |
| 18 | class checkdep (Command): |
| 19 | |
| 20 | # Brief (40-50 characters) description of the command |
| 21 | description = "check package dependencies" |
| 22 | |
| 23 | # List of option tuples: long name, short name (None if no short |
| 24 | # name), and help string. |
| 25 | # Later on, we might have auto-fetch and the like here. Feel free. |
| 26 | user_options = [] |
| 27 | |
| 28 | def initialize_options (self): |
| 29 | self.debug = None |
| 30 | |
| 31 | # initialize_options() |
| 32 | |
| 33 | |
| 34 | def finalize_options (self): |
| 35 | pass |
| 36 | # finalize_options() |
| 37 | |
| 38 | |
| 39 | def run (self): |
| 40 | from distutils.version import LooseVersion |
| 41 | failed = [] |
| 42 | for pkg, ver in self.distribution.metadata.requires: |
| 43 | if pkg == 'python': |
| 44 | if ver is not None: |
| 45 | # Special case the 'python' package |
| 46 | import sys |
| 47 | thisver = LooseVersion('%d.%d.%d'%sys.version_info[:3]) |
| 48 | if thisver < ver: |
| 49 | failed.append(((pkg,ver), VersionTooOld(thisver))) |
| 50 | continue |
| 51 | # Kinda hacky - we should do more here |
| 52 | try: |
| 53 | mod = __import__(pkg) |
| 54 | except Exception, e: |
| 55 | failed.append(((pkg,ver), e)) |
| 56 | continue |
| 57 | if ver is not None: |
| 58 | if hasattr(mod, '__version__'): |
| 59 | thisver = LooseVersion(mod.__version__) |
| 60 | if thisver < ver: |
| 61 | failed.append(((pkg,ver), VersionTooOld(thisver))) |
| 62 | else: |
| 63 | failed.append(((pkg,ver), VersionNotKnown())) |
| 64 | |
| 65 | if failed: |
| 66 | raise DependencyFailure, failed |
| 67 | |
| 68 | # run() |
| 69 | |
| 70 | # class x |