Commits

Philip Jenvey committed 680b7dc

cpython issue8202: include -m in the initial argv (more like -c does)

Comments (0)

Files changed (2)

pypy/interpreter/app_main.py

     return ['-c'] + list(iterargv)
 
 def m_option(options, runmodule, iterargv):
-    options["run_module"] = True
-    return [runmodule] + list(iterargv)
+    options["run_module"] = runmodule
+    return ['-m'] + list(iterargv)
 
 def W_option(options, warnoption, iterargv):
     options["warnoptions"].append(warnoption)
             def run_it():
                 exec_(run_command, mainmodule.__dict__)
             success = run_toplevel(run_it)
-        elif run_module:
+        elif run_module != 0:
             # handle the "-m" command
             # '' on sys.path is required also here
             sys.path.insert(0, '')
             import runpy
-            success = run_toplevel(runpy._run_module_as_main, sys.argv[0])
+            success = run_toplevel(runpy._run_module_as_main, run_module)
         elif run_stdin:
             # handle the case where no command/filename/module is specified
             # on the command-line.

pypy/interpreter/test2/test_app_main.py

                    no_site=1)
         self.check(['-Scpass'], {}, sys_argv=['-c'], run_command='pass', no_site=1)
         self.check(['-c', '', ''], {}, sys_argv=['-c', ''], run_command='')
-        self.check(['-mfoo', 'bar', 'baz'], {}, sys_argv=['foo', 'bar', 'baz'],
-                   run_module=True)
-        self.check(['-m', 'foo', 'bar', 'baz'], {}, sys_argv=['foo', 'bar', 'baz'],
-                   run_module=True)
-        self.check(['-Smfoo', 'bar', 'baz'], {}, sys_argv=['foo', 'bar', 'baz'],
-                   run_module=True, no_site=1)
-        self.check(['-Sm', 'foo', 'bar', 'baz'], {}, sys_argv=['foo', 'bar', 'baz'],
-                   run_module=True, no_site=1)
+        self.check(['-mfoo', 'bar', 'baz'], {}, sys_argv=['-m', 'bar', 'baz'],
+                   run_module='foo')
+        self.check(['-m', 'foo', 'bar', 'baz'], {}, sys_argv=['-m', 'bar', 'baz'],
+                   run_module='foo')
+        self.check(['-Smfoo', 'bar', 'baz'], {}, sys_argv=['-m', 'bar', 'baz'],
+                   run_module='foo', no_site=1)
+        self.check(['-Sm', 'foo', 'bar', 'baz'], {}, sys_argv=['-m', 'bar', 'baz'],
+                   run_module='foo', no_site=1)
         self.check(['-', 'foo', 'bar'], {}, sys_argv=['-', 'foo', 'bar'],
                    run_stdin=True)
         self.check(['foo', 'bar'], {}, sys_argv=['foo', 'bar'])
         assert ('File: ' + p) in data
         assert ('Argv: ' + repr([p, 'extra'])) in data
 
+    def test_option_m_package(self, monkeypatch):
+        if not hasattr(runpy, '_run_module_as_main'):
+            skip("requires CPython >= 2.6")
+        p = os.path.join(os.path.realpath(os.path.dirname(__file__)),
+                         'mypackage', '__main__.py')
+        p = os.path.abspath(p)
+        monkeypatch.chdir(os.path.dirname(app_main))
+        data = self.run('-m test2.mypackage extra')
+        assert "__init__ argv: ['-m', 'extra']" in data
+        assert "__main__ argv: [%r, 'extra']" % p in data
+
     def test_pythoninspect_doesnt_override_isatty(self):
         os.environ['PYTHONINSPECT_'] = '1'
         try: