annotate paint/info.py @ 57:d5e5c7496784

stubbing
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 23 Jan 2013 16:26:14 -0800
parents 042a1b2a3e8a
children 13767ee2ddf4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
54
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 """
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 interfaces to get information from a package
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4
57
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
5 import imp
54
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 import os
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 import sys
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8
57
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
9 from subprocess import check_call as call
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
10
54
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 class PackageInfo(object):
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 """abstract base class of package info"""
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 def __init__(self, path):
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 """
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 - path : path to setup.py or its directory
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 """
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 if os.path.isdir(path):
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 path = os.path.join(path, 'setup.py')
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 assert os.path.exists(path), "'%s' not found" % path
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 self.setup_py = os.path.abspath(path)
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 def __call__(self):
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 """returns dictionary of package info"""
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 raise NotImplementedError("abstract base class")
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 class SetupOverridePackageInfo(PackageInfo):
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 """
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28 gather setup.py information by overriding the function
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29 """
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31 def __call__(self):
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32 setuptools = sys.modules.get('setuptools')
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 sys.modules['setuptools'] = sys.modules[__name__]
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 globals()['setup'] = self._setup
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35 try:
57
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
36 module = imp.load_source('setup', self.setup_py)
56
042a1b2a3e8a start flushing out tests
Jeff Hammel <jhammel@mozilla.com>
parents: 54
diff changeset
37 finally:
042a1b2a3e8a start flushing out tests
Jeff Hammel <jhammel@mozilla.com>
parents: 54
diff changeset
38 sys.modules.pop('setuptools')
042a1b2a3e8a start flushing out tests
Jeff Hammel <jhammel@mozilla.com>
parents: 54
diff changeset
39 if setuptools:
042a1b2a3e8a start flushing out tests
Jeff Hammel <jhammel@mozilla.com>
parents: 54
diff changeset
40 sys.modules['setuptools'] = setuptools
042a1b2a3e8a start flushing out tests
Jeff Hammel <jhammel@mozilla.com>
parents: 54
diff changeset
41 globals().pop('setup')
54
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
42 return self.__dict__.pop('_info')
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
43
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
44 def _setup(self, **kwargs):
a8236b97abd3 separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
45 self._info = kwargs
57
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
46
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
47 class EggInfo(PackageInfo):
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
48 """
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
49 use `python setup.py egg_info` to gather package information
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
50 """
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
51
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
52 def __call__(self):
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
53 raise NotImplementedError("TODO")
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
54
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
55 def _egg_info(self):
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
56 """build the egg_info directory"""
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
57
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
58 if self._egg_info_path:
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
59 return self._egg_info_path
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
60
d5e5c7496784 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 56
diff changeset
61 raise NotImplementedError("TODO")