rewrote the initpkg mechanism and moved py lib implementation files to

_py/...  with py/__init__.py containing pointers into them

The new apipkg is only around 70 lines of code and allows
us to get rid of the infamous "py.__." by regular non-magical
"_py." imports. It is also available as a separately installable
package, see http://bitbucket.org/hpk42/apipkg

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-10-03 01:47:39 +02:00
parent db1ff48996
commit 5791c06bf2
171 changed files with 447 additions and 844 deletions

View File

@ -4,7 +4,9 @@ py lib plugins and plugin call management
import py
import inspect
__all__ = ['Registry', 'MultiCall', 'comregistry', 'HookRelay']
class MultiCall:
""" execute a call into multiple python functions/methods. """

View File

@ -9,7 +9,7 @@ prepended."""
import sys, os
import py
from py.__.io.terminalwriter import ansi_print, terminal_width
from _py.io.terminalwriter import ansi_print, terminal_width
import re
def rec(p):

View File

@ -35,8 +35,8 @@ parser.add_option("--debug", action="store_true", dest="debug",
def main():
try:
from py.__.rest import directive, resthtml
from py.__.rest.latex import process_rest_file, process_configfile
from _py.rest import directive, resthtml
from _py.rest.latex import process_rest_file, process_configfile
except ImportError:
e = sys.exc_info()[1]
print(str(e))

View File

@ -7,7 +7,7 @@ import sys
import ast
import py
from py.__.code.assertion import _format_explanation, BuiltinAssertionError
from _py.code.assertion import _format_explanation, BuiltinAssertionError
class Failure(Exception):

View File

@ -1,7 +1,7 @@
import py
import sys, inspect
from compiler import parse, ast, pycodegen
from py.__.code.assertion import BuiltinAssertionError, _format_explanation
from _py.code.assertion import BuiltinAssertionError, _format_explanation
passthroughex = (KeyboardInterrupt, SystemExit, MemoryError)

View File

@ -38,9 +38,9 @@ def _format_explanation(explanation):
if sys.version_info >= (2, 6):
from py.__.code._assertionnew import interpret
from _py.code._assertionnew import interpret
else:
from py.__.code._assertionold import interpret
from _py.code._assertionold import interpret
class AssertionError(BuiltinAssertionError):

View File

@ -84,7 +84,7 @@ class Code(object):
def fullsource(self):
""" return a py.code.Source object for the full source file of the code
"""
from py.__.code import source
from _py.code import source
full, _ = source.findsource(self.raw)
return full
fullsource = property(fullsource, None, None,
@ -196,7 +196,7 @@ class TracebackEntry(object):
"""Reinterpret the failing statement and returns a detailed information
about what operations are performed."""
if self.exprinfo is None:
from py.__.code import assertion
from _py.code import assertion
source = str(self.statement).strip()
x = assertion.interpret(source, self.frame, should_fail=True)
if not isinstance(x, str):
@ -738,7 +738,7 @@ oldbuiltins = {}
def patch_builtins(assertion=True, compile=True):
""" put compile and AssertionError builtins to Python's builtins. """
if assertion:
from py.__.code import assertion
from _py.code import assertion
l = oldbuiltins.setdefault('AssertionError', [])
l.append(py.builtin.builtins.AssertionError)
py.builtin.builtins.AssertionError = assertion.AssertionError

View File

@ -1,5 +1,5 @@
import py, itertools
from py.__.path import common
from _py.path import common
COUNTER = itertools.count()

View File

@ -1,10 +1,9 @@
"""
local path implementation.
"""
from __future__ import generators
import sys, os, stat, re, atexit
import py
from py.__.path import common
from _py.path import common
iswin32 = sys.platform == "win32"
@ -508,16 +507,9 @@ class LocalPath(FSBase):
if ensuresyspath:
self._prependsyspath(pkgpath.dirpath())
pkg = __import__(pkgpath.basename, None, None, [])
if hasattr(pkg, '__pkg__'):
modname = pkg.__pkg__.getimportname(self)
assert modname is not None, "package %s doesn't know %s" % (
pkg.__name__, self)
else:
names = self.new(ext='').relto(pkgpath.dirpath())
names = names.split(self.sep)
modname = ".".join(names)
names = self.new(ext='').relto(pkgpath.dirpath())
names = names.split(self.sep)
modname = ".".join(names)
else:
# no package scope, still make it possible
if ensuresyspath:

