Commits

Philip Jenvey  committed 60025b9

update sys.flags: add quiet, remove others

  • Participants
  • Parent commits 2664c3c
  • Branches py3k

Comments (0)

Files changed (5)

File lib_pypy/_pypy_interact.py

 import os
 
 
-def interactive_console(mainmodule=None):
+def interactive_console(mainmodule=None, quiet=False):
     # set sys.{ps1,ps2} just before invoking the interactive interpreter. This
     # mimics what CPython does in pythonrun.c
     if not hasattr(sys, 'ps1'):
     if not hasattr(sys, 'ps2'):
         sys.ps2 = '.... '
     #
-    try:
-        from _pypy_irc_topic import some_topic
-        text = "And now for something completely different: ``%s''" % (
-            some_topic(),)
-        while len(text) >= 80:
-            i = text[:80].rfind(' ')
-            print(text[:i])
-            text = text[i+1:]
-        print(text)
-    except ImportError:
-        pass
+    if not quiet:
+        try:
+            from _pypy_irc_topic import some_topic
+            text = "And now for something completely different: ``%s''" % (
+                some_topic(),)
+            while len(text) >= 80:
+                i = text[:80].rfind(' ')
+                print(text[:i])
+                text = text[i+1:]
+            print(text)
+        except ImportError:
+            pass
     #
     try:
         if not os.isatty(sys.stdin.fileno()):

File pypy/interpreter/app_main.py

 # Order is significant!
 sys_flags = (
     "debug",
-    "py3k_warning",
     "division_warning",
-    "division_new",
     "inspect",
     "interactive",
     "optimize",
     "no_user_site",
     "no_site",
     "ignore_environment",
-    "tabcheck",
     "verbose",
-    "unicode",
     "bytes_warning",
+    "quiet",
     "hash_randomization",
 )
 
 def simple_option(options, name, iterargv):
     options[name] += 1
 
-def div_option(options, div, iterargv):
-    if div == "warn":
-        options["division_warning"] = 1
-    elif div == "warnall":
-        options["division_warning"] = 2
-    elif div == "new":
-        options["division_new"] = 1
-    elif div != "old":
-        raise CommandLineError("invalid division option: %r" % (div,))
-
 def c_option(options, runcmd, iterargv):
     options["run_command"] = runcmd
     return ['-c'] + list(iterargv)
     'R': (simple_option, 'hash_randomization'),
     's': (simple_option, 'no_user_site'),
     'S': (simple_option, 'no_site'),
-    't': (simple_option, 'tabcheck'),
-    'U': (simple_option, 'unicode'),
     'u': (simple_option, 'unbuffered'),
     'b': (simple_option, 'bytes_warning'),
     'v': (simple_option, 'verbose'),
+    'q': (simple_option, 'quiet'),
     # more complex options
     'c':         (c_option,        Ellipsis),
     '?':         (print_help,      None),
     'W':         (W_option,        Ellipsis),
     'V':         (print_version,   None),
     '--version': (print_version,   None),
-    'Q':         (div_option,      Ellipsis),
     '--info':    (print_info,      None),
     '--jit':     (set_jit_option,  Ellipsis),
     '--':        (end_options,     None),
     if we_are_translated():
         flags = [options[flag] for flag in sys_flags]
         sys.flags = type(sys.flags)(flags)
-        sys.py3kwarning = bool(sys.flags.py3k_warning)
         sys.dont_write_bytecode = bool(sys.flags.dont_write_bytecode)
 
-        if sys.py3kwarning:
-            print("Warning: pypy does not implement py3k warnings",
-                  file=sys.stderr)
-
 ##    if not we_are_translated():
 ##        for key in sorted(options):
 ##            print '%40s: %s' % (key, options[key])
                      warnoptions,
                      unbuffered,
                      ignore_environment,
+                     quiet,
                      **ignored):
     # with PyPy in top of CPython we can only have around 100
     # but we need more in the translated PyPy for the compiler package
             sys.path.insert(0, '')
 
             if interactive or sys.stdin.isatty():
-                # If stdin is a tty or if "-i" is specified, we print
-                # a banner and run $PYTHONSTARTUP.
-                print_banner()
+                # If stdin is a tty or if "-i" is specified, we print a
+                # banner (unless "-q" was specified) and run
+                # $PYTHONSTARTUP.
+                if not quiet:
+                    print_banner()
                 python_startup = readenv and os.getenv('PYTHONSTARTUP')
                 if python_startup:
                     try:
         inteactive = False
         try:
             from _pypy_interact import interactive_console
-            success = run_toplevel(interactive_console, mainmodule)
+            success = run_toplevel(interactive_console, mainmodule, quiet)
         except SystemExit as e:
             status = e.code
         else:

File pypy/interpreter/test2/test_app_main.py

         self.check(['-S'], {}, sys_argv=[''], run_stdin=True, no_site=1)
         self.check(['-OO'], {}, sys_argv=[''], run_stdin=True, optimize=2)
         self.check(['-O', '-O'], {}, sys_argv=[''], run_stdin=True, optimize=2)
