diff --git a/_py/_metainfo.py b/_py/_metainfo.py new file mode 100644 index 000000000..af91973b9 --- /dev/null +++ b/_py/_metainfo.py @@ -0,0 +1,5 @@ + +import py +import _py + +impldir = py.path.local(_py.__file__).dirpath() diff --git a/_py/apipkg.py b/_py/apipkg.py index 0751719ab..668b48726 100644 --- a/_py/apipkg.py +++ b/_py/apipkg.py @@ -5,18 +5,21 @@ see http://pypi.python.org/pypi/apipkg (c) holger krekel, 2009 - MIT license """ -import os, sys +import sys from types import ModuleType -__version__ = "1.0b1" +__version__ = "1.0b2" def initpkg(pkgname, exportdefs): - """ initialize given package from the export definitions. """ - pkgmodule = sys.modules[pkgname] + """ initialize given package from the export definitions. + replace it in sys.modules + """ mod = ApiModule(pkgname, exportdefs) - for name, value in mod.__dict__.items(): - if name[:2] != "__" or name == "__all__": - setattr(pkgmodule, name, value) + oldmod = sys.modules[pkgname] + mod.__file__ = getattr(oldmod, '__file__', None) + mod.__version__ = getattr(oldmod, '__version__', None) + mod.__path__ = getattr(oldmod, '__path__', None) + sys.modules[pkgname] = mod def importobj(importspec): """ return object specified by importspec.""" @@ -29,26 +32,24 @@ class ApiModule(ModuleType): self.__name__ = name self.__all__ = list(importspec) self.__map__ = {} - if parent: - fullname = parent.__fullname__ + "." + name - setattr(parent, name, self) - else: - fullname = name - self.__fullname__ = fullname for name, importspec in importspec.items(): if isinstance(importspec, dict): - apimod = ApiModule(name, importspec, parent=self) - sys.modules[apimod.__fullname__] = apimod + package = '%s.%s'%(self.__name__, name) + apimod = ApiModule(package, importspec, parent=self) + sys.modules[package] = apimod + setattr(self, name, apimod) else: if not importspec.count(":") == 1: raise ValueError("invalid importspec %r" % (importspec,)) if name == '__doc__': self.__doc__ = importobj(importspec) else: + if importspec[0] == '.': + importspec = self.__name__ + importspec self.__map__[name] = importspec def __repr__(self): - return '' % (self.__fullname__,) + return '' % (self.__name__,) def __getattr__(self, name): try: diff --git a/_py/test/collect.py b/_py/test/collect.py index cd96e6714..411a9719b 100644 --- a/_py/test/collect.py +++ b/_py/test/collect.py @@ -4,7 +4,6 @@ Collectors and test Items form a tree that is usually built iteratively. """ import py -pydir = py.path.local(py._py.__file__).dirpath() def configproperty(name): def fget(self): @@ -336,7 +335,7 @@ class Collector(Node): path = self.fspath ntraceback = traceback.cut(path=self.fspath) if ntraceback == traceback: - ntraceback = ntraceback.cut(excludepath=pydir) + ntraceback = ntraceback.cut(excludepath=py._impldir) traceback = ntraceback.filter() return traceback diff --git a/_py/test/config.py b/_py/test/config.py index e5b2dd2be..e1c132988 100644 --- a/_py/test/config.py +++ b/_py/test/config.py @@ -261,8 +261,8 @@ class Config(object): conftestroots = config.getconftest_pathlist("rsyncdirs") if conftestroots: roots.extend(conftestroots) - pydirs = [py.path.local(x).dirpath() - for x in (py.__file__, py._py.__file__)] + pydirs = [py.path.local(py.__file__).dirpath(), + py._impldir] roots = [py.path.local(root) for root in roots] for root in roots: if not root.check(): diff --git a/_py/test/plugin/pytest_restdoc.py b/_py/test/plugin/pytest_restdoc.py index 296ca95e7..12e78a5ea 100644 --- a/_py/test/plugin/pytest_restdoc.py +++ b/_py/test/plugin/pytest_restdoc.py @@ -175,7 +175,7 @@ class ReSTSyntaxTest(py.test.collect.Item): 'to the py package') % (text,) relpath = '/'.join(text.split('/')[1:]) if check: - pkgroot = py.path.local(py._py.__file__).dirpath() + pkgroot = py._impldir abspath = pkgroot.join(relpath) assert pkgroot.join(relpath).check(), ( 'problem with linkrole :source:`%s`: ' diff --git a/_py/test/pycollect.py b/_py/test/pycollect.py index f2fbf324a..bb0cbed7a 100644 --- a/_py/test/pycollect.py +++ b/_py/test/pycollect.py @@ -19,7 +19,6 @@ a tree of collectors and test items that this modules provides:: import py import inspect from _py.test.collect import configproperty, warnoldcollect -pydir = py.path.local(py._py.__file__).dirpath() from _py.test import funcargs class PyobjMixin(object): @@ -258,7 +257,7 @@ class FunctionMixin(PyobjMixin): if ntraceback == traceback: ntraceback = ntraceback.cut(path=path) if ntraceback == traceback: - ntraceback = ntraceback.cut(excludepath=pydir) + ntraceback = ntraceback.cut(excludepath=py._impldir) traceback = ntraceback.filter() return traceback diff --git a/py/__init__.py b/py/__init__.py index 56e798ed9..0156157ea 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -26,6 +26,9 @@ _py.apipkg.initpkg(__name__, dict( # access to all posix errno's as classes error = '_py.error:error', + _impldir = '_py._metainfo:impldir', + version = 'py:__version__', # backward compatibility + _com = { 'Registry': '_py._com:Registry', 'MultiCall': '_py._com:MultiCall', diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py index 1afdb0463..8b249d1f5 100644 --- a/testing/code/test_excinfo.py +++ b/testing/code/test_excinfo.py @@ -112,7 +112,7 @@ class TestTraceback_f_g_h: def test_traceback_cut_excludepath(self, testdir): p = testdir.makepyfile("def f(): raise ValueError") 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) assert len(newtraceback) == 1 assert newtraceback[0].frame.code.path == p diff --git a/testing/pytest/plugin/conftest.py b/testing/pytest/plugin/conftest.py index f19852f77..0a4a26595 100644 --- a/testing/pytest/plugin/conftest.py +++ b/testing/pytest/plugin/conftest.py @@ -1,7 +1,7 @@ import py 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 def pytest_collect_file(path, parent): diff --git a/testing/test_py_imports.py b/testing/test_py_imports.py index bdf4972b4..dd591e65e 100644 --- a/testing/test_py_imports.py +++ b/testing/test_py_imports.py @@ -7,6 +7,7 @@ def checksubpackage(name): if hasattr(obj, '__map__'): # isinstance(obj, Module): keys = dir(obj) assert len(keys) > 0 + print (obj.__map__) assert getattr(obj, '__map__') == {} def test_dir():