[pypy-commit] pypy py3k: Implement imp.cache_from_source()
amauryfa
noreply at buildbot.pypy.org
Sun Nov 6 20:59:21 CET 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r48844:b12056207f0c
Date: 2011-10-26 19:34 +0200
http://bitbucket.org/pypy/pypy/changeset/b12056207f0c/
Log: Implement imp.cache_from_source()
diff --git a/pypy/module/imp/__init__.py b/pypy/module/imp/__init__.py
--- a/pypy/module/imp/__init__.py
+++ b/pypy/module/imp/__init__.py
@@ -34,6 +34,8 @@
'lock_held': 'interp_imp.lock_held',
'acquire_lock': 'interp_imp.acquire_lock',
'release_lock': 'interp_imp.release_lock',
+
+ 'cache_from_source': 'interp_imp.cache_from_source',
}
appleveldefs = {
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -852,6 +852,9 @@
space.wrap(space.builtin))
code_w.exec_code(space, w_dict, w_dict)
+def make_compiled_pathname(pathname):
+ "Given the path to a .py file, return the path to its .pyc file."
+ return pathname + 'c'
@jit.dont_look_inside
def load_source_module(space, w_modulename, w_mod, pathname, source,
@@ -863,7 +866,7 @@
w = space.wrap
if space.config.objspace.usepycfiles:
- cpathname = pathname + 'c'
+ cpathname = make_compiled_pathname(pathname)
src_stat = os.stat(pathname)
mtime = int(src_stat[stat.ST_MTIME])
mode = src_stat[stat.ST_MODE]
diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py
--- a/pypy/module/imp/interp_imp.py
+++ b/pypy/module/imp/interp_imp.py
@@ -180,3 +180,7 @@
def reinit_lock(space):
if space.config.objspace.usemodules.thread:
importing.getimportlock(space).reinit_lock()
+
+ at unwrap_spec(pathname=str)
+def cache_from_source(space, pathname):
+ return space.wrap(importing.make_compiled_pathname(pathname))
diff --git a/pypy/module/imp/test/test_import.py b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -137,7 +137,8 @@
def _teardown(space, w_saved_modules):
space.appexec([w_saved_modules], """
- ((saved_path, saved_modules)):
+ (path_and_modules):
+ saved_path, saved_modules = path_and_modules
import sys
sys.path[:] = saved_path
sys.modules.clear()
@@ -571,6 +572,10 @@
else:
assert False, 'should not work'
+ def test_cache_from_source(self):
+ import imp
+ assert imp.cache_from_source('a/b/c.py') == 'a/b/c.pyc'
+
class TestAbi:
def test_abi_tag(self):
space1 = gettestobjspace(soabi='TEST')
More information about the pypy-commit
mailing list