using apipkg 1.0b2 snapshot version - adjusting/cleaning up some impl-detail accesses

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-10-27 21:31:42 +01:00
parent cc3404b832
commit 33bd39053f
10 changed files with 33 additions and 25 deletions

5
_py/_metainfo.py Normal file
View File

@ -0,0 +1,5 @@
import py
import _py
impldir = py.path.local(_py.__file__).dirpath()

View File

@ -5,18 +5,21 @@ see http://pypi.python.org/pypi/apipkg
(c) holger krekel, 2009 - MIT license (c) holger krekel, 2009 - MIT license
""" """
import os, sys import sys
from types import ModuleType from types import ModuleType
__version__ = "1.0b1" __version__ = "1.0b2"
def initpkg(pkgname, exportdefs): def initpkg(pkgname, exportdefs):
""" initialize given package from the export definitions. """ """ initialize given package from the export definitions.
pkgmodule = sys.modules[pkgname] replace it in sys.modules
"""
mod = ApiModule(pkgname, exportdefs) mod = ApiModule(pkgname, exportdefs)
for name, value in mod.__dict__.items(): oldmod = sys.modules[pkgname]
if name[:2] != "__" or name == "__all__": mod.__file__ = getattr(oldmod, '__file__', None)
setattr(pkgmodule, name, value) mod.__version__ = getattr(oldmod, '__version__', None)
mod.__path__ = getattr(oldmod, '__path__', None)
sys.modules[pkgname] = mod
def importobj(importspec): def importobj(importspec):
""" return object specified by importspec.""" """ return object specified by importspec."""
@ -29,26 +32,24 @@ class ApiModule(ModuleType):
self.__name__ = name self.__name__ = name
self.__all__ = list(importspec) self.__all__ = list(importspec)
self.__map__ = {} self.__map__ = {}
if parent:
fullname = parent.__fullname__ + "." + name
setattr(parent, name, self)
else:
fullname = name
self.__fullname__ = fullname
for name, importspec in importspec.items(): for name, importspec in importspec.items():
if isinstance(importspec, dict): if isinstance(importspec, dict):
apimod = ApiModule(name, importspec, parent=self) package = '%s.%s'%(self.__name__, name)
sys.modules[apimod.__fullname__] = apimod apimod = ApiModule(package, importspec, parent=self)
sys.modules[package] = apimod
setattr(self, name, apimod)
else: else:
if not importspec.count(":") == 1: if not importspec.count(":") == 1:
raise ValueError("invalid importspec %r" % (importspec,)) raise ValueError("invalid importspec %r" % (importspec,))
if name == '__doc__': if name == '__doc__':
self.__doc__ = importobj(importspec) self.__doc__ = importobj(importspec)
else: else:
if importspec[0] == '.':
importspec = self.__name__ + importspec
self.__map__[name] = importspec self.__map__[name] = importspec
def __repr__(self): def __repr__(self):
return '<ApiModule %r>' % (self.__fullname__,) return '<ApiModule %r>' % (self.__name__,)
def __getattr__(self, name): def __getattr__(self, name):
try: try:

View File

@ -4,7 +4,6 @@ Collectors and test Items form a tree
that is usually built iteratively. that is usually built iteratively.
""" """
import py import py
pydir = py.path.local(py._py.__file__).dirpath()
def configproperty(name): def configproperty(name):
def fget(self): def fget(self):
@ -336,7 +335,7 @@ class Collector(Node):
path = self.fspath path = self.fspath
ntraceback = traceback.cut(path=self.fspath) ntraceback = traceback.cut(path=self.fspath)
if ntraceback == traceback: if ntraceback == traceback:
ntraceback = ntraceback.cut(excludepath=pydir) ntraceback = ntraceback.cut(excludepath=py._impldir)
traceback = ntraceback.filter() traceback = ntraceback.filter()
return traceback return traceback

View File

@ -261,8 +261,8 @@ class Config(object):
conftestroots = config.getconftest_pathlist("rsyncdirs") conftestroots = config.getconftest_pathlist("rsyncdirs")
if conftestroots: if conftestroots:
roots.extend(conftestroots) roots.extend(conftestroots)
pydirs = [py.path.local(x).dirpath() pydirs = [py.path.local(py.__file__).dirpath(),
for x in (py.__file__, py._py.__file__)] py._impldir]
roots = [py.path.local(root) for root in roots] roots = [py.path.local(root) for root in roots]
for root in roots: for root in roots:
if not root.check(): if not root.check():