-        self.check(['-Qnew'], {}, sys_argv=[''], run_stdin=True, division_new=1)
-        self.check(['-Qold'], {}, sys_argv=[''], run_stdin=True, division_new=0)
-        self.check(['-Qwarn'], {}, sys_argv=[''], run_stdin=True, division_warning=1)
-        self.check(['-Qwarnall'], {}, sys_argv=[''], run_stdin=True,
-                   division_warning=2)
-        self.check(['-Q', 'new'], {}, sys_argv=[''], run_stdin=True, division_new=1)
-        self.check(['-SOQnew'], {}, sys_argv=[''], run_stdin=True,
-                   no_site=1, optimize=1, division_new=1)
-        self.check(['-SOQ', 'new'], {}, sys_argv=[''], run_stdin=True,
-                   no_site=1, optimize=1, division_new=1)
+        self.check(['-SO'], {}, sys_argv=[''], run_stdin=True,
+                   no_site=1, optimize=1)
         self.check(['-i'], {}, sys_argv=[''], run_stdin=True,
                    interactive=1, inspect=1)
         self.check(['-?'], {}, output_contains='usage:')
         self.check(['-h'], {}, output_contains='usage:')
-        self.check(['-S', '-tO', '-h'], {}, output_contains='usage:')
-        self.check(['-S', '-thO'], {}, output_contains='usage:')
-        self.check(['-S', '-tO', '--help'], {}, output_contains='usage:')
-        self.check(['-S', '-tO', '--info'], {}, output_contains='translation')
-        self.check(['-S', '-tO', '--version'], {}, output_contains='Python')
-        self.check(['-S', '-tOV'], {}, output_contains='Python')
+        self.check(['-S', '-O', '-h'], {}, output_contains='usage:')
+        self.check(['-S', '-hO'], {}, output_contains='usage:')
+        self.check(['-S', '-O', '--help'], {}, output_contains='usage:')
+        self.check(['-S', '-O', '--info'], {}, output_contains='translation')
+        self.check(['-S', '-O', '--version'], {}, output_contains='Python')
+        self.check(['-S', '-OV'], {}, output_contains='Python')
         self.check(['--jit', 'foobar', '-S'], {}, sys_argv=[''],
                    run_stdin=True, no_site=1)
         self.check(['-c', 'pass'], {}, sys_argv=['-c'], run_command='pass')
     def test_sysflags(self):
         flags = (
             ("debug", "-d", "1"),
-            ("division_warning", "-Qwarn", "1"),
-            ("division_warning", "-Qwarnall", "2"),
-            ("division_new", "-Qnew", "1"),
             (["inspect", "interactive"], "-i", "1"),
             ("optimize", "-O", "1"),
             ("optimize", "-OO", "2"),
             ("no_user_site", "-s", "1"),
             ("no_site", "-S", "1"),
             ("ignore_environment", "-E", "1"),
-            ("tabcheck", "-t", "1"),
-            ("tabcheck", "-tt", "2"),
             ("verbose", "-v", "1"),
-            ("unicode", "-U", "1"),
             ("bytes_warning", "-b", "1"),
         )
         for flag, opt, value in flags:
         assert 'hello world\n' in data
         assert '42\n' in data
 
+    def test_q_flag(self):
+        data = self.run('-iq', senddata='6*7\nraise SystemExit\n',
+                        expect_prompt=True, expect_banner=False)
+        assert '42\n' in data
+
     def test_non_interactive_stdout_fully_buffered(self):
         path = getscript(r"""
             import sys, time

File pypy/module/_warnings/interp_warnings.py

     def init_filters(self, space):
         filters_w = []
 
-        if (not space.sys.get_flag('py3k_warning') and
-            not space.sys.get_flag('division_warning')):
-            filters_w.append(create_filter(
-                space, space.w_DeprecationWarning, "ignore"))
-
+        filters_w.append(create_filter(
+            space, space.w_DeprecationWarning, "ignore"))
         filters_w.append(create_filter(
             space, space.w_PendingDeprecationWarning, "ignore"))
         filters_w.append(create_filter(

File pypy/module/sys/app.py

     name = "sys.flags"
 
     debug = structseqfield(0)
-    py3k_warning = structseqfield(1)
-    division_warning = structseqfield(2)
-    division_new = structseqfield(3)
-    inspect = structseqfield(4)
-    interactive = structseqfield(5)
-    optimize = structseqfield(6)
-    dont_write_bytecode = structseqfield(7)
-    no_user_site = structseqfield(8)
-    no_site = structseqfield(9)
-    ignore_environment = structseqfield(10)
-    tabcheck = structseqfield(11)
-    verbose = structseqfield(12)
-    unicode = structseqfield(13)
-    bytes_warning = structseqfield(14)
-    hash_randomization = structseqfield(15)
+    division_warning = structseqfield(1)
+    inspect = structseqfield(2)
+    interactive = structseqfield(3)
+    optimize = structseqfield(4)
+    dont_write_bytecode = structseqfield(5)
+    no_user_site = structseqfield(6)
+    no_site = structseqfield(7)
+    ignore_environment = structseqfield(8)
+    verbose = structseqfield(9)
+    bytes_warning = structseqfield(10)
+    quiet = structseqfield(11)
+    hash_randomization = structseqfield(12)
 
-null_sysflags = sysflags((0,)*16)
+null_sysflags = sysflags((0,)*13)