[pypy-commit] pypy verbose-imports: Log things if verbose flags are supplied

william_ml_leslie pypy.commits at gmail.com
Tue Apr 26 07:35:40 EDT 2016


Author: William ML Leslie <william.leslie.ttg at gmail.com>
Branch: verbose-imports
Changeset: r83902:7a2a835311f1
Date: 2016-04-26 21:28 +1000
http://bitbucket.org/pypy/pypy/changeset/7a2a835311f1/

Log:	Log things if verbose flags are supplied

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
@@ -55,6 +55,13 @@
 
     return '.' + soabi + SO
 
+def log_pyverbose(space, level, message):
+    w_flags = space.sys.get('flags')
+    w_verbose = space.getattr(w_flags, 'verbose')
+    if space.int_w(w_verbose) >= level:
+        w_stderr = space.sys.get('stderr')
+        space.call_method(w_stderr, "write", space.wrap(message))
+
 def file_exists(path):
     """Tests whether the given path is an existing regular file."""
     return os.path.isfile(path) and case_ok(path)
@@ -541,6 +548,7 @@
 
             path = space.str0_w(w_pathitem)
             filepart = os.path.join(path, partname)
+            log_pyverbose(space, 2, "# trying %s" % (filepart,))
             if os.path.isdir(filepart) and case_ok(filepart):
                 initfile = os.path.join(filepart, '__init__')
                 modtype, _, _ = find_modtype(space, initfile)
@@ -585,6 +593,8 @@
 
 def load_c_extension(space, filename, modulename):
     from pypy.module.cpyext.api import load_extension_module
+    log_pyverbose(space, 1, "import %s # from %s\n" %
+                  (modulename, pathname))
     load_extension_module(space, filename, modulename)
     # NB. cpyext.api.load_extension_module() can also delegate to _cffi_backend
 
@@ -888,6 +898,11 @@
     """
     w = space.wrap
 
+    space.sys
+
+    log_pyverbose(space, 1, "import %s # from %s\n" %
+                  (space.str_w(w_modulename), pathname))
+
     if space.config.objspace.usepycfiles:
         src_stat = os.fstat(fd)
         cpathname = pathname + 'c'
@@ -1016,6 +1031,9 @@
     Load a module from a compiled file, execute it, and return its
     module object.
     """
+    log_pyverbose(space, 1, "import %s # compiled from %s\n" %
+                  (space.str_w(w_modulename), cpathname))
+
     if magic != get_pyc_magic(space):
         raise oefmt(space.w_ImportError, "Bad magic number in %s", cpathname)
     #print "loading pyc file:", cpathname


More information about the pypy-commit mailing list