Mercurial > hg > PaInt
changeset 54:a8236b97abd3
separate methods for gathering package information
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 23 Jan 2013 15:12:37 -0800 |
parents | c588375a7ce4 |
children | 72e521851f1a |
files | paint/info.py tests/doctest.txt |
diffstat | 2 files changed, 42 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/paint/info.py Wed Jan 23 15:12:37 2013 -0800 @@ -0,0 +1,37 @@ +""" +interfaces to get information from a package +""" + +import os +import sys + +class PackageInfo(object): + """abstract base class of package info""" + def __init__(self, path): + """ + - path : path to setup.py or its directory + """ + if os.path.isdir(path): + path = os.path.join(path, 'setup.py') + assert os.path.exists(path), "'%s' not found" % path + self.setup_py = os.path.abspath(path) + + def __call__(self): + """returns dictionary of package info""" + raise NotImplementedError("abstract base class") + +class SetupOverridePackageInfo(PackageInfo): + """ + gather setup.py information by overriding the function + """ + + def __call__(self): + setuptools = sys.modules.get('setuptools') + sys.modules['setuptools'] = sys.modules[__name__] + globals()['setup'] = self._setup + try: + + return self.__dict__.pop('_info') + + def _setup(self, **kwargs): + self._info = kwargs
--- a/tests/doctest.txt Wed Jan 02 13:59:27 2013 -0800 +++ b/tests/doctest.txt Wed Jan 23 15:12:37 2013 -0800 @@ -12,3 +12,8 @@ >>> dependencies == {'mozharness': 'http://hg.mozilla.org/build/mozharness/archive/tip.tar.gz#egg=mozharness', 'talos': 'http://hg.mozilla.org/build/talos/archive/tip.tar.gz#egg=talos'} True >>> jetperf._cleanup() + +Test different ways of getting package information. First we'll use +an interface that overrides ``setuptools.setup``:: + + >>> import paint.info