View File

@ -7,9 +7,9 @@ but might also interact well with earlier versions.
import os, sys, time, re
import py
from py import path, process
from py.__.path import common
from py.__.path import svnwc as svncommon
from py.__.path.cacheutil import BuildcostAccessCache, AgingCache
from _py.path import common
from _py.path import svnwc as svncommon
from _py.path.cacheutil import BuildcostAccessCache, AgingCache
DEBUG=False

View File

@ -8,7 +8,7 @@ svn-Command based Implementation of a Subversion WorkingCopy Path.
import os, sys, time, re, calendar
import py
import subprocess
from py.__.path import common
from _py.path import common
#-----------------------------------------------------------
# Caching latest repository revision and repo-paths

View File

@ -1,6 +1,6 @@
import py
from py.__.process.cmdexec import ExecutionFailed
from _py.process.cmdexec import ExecutionFailed
# utility functions to convert between various formats
format_to_dotargument = {"png": "png",

View File

@ -1,7 +1,7 @@
# XXX this file is messy since it tries to deal with several docutils versions
import py
from py.__.rest.convert import convert_dot, latexformula2png
from _py.rest.convert import convert_dot, latexformula2png
import sys
import docutils

View File

@ -1,6 +1,6 @@
import py
from py.__.process.cmdexec import ExecutionFailed
from _py.process.cmdexec import ExecutionFailed
font_to_package = {"times": "times", "helvetica": "times",
"new century schoolbock": "newcent", "avant garde": "newcent",

View File

@ -10,7 +10,7 @@ else:
pass
def convert_rest_html(source, source_path, stylesheet=None, encoding='latin1'):
from py.__.rest import directive
from _py.rest import directive
""" return html latin1-encoded document for the given input.
source a ReST-string
sourcepath where to look for includes (basically)

View File

@ -4,7 +4,7 @@ Collectors and test Items form a tree
that is usually built iteratively.
"""
import py
pydir = py.path.local(py.__file__).dirpath()
pydir = py.path.local(py._py.__file__).dirpath()
def configproperty(name):
def fget(self):

View File

@ -1,7 +1,7 @@
import py, os
from py.__.test.conftesthandle import Conftest
from _py.test.conftesthandle import Conftest
from py.__.test import parseopt
from _py.test import parseopt
def ensuretemp(string, dir=1):
""" return temporary directory path with
@ -221,7 +221,7 @@ class Config(object):
""" return an initialized session object. """
cls = self._sessionclass
if cls is None:
from py.__.test.session import Session
from _py.test.session import Session
cls = Session
session = cls(self)
self.trace("instantiated session %r" % session)
@ -256,24 +256,22 @@ class Config(object):
return [execnet.XSpec(x) for x in xspeclist]
def getrsyncdirs(self):
config = self
config = self
roots = config.option.rsyncdir
conftestroots = config.getconftest_pathlist("rsyncdirs")
if conftestroots:
roots.extend(conftestroots)
pydir = py.path.local(py.__file__).dirpath()
pydirs = [py.path.local(x).dirpath()
for x in (py.__file__, py._py.__file__)]
roots = [py.path.local(root) for root in roots]
for root in roots:
if not root.check():
raise config.Error("rsyncdir doesn't exist: %r" %(root,))
if pydir is not None and root.basename == "py":
if root != pydir:
raise config.Error("root %r conflicts with imported %r" %(root, pydir))
pydir = None
if pydir is not None:
roots.append(pydir)
return roots
if pydirs is not None and root.basename in ("py", "_py"):
pydirs.remove(root) # otherwise it's a conflict
roots.extend(pydirs)
return roots
#
# helpers
#

View File

@ -5,9 +5,9 @@
"""
import py
from py.__.test.session import Session
from py.__.test import outcome
from py.__.test.dist.nodemanage import NodeManager
from _py.test.session import Session
from _py.test import outcome
from _py.test.dist.nodemanage import NodeManager
queue = py.builtin._tryimport('queue', 'Queue')
debug_file = None # open('/tmp/loop.log', 'w')

View File

@ -1,7 +1,7 @@
import py
import sys, os
from py.__.test.dist.txnode import TXNode
from py.__.test.dist.gwmanage import GatewayManager
from _py.test.dist.txnode import TXNode
from _py.test.dist.gwmanage import GatewayManager
class NodeManager(object):

View File

@ -2,7 +2,7 @@
Manage setup, running and local representation of remote nodes/processes.
"""
import py
from py.__.test.dist.mypickle import PickleChannel
from _py.test.dist.mypickle import PickleChannel
class TXNode(object):
""" Represents a Test Execution environment in the controlling process.
@ -84,8 +84,8 @@ def install_slave(gateway, config):
channel = gateway.remote_exec(source="""
import os, sys
sys.path.insert(0, os.getcwd())
from py.__.test.dist.mypickle import PickleChannel
from py.__.test.dist.txnode import SlaveNode
from _py.test.dist.mypickle import PickleChannel
from _py.test.dist.txnode import SlaveNode
channel = PickleChannel(channel)
slavenode = SlaveNode(channel)
slavenode.run()

View File

@ -10,9 +10,9 @@
import py
import sys
import execnet
from py.__.test.session import Session
from py.__.test.dist.mypickle import PickleChannel
from py.__.test.looponfail import util
from _py.test.session import Session
from _py.test.dist.mypickle import PickleChannel
from _py.test.looponfail import util
class LooponfailingSession(Session):
def __init__(self, config):
@ -68,8 +68,8 @@ class RemoteControl(object):
finally:
old.chdir()
channel = self.gateway.remote_exec(source="""
from py.__.test.dist.mypickle import PickleChannel
from py.__.test.looponfail.remote import slave_runsession
from _py.test.dist.mypickle import PickleChannel
from _py.test.looponfail.remote import slave_runsession
outchannel = channel.gateway.newchannel()
channel.send(outchannel)
channel = PickleChannel(channel)

View File

@ -120,12 +120,12 @@ def fixoptions(config):
def setsession(config):
val = config.getvalue
if val("collectonly"):
from py.__.test.session import Session
from _py.test.session import Session
config.setsessionclass(Session)
elif execnet:
if val("looponfail"):
from py.__.test.looponfail.remote import LooponfailingSession
from _py.test.looponfail.remote import LooponfailingSession
config.setsessionclass(LooponfailingSession)
elif val("dist") != "no":
from py.__.test.dist.dsession import DSession
from _py.test.dist.dsession import DSession
config.setsessionclass(DSession)

View File

@ -14,7 +14,7 @@ as well.
"""
import py
from py.__.code.code import TerminalRepr, ReprFileLocation
from _py.code.code import TerminalRepr, ReprFileLocation
import doctest
def pytest_addoption(parser):

View File

@ -3,7 +3,7 @@ interactive debugging with the Python Debugger.
"""
import py
import pdb, sys, linecache
from py.__.test.outcome import Skipped
from _py.test.outcome import Skipped
try:
import execnet
except ImportError:

View File

@ -5,8 +5,8 @@ funcargs and support code for testing py.test's own functionality.
import py
import sys, os
import inspect
from py.__.test.config import Config as pytestConfig
from py.__.test.plugin import hookspec
from _py.test.config import Config as pytestConfig
from _py.test.plugin import hookspec
from py.builtin import print_
pytest_plugins = '_pytest'

View File

@ -87,7 +87,7 @@ class ReSTSyntaxTest(py.test.collect.Item):
py.test.fail("docutils processing failed, see captured stderr")
def register_linkrole(self):
from py.__.rest import directive
from _py.rest import directive
directive.register_linkrole('api', self.resolve_linkrole)
directive.register_linkrole('source', self.resolve_linkrole)

View File

@ -3,7 +3,7 @@ collect and run test items and create reports.
"""
import py
from py.__.test.outcome import Skipped
from _py.test.outcome import Skipped
#
# pytest plugin hooks
@ -118,7 +118,7 @@ def forked_run_report(item):
# for now, we run setup/teardown in the subprocess
# XXX optionally allow sharing of setup/teardown
EXITSTATUS_TESTEXIT = 4
from py.__.test.dist.mypickle import ImmutablePickler
from _py.test.dist.mypickle import ImmutablePickler
ipickle = ImmutablePickler(uneven=0)
ipickle.selfmemoize(item.config)
# XXX workaround the issue that 2.6 cannot pickle

Some files were not shown because too many files have changed in this diff Show More