-
Charles Ferguson authored
Add '-m <module>' to the shell so that a module can be run with long tracebacks in the way that 'python -m <module>' runs it. This takes the approach of module-script-loading, but uses runpy (which is what Python itself uses) to find the module, instead of a copy of the import machinery: * It works on every supported version of Python. The earlier version imported 'imp', which Python 3.12 removed, and used code that is only valid for Python 3. * A package is run through its '__main__', and relative imports within it work, as the package, spec and loader of the module are set up. * sys.argv[0] is the file of the module, as for Python. * Everything after the module name is for the module, including anything which looks like one of our options (so '-m module --flag' keeps the flag), and '-mmodule' without a space is accepted. * The module is found from the current directory, and the modules that it imports are found there too, rather than where the module is. * A module which is not found gives an error and an exit code of 1. The tests run modules with Python and with the shell, and compare what the module sees and the exit code that results. Co-Authored-By:Claude Sonnet 5.5 <noreply@anthropic.com>
2e487464