[pypy-svn] r39801 - pypy/dist/pypy/translator/goal

asigfrid at codespeak.net asigfrid at codespeak.net
Sat Mar 3 14:34:05 CET 2007


Author: asigfrid
Date: Sat Mar  3 14:34:04 2007
New Revision: 39801

Modified:
   pypy/dist/pypy/translator/goal/app_main.py
Log:
Issue 145 resolved
(asigfrid, arre)
Added -m option to pypy-c
Fixed bug in processing -c option


Modified: pypy/dist/pypy/translator/goal/app_main.py
==============================================================================
--- pypy/dist/pypy/translator/goal/app_main.py	(original)
+++ pypy/dist/pypy/translator/goal/app_main.py	Sat Mar  3 14:34:04 2007
@@ -9,6 +9,7 @@
   -S           do not 'import site' on initialization
   -u           unbuffered binary stdout and stderr
   -h, --help   show this help message and exit
+  -m           library module to be run as a script (terminates option list)
   --version    print the PyPy version
   --info       print translation information about this PyPy executable
 """
@@ -176,6 +177,7 @@
     run_command = False
     import_site = True
     i = 0
+    run_module = False
     while i < len(argv):
         arg = argv[i]
         if not arg.startswith('-'):
@@ -183,7 +185,7 @@
         if arg == '-i':
             go_interactive = True
         elif arg == '-c':
-            if i >= len(argv):
+            if i+1 >= len(argv):
                 print_error('Argument expected for the -c option')
                 return 2
             run_command = True
@@ -203,6 +205,13 @@
             return 0
         elif arg == '-S':
             import_site = False
+        elif arg == '-m':
+            i += 1
+            if i >= len(argv):
+                print_error('Argument expected for the -m option')
+                return 2
+            run_module = True
+            break
         elif arg == '--':
             i += 1
             break     # terminates option list
@@ -246,6 +255,11 @@
                 def run_it():
                     exec cmd in mainmodule.__dict__
                 success = run_toplevel(run_it)
+            elif run_module:
+                def run_it():
+                    import runpy
+                    runpy.run_module(sys.argv[0], None, '__main__', True)
+                success = run_toplevel(run_it)
             else:
                 scriptdir = resolvedirof(sys.argv[0])
                 sys.path.insert(0, scriptdir)



More information about the Pypy-commit mailing list