Commits

Philip Jenvey committed 5fae4dd

add sys._xoptions

  • Participants
  • Parent commits 680b7dc
  • Branches py3k

Comments (0)

Files changed (4)

File pypy/interpreter/app_main.py

   -h, --help     show this help message and exit
   -m mod         library module to be run as a script (terminates option list)
   -W arg         warning control (arg is action:message:category:module:lineno)
+  -X opt         set implementation-specific option
   -E             ignore environment variables (such as PYTHONPATH)
   -R             ignored (see http://bugs.python.org/issue14621)
   --version      print the PyPy version
     options["run_module"] = runmodule
     return ['-m'] + list(iterargv)
 
+def X_option(options, xoption, iterargv):
+    options["_xoptions"].append(xoption)
+
 def W_option(options, warnoption, iterargv):
     options["warnoptions"].append(warnoption)
 
     '--help':    (print_help,      None),
     'm':         (m_option,        Ellipsis),
     'W':         (W_option,        Ellipsis),
+    'X':         (X_option,        Ellipsis),
     'V':         (print_version,   None),
     '--version': (print_version,   None),
     '--info':    (print_info,      None),
     import os
     options = default_options.copy()
     options['warnoptions'] = []
+    options['_xoptions'] = []
 
     iterargv = iter(argv)
     argv = None
         sys.flags = type(sys.flags)(flags)
         sys.dont_write_bytecode = bool(sys.flags.dont_write_bytecode)
 
+    sys._xoptions = dict(x.split('=', 1) if '=' in x else (x, True)
+                         for x in options['_xoptions'])
+
 ##    if not we_are_translated():
 ##        for key in sorted(options):
 ##            print '%40s: %s' % (key, options[key])

File pypy/interpreter/test2/test_app_main.py

         self.check(['-Wbog'], {}, sys_argv=[''], warnoptions=['bog'], run_stdin=True)
         self.check(['-W', 'ab', '-SWc'], {}, sys_argv=[''], warnoptions=['ab', 'c'],
                    run_stdin=True, no_site=1)
+        self.check(['-X', 'foo'], {}, sys_argv=[''], _xoptions=['foo'],
+                   run_stdin=True)
+        self.check(['-X', 'foo=bar', '-Xbaz'], {}, sys_argv=[''],
+                   _xoptions=['foo=bar', 'baz'], run_stdin=True)
 
         self.check([], {'PYTHONDEBUG': '1'}, sys_argv=[''], run_stdin=True, debug=1)
         self.check([], {'PYTHONDONTWRITEBYTECODE': '1'}, sys_argv=[''], run_stdin=True, dont_write_bytecode=1)
         assert "__init__ argv: ['-m', 'extra']" in data
         assert "__main__ argv: [%r, 'extra']" % p in data
 
+    def test_xoptions(self):
+        data = self.run('-Xfoo -Xbar=baz -Xquux=cdrom.com=FreeBSD -Xx=X,d=e '
+                        '-c "import sys;print(sorted(sys._xoptions.items()))"')
+        expected = ("[('bar', 'baz'), ('foo', True), "
+                    "('quux', 'cdrom.com=FreeBSD'), ('x', 'X,d=e')]")
+        assert expected in data
+
     def test_pythoninspect_doesnt_override_isatty(self):
         os.environ['PYTHONINSPECT_'] = '1'
         try:

File pypy/module/sys/__init__.py

         'callstats'             : 'app.callstats',
         'copyright'             : 'app.copyright_str',
         'flags'                 : 'app.null_sysflags',
+        '_xoptions'             : 'app.null__xoptions',
     }
 
     def setbuiltinmodule(self, w_module, name): 

File pypy/module/sys/app.py

     hash_randomization = structseqfield(12)
 
 null_sysflags = sysflags((0,)*13)
+null__xoptions = {}