Nov-16-2021, 09:04 AM
(This post was last modified: Nov-16-2021, 09:16 AM by Gribouillis.)
I'm unable to answer the title of this thread, that is a question for the Python core dev team, but you could try the following workaround:
instead of execve-ing python with the arguments that you showed above, you would execve
instead of execve-ing python with the arguments that you showed above, you would execve
python wrapper2.py <any args you want>
. Then wrapper2.py would do something like# wrapper2.py import importlib.util import sys modname = ... # should extract 'blurble.libexec.util_one' from sys.argv spec = importlib.util.find_spec(modname) assert(spec.origin.endswith('.py')) # should be '/path/to/blurble/libexec/util_one.py' with open(spec.origin) as ifh: code = compile(ifh.read(), spec.origin, 'exec') sys.argv[:] = ... # do anything you want with sys.argv mainmod = sys.modules['__main__'] mainmod.__file__ = spec.origin exec(code, mainmod.__dict__) # run the desired program in the __main__ module.Of course, you would hide all this in a function's body (or an external module) to avoid cluttering the __main__ module's namespace.