Commit 21756bd3 authored by Kirill Smelkov's avatar Kirill Smelkov

gpython: Rework pymain interface to accept python exe as argv[0]

In other words pymain now requires to be passed in full argv when
called. We will need exe=argv[0] in a followup patch to be able to
reexecute underlying python interpreter when given options like -O, -S,
etc...

This is change in behaviour and in general must come with changing
pymain name - e.g. to pymain2 - so that old pymain continues to work as
before. However since there are not so many known pymain users, we can
probably do this change in place since we'll care ourselves about all
those users:

- [python-interpreter] in SlapOS:
  https://lab.nexedi.com/nexedi/slapos/blob/46ed2afe/component/pygolang/buildout.cfg#L30-53

- pyruntraced in Go123:
  https://lab.nexedi.com/kirr/go123/blob/96046edf/tracing/cmd/pyruntraced

- zobjtrace in ZODB:
  https://lab.nexedi.com/kirr/ZODB/blob/07c21671/zobjtrace

So I hope it is ok.
parent 26058b5b
...@@ -46,10 +46,11 @@ _pyopt_long = ('version',) ...@@ -46,10 +46,11 @@ _pyopt_long = ('version',)
# pymain mimics `python ...` # pymain mimics `python ...`
# #
# argv is what comes via `...` without first [0] for python. # argv is full argument vector including first [0] for path to main program itself.
# init, if provided, is called after options are parsed, but before interpreter start. # init, if provided, is called after options are parsed, but before interpreter start.
def pymain(argv, init=None): def pymain(argv, init=None):
import sys import sys
argv = argv[1:]
from os.path import dirname, realpath from os.path import dirname, realpath
run = None # function to run according to -c/-m/file/interactive run = None # function to run according to -c/-m/file/interactive
...@@ -317,7 +318,7 @@ def main(): ...@@ -317,7 +318,7 @@ def main():
if opt in ('-c', '-m'): if opt in ('-c', '-m'):
break break
argv = argv_ + igetopt.argv argv = [exe] + argv_ + igetopt.argv
# init initializes according to selected runtime # init initializes according to selected runtime
# it is called after options are parsed and sys.path is setup correspondingly. # it is called after options are parsed and sys.path is setup correspondingly.
......
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