Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r61337:60025b983898
Date: 2013-02-16 14:38 -0800
http://bitbucket.org/pypy/pypy/changeset/60025b983898/
Log: update sys.flags: add quiet, remove others
diff --git a/lib_pypy/_pypy_interact.py b/lib_pypy/_pypy_interact.py
--- a/lib_pypy/_pypy_interact.py
+++ b/lib_pypy/_pypy_interact.py
@@ -4,7 +4,7 @@
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'):
@@ -12,17 +12,18 @@
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()):
diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py
--- a/pypy/interpreter/app_main.py
+++ b/pypy/interpreter/app_main.py
@@ -299,9 +299,7 @@
# Order is significant!
sys_flags = (
"debug",
- "py3k_warning",
"division_warning",
- "division_new",
"inspect",
"interactive",
"optimize",
@@ -309,10 +307,9 @@
"no_user_site",
"no_site",
"ignore_environment",
- "tabcheck",
"verbose",
- "unicode",
"bytes_warning",
+ "quiet",
"hash_randomization",
)
@@ -327,16 +324,6 @@
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)
@@ -362,11 +349,10 @@
'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),
@@ -376,7 +362,6 @@
'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),
@@ -465,13 +450,8 @@
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])
@@ -493,6 +473,7 @@
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
@@ -577,9 +558,11 @@
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:
@@ -655,7 +638,7 @@
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:
diff --git a/pypy/interpreter/test2/test_app_main.py
b/pypy/interpreter/test2/test_app_main.py
--- a/pypy/interpreter/test2/test_app_main.py
+++ b/pypy/interpreter/test2/test_app_main.py
@@ -129,26 +129,18 @@
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')
@@ -187,9 +179,6 @@
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"),
@@ -197,10 +186,7 @@
("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:
@@ -729,6 +715,11 @@
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
diff --git a/pypy/module/_warnings/interp_warnings.py
b/pypy/module/_warnings/interp_warnings.py
--- a/pypy/module/_warnings/interp_warnings.py
+++ b/pypy/module/_warnings/interp_warnings.py
@@ -15,11 +15,8 @@
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(
diff --git a/pypy/module/sys/app.py b/pypy/module/sys/app.py
--- a/pypy/module/sys/app.py
+++ b/pypy/module/sys/app.py
@@ -90,20 +90,17 @@
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)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit