Commit cfdc9b83 authored by Jérome Perrin's avatar Jérome Perrin

component/pygolang: minimal -O support in [python-interpreter]

When use this interpreter to run buildout, buildout will pre-compile eggs with
different level of optimisations, for this it spawns sys.executable with -O
option (see [1]). Since pymain does not support -O argument and python only
support changing optimization level at startup, we can not easily handle -O
argument, execpt by re-executing ourselves with PYTHONOPTIMIZE environment
variable, which has same effect than setting -O flag

1: https://lab.nexedi.com/nexedi/slapos.buildout/blob/488b2dfd3088cba7b322827c904fe1f93fba73e6/src/zc/buildout/easy_install.py#L1716-1722
parent 3a1e5628
......@@ -37,6 +37,14 @@ interpreter = python
# interpreter code that buildout generates cannot process `-m pytest --<pytest-option>`
# -> use pymain from gpython to workaround that.
initialization =
# minimal support for -O argument.
if '-O' in sys.argv:
import os
with open(sys.argv[0]) as f:
executable = f.readlines()[0][2:-1]
sys.argv.remove('-O')
os.execve(executable, sys.argv, dict(os.environ, PYTHONOPTIMIZE='1'))
# set sys.executable to self, so that subprocess and friends go through us
# and this way spawn children with correct sys.path where all eggs that
# parent have are present. TODO consider migrating this into pymain
......
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