[py-svn] py-trunk commit eac97f2e3174: using apipkg 1.0b2 snapshot version - adjusting/cleaning up some impl-detail accesses
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Tue Oct 27 21:38:32 CET 2009
# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1256675502 -3600
# Node ID eac97f2e317418956e509252f7d6adf6a0bed792
# Parent 726d84814940d464c3fc22f0e8624f9368035695
using apipkg 1.0b2 snapshot version - adjusting/cleaning up some impl-detail accesses
--- a/_py/test/plugin/pytest_restdoc.py
+++ b/_py/test/plugin/pytest_restdoc.py
@@ -175,7 +175,7 @@ class ReSTSyntaxTest(py.test.collect.Ite
'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`: '
--- 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',
--- /dev/null
+++ b/_py/_metainfo.py
@@ -0,0 +1,5 @@
+
+import py
+import _py
+
+impldir = py.path.local(_py.__file__).dirpath()
--- 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 '<ApiModule %r>' % (self.__fullname__,)
+ return '<ApiModule %r>' % (self.__name__,)
def __getattr__(self, name):
try:
--- 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):
--- 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():
--- a/_py/test/pycollect.py
+++ b/_py/test/pycollect.py
@@ -19,7 +19,6 @@ a tree of collectors and test items that
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
--- 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
--- 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
--- 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():
More information about the pytest-commit
mailing list