Commit 9434cf08 authored by Kirill Smelkov's avatar Kirill Smelkov

gpython: Implement -v

Tracing import statements might be handy while debugging things
related to initialization. Implementation is simple reexecution of
underlying python with that same -v like we already do for -O, -E and -X.

/reviewed-by @jerome
/reviewed-on nexedi/pygolang!30
parent b7d0f6b2
Pipeline #37037 failed with stage
in 0 seconds
......@@ -41,7 +41,7 @@ $GPYTHON_RUNTIME=threads.
from __future__ import print_function, absolute_import
_pyopt = "c:Eim:OVW:X:"
_pyopt = "c:Eim:OvVW:X:"
_pyopt_long = ('version',)
# pymain mimics `python ...`
......@@ -115,6 +115,7 @@ def pymain(argv, init=None):
if opt in (
'-E', # ignore $PYTHON*
'-O', # optimize
'-v', # trace import statements
'-X', # set implementation-specific option
):
......
......@@ -347,6 +347,29 @@ def test_pymain_X():
check_gpy_vs_py(['-X', 'faulthandler', 'testprog/print_faulthandler.py'], cwd=here)
# pymain -v
@gpython_only
def test_pymain_v():
def nimport(argv, **kw):
argv = argv + ['testdata/hello.py']
kw.setdefault('cwd', here)
ret, out, err = _pyrun(argv, stdout=PIPE, stderr=PIPE, **kw)
assert ret == 0, (out, err)
n = 0
for _ in u(err).splitlines():
if _.startswith("import "):
n += 1
return n
# without -v there must be no "import ..." messages
assert nimport([]) == 0
assert nimport([], pyexe=sys._gpy_underlying_executable) == 0
# with -v there must be many "import ..." messages
assert nimport(['-v']) > 10
assert nimport(['-v'], pyexe=sys._gpy_underlying_executable) > 10
# pymain -V/--version
# gpython_only because output differs from !gpython.
@gpython_only
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment