Commit e703572c authored by Kirill Smelkov's avatar Kirill Smelkov

gpython: Implement -E

Let's teach gpython and pymain about -E (ignore $PYTHON* environment
variables) because new buildout runs python -E inside. Xavier reports:

    Since slapos was upgraded zc.buildout 3.0.1+slapos004, tests for
    slapos.rebootstrap and slapos.recipe.template fail because buildout now
    installs in develop with pip install --editable instead of python
    setup.py develop and in the process pip runs python -E, e.g.
    https://erp5js.nexedi.net/#/test_result_module/20240912-837A12F7/10

For the implementation use the same approach to reexecute underlying
interpreter with given low-level option as we already did for -O in
8564dfdd (gpython: Implement -O).

/reported-by @xavier_thompson
/cc @jerome
parent 30f06b4a
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2018-2023 Nexedi SA and Contributors. # Copyright (C) 2018-2024 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
...@@ -41,7 +41,7 @@ $GPYTHON_RUNTIME=threads. ...@@ -41,7 +41,7 @@ $GPYTHON_RUNTIME=threads.
from __future__ import print_function, absolute_import from __future__ import print_function, absolute_import
_pyopt = "c:im:OVW:X:" _pyopt = "c:Eim:OVW:X:"
_pyopt_long = ('version',) _pyopt_long = ('version',)
# pymain mimics `python ...` # pymain mimics `python ...`
...@@ -113,6 +113,7 @@ def pymain(argv, init=None): ...@@ -113,6 +113,7 @@ def pymain(argv, init=None):
for (opt, arg) in igetopt: for (opt, arg) in igetopt:
# options that require reexecuting through underlying python with that -<opt> # options that require reexecuting through underlying python with that -<opt>
if opt in ( if opt in (
'-E', # ignore $PYTHON*
'-O', # optimize '-O', # optimize
): ):
reexec_with.append(opt) reexec_with.append(opt)
......
...@@ -315,6 +315,28 @@ def test_pymain_opt(): ...@@ -315,6 +315,28 @@ def test_pymain_opt():
check(["-O", "-O"]) check(["-O", "-O"])
check(["-O", "-O", "-O"]) check(["-O", "-O", "-O"])
# verify that pymain handles -E in exactly the same way as underlying python does.
@gpython_only
def test_pymain_E():
envadj = {'PYTHONOPTIMIZE': '1'}
def sys_flags_optimize(level):
return 'sys.flags.optimize: %s' % level
# without -E $PYTHONOPTIMIZE should be taken into account
def _(gpyoutv, stdpyoutv):
assert sys_flags_optimize(0) not in stdpyoutv
assert sys_flags_optimize(0) not in gpyoutv
assert sys_flags_optimize(1) in stdpyoutv
assert sys_flags_optimize(1) in gpyoutv
check_gpy_vs_py(['testprog/print_opt.py'], _, envadj=envadj, cwd=here)
# with -E not
def _(gpyoutv, stdpyoutv):
assert sys_flags_optimize(0) in stdpyoutv
assert sys_flags_optimize(0) in gpyoutv
assert sys_flags_optimize(1) not in stdpyoutv
assert sys_flags_optimize(1) not in gpyoutv
check_gpy_vs_py(['-E', 'testprog/print_opt.py'], _, envadj=envadj, cwd=here)
# pymain -V/--version # pymain -V/--version
# gpython_only because output differs from !gpython. # gpython_only because output differs from !gpython.
......
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