View File

@ -175,7 +175,7 @@ class ReSTSyntaxTest(py.test.collect.Item):
'to the py package') % (text,) 'to the py package') % (text,)
relpath = '/'.join(text.split('/')[1:]) relpath = '/'.join(text.split('/')[1:])
if check: if check:
pkgroot = py.path.local(py._py.__file__).dirpath() pkgroot = py._impldir
abspath = pkgroot.join(relpath) abspath = pkgroot.join(relpath)
assert pkgroot.join(relpath).check(), ( assert pkgroot.join(relpath).check(), (
'problem with linkrole :source:`%s`: ' 'problem with linkrole :source:`%s`: '

View File

@ -19,7 +19,6 @@ a tree of collectors and test items that this modules provides::
import py import py
import inspect import inspect
from _py.test.collect import configproperty, warnoldcollect from _py.test.collect import configproperty, warnoldcollect
pydir = py.path.local(py._py.__file__).dirpath()
from _py.test import funcargs from _py.test import funcargs
class PyobjMixin(object): class PyobjMixin(object):
@ -258,7 +257,7 @@ class FunctionMixin(PyobjMixin):
if ntraceback == traceback: if ntraceback == traceback:
ntraceback = ntraceback.cut(path=path) ntraceback = ntraceback.cut(path=path)
if ntraceback == traceback: if ntraceback == traceback:
ntraceback = ntraceback.cut(excludepath=pydir) ntraceback = ntraceback.cut(excludepath=py._impldir)
traceback = ntraceback.filter() traceback = ntraceback.filter()
return traceback return traceback

View File

@ -26,6 +26,9 @@ _py.apipkg.initpkg(__name__, dict(
# access to all posix errno's as classes # access to all posix errno's as classes
error = '_py.error:error', error = '_py.error:error',
_impldir = '_py._metainfo:impldir',
version = 'py:__version__', # backward compatibility
_com = { _com = {
'Registry': '_py._com:Registry', 'Registry': '_py._com:Registry',
'MultiCall': '_py._com:MultiCall', 'MultiCall': '_py._com:MultiCall',

View File

@ -112,7 +112,7 @@ class TestTraceback_f_g_h:
def test_traceback_cut_excludepath(self, testdir): def test_traceback_cut_excludepath(self, testdir):
p = testdir.makepyfile("def f(): raise ValueError") p = testdir.makepyfile("def f(): raise ValueError")
excinfo = py.test.raises(ValueError, "p.pyimport().f()") excinfo = py.test.raises(ValueError, "p.pyimport().f()")
basedir = py.path.local(py._py.__file__).dirpath() basedir = py._impldir
newtraceback = excinfo.traceback.cut(excludepath=basedir) newtraceback = excinfo.traceback.cut(excludepath=basedir)
assert len(newtraceback) == 1 assert len(newtraceback) == 1
assert newtraceback[0].frame.code.path == p assert newtraceback[0].frame.code.path == p

View File

@ -1,7 +1,7 @@
import py import py
pytest_plugins = "pytester" pytest_plugins = "pytester"
plugindir = py.path.local(py._py.__file__).dirpath('test', 'plugin') plugindir = py._impldir.join('test', 'plugin')
from _py.test.defaultconftest import pytest_plugins as default_plugins from _py.test.defaultconftest import pytest_plugins as default_plugins
def pytest_collect_file(path, parent): def pytest_collect_file(path, parent):

View File

@ -7,6 +7,7 @@ def checksubpackage(name):
if hasattr(obj, '__map__'): # isinstance(obj, Module): if hasattr(obj, '__map__'): # isinstance(obj, Module):
keys = dir(obj) keys = dir(obj)
assert len(keys) > 0 assert len(keys) > 0
print (obj.__map__)
assert getattr(obj, '__map__') == {} assert getattr(obj, '__map__') == {}
def test_dir(): def test_dir():