From 7852ead1fe1592ee8ce5254f6ced5bf4a89a2c5f Mon Sep 17 00:00:00 2001 From: guido Date: Sun, 4 Feb 2007 15:27:10 +0100 Subject: [PATCH] [svn r37912] Made some small changes to the initpkg mechanism so docstrings are, if provided in the exportdefs, copied to the namespaces (from whereever they come), and added docstrings to all exposed namespaces (except for _thread for now). --HG-- branch : trunk --- py/__init__.py | 18 +++++++++++++++--- py/builtin/__init__.py | 3 ++- py/code/__init__.py | 2 +- py/compat/__init__.py | 3 ++- py/execnet/__init__.py | 2 +- py/initpkg.py | 6 +++++- py/io/__init__.py | 2 +- py/log/__init__.py | 3 ++- py/magic/__init__.py | 2 +- py/misc/std.py | 2 ++ py/misc/testing/test_initpkg.py | 8 ++++++++ py/path/__init__.py | 2 +- py/process/__init__.py | 2 +- py/test/__init__.py | 2 +- py/xmlobj/__init__.py | 3 ++- 15 files changed, 45 insertions(+), 15 deletions(-) diff --git a/py/__init__.py b/py/__init__.py index bd52ddaaf..9f2810188 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -9,8 +9,8 @@ version = "0.8.80-alpha2" initpkg(__name__, description = "py.test and the py lib", - revision = int('$LastChangedRevision: 37863 $'.split(':')[1][:-1]), - lastchangedate = '$LastChangedDate: 2007-02-03 13:15:23 +0100 (Sat, 03 Feb 2007) $', + revision = int('$LastChangedRevision: 37912 $'.split(':')[1][:-1]), + lastchangedate = '$LastChangedDate: 2007-02-04 15:27:10 +0100 (Sun, 04 Feb 2007) $', version = version, url = "http://codespeak.net/py", download_url = "http://codespeak.net/download/py/%s.tar.gz" %(version,), @@ -22,6 +22,7 @@ initpkg(__name__, exportdefs = { # helpers for use from test functions or collectors + 'test.__doc__' : ('./test/__init__.py', '__doc__'), 'test.raises' : ('./test/raises.py', 'raises'), 'test.deprecated_call' : ('./test/deprecate.py', 'deprecated_call'), 'test.skip' : ('./test/item.py', 'skip'), @@ -52,14 +53,17 @@ initpkg(__name__, # hook into the top-level standard library 'std' : ('./misc/std.py', 'std'), + 'process.__doc__' : ('./process/__init__.py', '__doc__'), 'process.cmdexec' : ('./process/cmdexec.py', 'cmdexec'), - # path implementations + # path implementation + 'path.__doc__' : ('./path/__init__.py', '__doc__'), 'path.svnwc' : ('./path/svn/wccommand.py', 'SvnWCCommandPath'), 'path.svnurl' : ('./path/svn/urlcommand.py', 'SvnCommandPath'), 'path.local' : ('./path/local/local.py', 'LocalPath'), # some nice slightly magic APIs + 'magic.__doc__' : ('./magic/__init__.py', '__doc__'), 'magic.greenlet' : ('./magic/greenlet.py', 'greenlet'), 'magic.invoke' : ('./magic/invoke.py', 'invoke'), 'magic.revoke' : ('./magic/invoke.py', 'revoke'), @@ -69,6 +73,7 @@ initpkg(__name__, 'magic.AssertionError' : ('./magic/assertion.py', 'AssertionError'), # python inspection/code-generation API + 'code.__doc__' : ('./code/__init__.py', '__doc__'), 'code.compile' : ('./code/source.py', 'compile_'), 'code.Source' : ('./code/source.py', 'Source'), 'code.Code' : ('./code/code.py', 'Code'), @@ -77,6 +82,7 @@ initpkg(__name__, 'code.Traceback' : ('./code/traceback2.py', 'Traceback'), # backports and additions of builtins + 'builtin.__doc__' : ('./builtin/__init__.py', '__doc__'), 'builtin.enumerate' : ('./builtin/enumerate.py', 'enumerate'), 'builtin.reversed' : ('./builtin/reversed.py', 'reversed'), 'builtin.sorted' : ('./builtin/sorted.py', 'sorted'), @@ -85,6 +91,7 @@ initpkg(__name__, 'builtin.frozenset' : ('./builtin/set.py', 'frozenset'), # gateways into remote contexts + 'execnet.__doc__' : ('./execnet/__init__.py', '__doc__'), 'execnet.SocketGateway' : ('./execnet/register.py', 'SocketGateway'), 'execnet.PopenGateway' : ('./execnet/register.py', 'PopenGateway'), 'execnet.SshGateway' : ('./execnet/register.py', 'SshGateway'), @@ -93,6 +100,7 @@ initpkg(__name__, 'execnet.RSync' : ('./execnet/rsync.py', 'RSync'), # input-output helping + 'io.__doc__' : ('./io/__init__.py', '__doc__'), 'io.dupfile' : ('./io/dupfile.py', 'dupfile'), 'io.FDCapture' : ('./io/fdcapture.py', 'FDCapture'), 'io.StdCapture' : ('./io/stdcapture.py', 'StdCapture'), @@ -102,6 +110,7 @@ initpkg(__name__, 'error' : ('./misc/error.py', 'error'), # small and mean xml/html generation + 'xml.__doc__' : ('./xmlobj/__init__.py', '__doc__'), 'xml.html' : ('./xmlobj/html.py', 'html'), 'xml.Tag' : ('./xmlobj/xml.py', 'Tag'), 'xml.raw' : ('./xmlobj/xml.py', 'raw'), @@ -109,6 +118,7 @@ initpkg(__name__, 'xml.escape' : ('./xmlobj/misc.py', 'escape'), # logging API ('producers' and 'consumers' connected via keywords) + 'log.__doc__' : ('./log/__init__.py', '__doc__'), 'log.Producer' : ('./log/producer.py', 'Producer'), 'log.default' : ('./log/producer.py', 'default'), 'log._getstate' : ('./log/producer.py', '_getstate'), @@ -121,8 +131,10 @@ initpkg(__name__, 'log.get' : ('./log/logger.py', 'get'), # compatibility modules (taken from 2.4.4) + 'compat.__doc__' : ('./compat/__init__.py', '__doc__'), 'compat.doctest' : ('./compat/doctest.py', '*'), 'compat.optparse' : ('./compat/optparse.py', '*'), 'compat.textwrap' : ('./compat/textwrap.py', '*'), 'compat.subprocess' : ('./compat/subprocess.py', '*'), }) + diff --git a/py/builtin/__init__.py b/py/builtin/__init__.py index 792d60054..f9848c1a7 100644 --- a/py/builtin/__init__.py +++ b/py/builtin/__init__.py @@ -1 +1,2 @@ -# +""" backports and additions of builtins """ + diff --git a/py/code/__init__.py b/py/code/__init__.py index 792d60054..f15acf851 100644 --- a/py/code/__init__.py +++ b/py/code/__init__.py @@ -1 +1 @@ -# +""" python inspection/code generation API """ diff --git a/py/compat/__init__.py b/py/compat/__init__.py index 792d60054..727911bc9 100644 --- a/py/compat/__init__.py +++ b/py/compat/__init__.py @@ -1 +1,2 @@ -# +""" compatibility modules (taken from 2.4.4) """ + diff --git a/py/execnet/__init__.py b/py/execnet/__init__.py index 792d60054..603aa384e 100644 --- a/py/execnet/__init__.py +++ b/py/execnet/__init__.py @@ -1 +1 @@ -# +""" ad-hoc networking mechanism """ diff --git a/py/initpkg.py b/py/initpkg.py index 4419995fc..3ca72c0a5 100644 --- a/py/initpkg.py +++ b/py/initpkg.py @@ -259,7 +259,11 @@ def initpkg(pkgname, exportdefs, **kw): "only root modules are allowed to be non-lazy. " deferred_imports.append((mod, pyparts[-1], extpy)) else: - mod.__map__[lastmodpart] = extpy + if extpy[1] == '__doc__': + mod.__doc__ = pkg._resolve(extpy) + else: + mod.__map__[lastmodpart] = extpy for mod, pypart, extpy in deferred_imports: setattr(mod, pypart, pkg._resolve(extpy)) + diff --git a/py/io/__init__.py b/py/io/__init__.py index 792d60054..835f01f3a 100644 --- a/py/io/__init__.py +++ b/py/io/__init__.py @@ -1 +1 @@ -# +""" input/output helping """ diff --git a/py/log/__init__.py b/py/log/__init__.py index 792d60054..fad62e960 100644 --- a/py/log/__init__.py +++ b/py/log/__init__.py @@ -1 +1,2 @@ -# +""" logging API ('producers' and 'consumers' connected via keywords) """ + diff --git a/py/magic/__init__.py b/py/magic/__init__.py index 792d60054..5f73d550b 100644 --- a/py/magic/__init__.py +++ b/py/magic/__init__.py @@ -1 +1 @@ -# +""" some nice, slightly magic APIs """ diff --git a/py/misc/std.py b/py/misc/std.py index 4c979361b..7c711cdfd 100644 --- a/py/misc/std.py +++ b/py/misc/std.py @@ -2,6 +2,8 @@ import sys class Std(object): + """ (lazily) hook into the top-level standard library """ + def __init__(self): self.__dict__ = sys.modules diff --git a/py/misc/testing/test_initpkg.py b/py/misc/testing/test_initpkg.py index 015b64be8..86cb91f1a 100644 --- a/py/misc/testing/test_initpkg.py +++ b/py/misc/testing/test_initpkg.py @@ -127,12 +127,15 @@ class TestRealModule: tfile.write(py.code.Source(""" import py py.initpkg('realtest', { + 'x.module.__doc__': ('./testmodule.py', '__doc__'), 'x.module': ('./testmodule.py', '*'), }) """)) tfile = pkgdir.join('testmodule.py') tfile.write(py.code.Source(""" + 'test module' + __all__ = ['mytest0', 'mytest1', 'MyTest'] def mytest0(): @@ -186,6 +189,11 @@ class TestRealModule: assert 'mytest1' in moddict assert 'MyTest' in moddict + def test_realmodule___doc__(self): + """test whether the __doc__ attribute is set properly from initpkg""" + import realtest.x.module + assert realtest.x.module.__doc__ == 'test module' + #class TestStdHook: # """Tests imports for the standard Python library hook.""" # diff --git a/py/path/__init__.py b/py/path/__init__.py index 792d60054..51f3246f8 100644 --- a/py/path/__init__.py +++ b/py/path/__init__.py @@ -1 +1 @@ -# +""" unified file system api """ diff --git a/py/process/__init__.py b/py/process/__init__.py index 792d60054..86c714ad1 100644 --- a/py/process/__init__.py +++ b/py/process/__init__.py @@ -1 +1 @@ -# +""" high-level sub-process handling """ diff --git a/py/test/__init__.py b/py/test/__init__.py index 792d60054..091799fd4 100644 --- a/py/test/__init__.py +++ b/py/test/__init__.py @@ -1 +1 @@ -# +""" versatile unit-testing tool + libraries """ diff --git a/py/xmlobj/__init__.py b/py/xmlobj/__init__.py index 792d60054..7caf45491 100644 --- a/py/xmlobj/__init__.py +++ b/py/xmlobj/__init__.py @@ -1 +1,2 @@ -# +""" small and mean xml/html generation """ +