[svn r38203] rename getpymodule/getpycodeobj to "_" methods
(which can build C modules on the fly) it's not clear they are still useful this way and they are easy to confuse with pyimport() --HG-- branch : trunk
This commit is contained in:
parent
0a79e56b40
commit
499d60c8ab
|
@ -7,4 +7,4 @@ else:
|
|||
import py
|
||||
gdir = py.path.local(py.__file__).dirpath()
|
||||
path = gdir.join('c-extension', 'greenlet', 'greenlet.c')
|
||||
greenlet = path.getpymodule().greenlet
|
||||
greenlet = path._getpymodule().greenlet
|
||||
|
|
|
@ -370,14 +370,14 @@ newline will be removed from the end of each line. """
|
|||
self.copy(target)
|
||||
self.remove()
|
||||
|
||||
def getpymodule(self):
|
||||
def _getpymodule(self):
|
||||
"""resolve this path to a module python object. """
|
||||
modname = str(self)
|
||||
modname = modname.replace('.', self.sep)
|
||||
try:
|
||||
return sys.modules[modname]
|
||||
except KeyError:
|
||||
co = self.getpycodeobj()
|
||||
co = self._getpycodeobj()
|
||||
mod = py.std.new.module(modname)
|
||||
mod.__file__ = PathStr(self)
|
||||
if self.basename == '__init__.py':
|
||||
|
@ -390,7 +390,7 @@ newline will be removed from the end of each line. """
|
|||
raise
|
||||
return mod
|
||||
|
||||
def getpycodeobj(self):
|
||||
def _getpycodeobj(self):
|
||||
""" read the path and compile it to a py.code.Code object. """
|
||||
s = self.read('rU')
|
||||
# XXX str(self) should show up somewhere in the code's filename
|
||||
|
@ -421,7 +421,7 @@ def relativeimport(p, name, parent=None):
|
|||
p = p.new(basename=name).join('__init__.py')
|
||||
if not p.check():
|
||||
return None # not found
|
||||
submodule = p.getpymodule()
|
||||
submodule = p._getpymodule()
|
||||
if parent is not None:
|
||||
setattr(parent, name, submodule)
|
||||
modules.append(submodule)
|
||||
|
|
|
@ -426,15 +426,15 @@ class LocalPath(common.FSPathBase, PlatformMixin):
|
|||
raise
|
||||
return mod
|
||||
|
||||
def getpymodule(self):
|
||||
def _getpymodule(self):
|
||||
"""resolve this path to a module python object. """
|
||||
if self.ext != '.c':
|
||||
return super(LocalPath, self).getpymodule()
|
||||
return super(LocalPath, self)._getpymodule()
|
||||
from py.__.misc.buildcmodule import make_module_from_c
|
||||
mod = make_module_from_c(self)
|
||||
return mod
|
||||
|
||||
def getpycodeobj(self):
|
||||
def _getpycodeobj(self):
|
||||
""" read the path and compile it to a code object. """
|
||||
dotpy = self.check(ext='.py')
|
||||
if dotpy:
|
||||
|
|
|
@ -216,8 +216,8 @@ class CommonFSTests(common.CommonPathTests):
|
|||
assert dest.join('otherfile').check(file=1)
|
||||
assert not source.join('sampledir').check()
|
||||
|
||||
def test_getpymodule(self):
|
||||
obj = self.root.join('execfile').getpymodule()
|
||||
def test__getpymodule(self):
|
||||
obj = self.root.join('execfile')._getpymodule()
|
||||
assert obj.x == 42
|
||||
|
||||
def test_not_has_resolve(self):
|
||||
|
@ -225,22 +225,22 @@ class CommonFSTests(common.CommonPathTests):
|
|||
# py.path.extpy
|
||||
assert not hasattr(self.root, 'resolve')
|
||||
|
||||
def test_getpymodule_a(self):
|
||||
def test__getpymodule_a(self):
|
||||
otherdir = self.root.join('otherdir')
|
||||
mod = otherdir.join('a.py').getpymodule()
|
||||
mod = otherdir.join('a.py')._getpymodule()
|
||||
assert mod.result == "got it"
|
||||
|
||||
def test_getpymodule_b(self):
|
||||
def test__getpymodule_b(self):
|
||||
otherdir = self.root.join('otherdir')
|
||||
mod = otherdir.join('b.py').getpymodule()
|
||||
mod = otherdir.join('b.py')._getpymodule()
|
||||
assert mod.stuff == "got it"
|
||||
|
||||
def test_getpymodule_c(self):
|
||||
def test__getpymodule_c(self):
|
||||
otherdir = self.root.join('otherdir')
|
||||
mod = otherdir.join('c.py').getpymodule()
|
||||
mod = otherdir.join('c.py')._getpymodule()
|
||||
assert mod.value == "got it"
|
||||
|
||||
def test_getpymodule_d(self):
|
||||
def test__getpymodule_d(self):
|
||||
otherdir = self.root.join('otherdir')
|
||||
mod = otherdir.join('d.py').getpymodule()
|
||||
mod = otherdir.join('d.py')._getpymodule()
|
||||
assert mod.value2 == "got it"
|
||||
|
|
Loading…
Reference in New Issue