Mercurial > hg > PaInt
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 |
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 | 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 | 9 from subprocess import check_call as call |
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 | 36 module = imp.load_source('setup', self.setup_py) |
56 | 37 finally: |
38 sys.modules.pop('setuptools') | |
39 if setuptools: | |
40 sys.modules['setuptools'] = setuptools | |
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 | 46 |
47 class EggInfo(PackageInfo): | |
48 """ | |
49 use `python setup.py egg_info` to gather package information | |
50 """ | |
51 | |
52 def __call__(self): | |
53 raise NotImplementedError("TODO") | |
54 | |
55 def _egg_info(self): | |
56 """build the egg_info directory""" | |
57 | |
58 if self._egg_info_path: | |
59 return self._egg_info_path | |
60 | |
61 raise NotImplementedError("TODO") |