Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4cd8b5c

Browse files
committed
Print messages about where from modules are imported when -v is given.
1 parent 2bac4d3 commit 4cd8b5c

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

Python/import.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3838
#include "ceval.h"
3939
#include "osdefs.h"
4040

41+
extern int verbose; /* Defined in pythonmain.c */
42+
4143
#ifdef DEBUG
4244
#define D(x) x
4345
#else
@@ -186,6 +188,10 @@ get_module(m, name, m_ret)
186188
D(fprintf(stderr, "dl_loadmod failed\n"));
187189
}
188190
else {
191+
if (verbose)
192+
fprintf(stderr,
193+
"import %s # dynamically loaded from \"%s\"\n",
194+
name, namebuf);
189195
(*p)();
190196
*m_ret = m = dictlookup(modules, name);
191197
if (m == NULL) {
@@ -234,10 +240,25 @@ get_module(m, name, m_ret)
234240
co = (codeobject *)v;
235241
}
236242
fclose(fpc);
243+
if (verbose) {
244+
if (co != NULL)
245+
fprintf(stderr,
246+
"import %s # precompiled from \"%s\"\n",
247+
name, namebuf);
248+
else
249+
fprintf(stderr,
250+
"# invalid precompiled file \"%s\"\n",
251+
namebuf);
252+
}
237253
}
238254
namebuf[namelen] = '\0';
239-
if (co == NULL)
255+
if (co == NULL) {
256+
if (verbose)
257+
fprintf(stderr,
258+
"import %s # from \"%s\"\n",
259+
name, namebuf);
240260
err = parse_file(fp, namebuf, file_input, &n);
261+
}
241262
else
242263
err = E_DONE;
243264
fclose(fp);
@@ -307,7 +328,8 @@ import_module(name)
307328
if ((m = dictlookup(modules, name)) == NULL) {
308329
if (init_builtin(name)) {
309330
if ((m = dictlookup(modules, name)) == NULL)
310-
err_setstr(SystemError, "builtin module missing");
331+
err_setstr(SystemError,
332+
"builtin module missing");
311333
}
312334
else {
313335
m = load_module(name);
@@ -385,6 +407,9 @@ init_builtin(name)
385407
int i;
386408
for (i = 0; inittab[i].name != NULL; i++) {
387409
if (strcmp(name, inittab[i].name) == 0) {
410+
if (verbose)
411+
fprintf(stderr, "import %s # builtin\n",
412+
name);
388413
(*inittab[i].initfunc)();
389414
return 1;
390415
}

0 commit comments

Comments
 (0)