[pypy-svn] r35318 - in pypy/dist/pypy: . bin interpreter/pyparser interpreter/pyparser/test tool translator/goal translator/js
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Dec 5 18:29:17 CET 2006
Author: cfbolz
Date: Tue Dec 5 18:29:14 2006
New Revision: 35318
Modified:
pypy/dist/pypy/bin/jscompile.py
pypy/dist/pypy/bin/py.py
pypy/dist/pypy/conftest.py
pypy/dist/pypy/interpreter/pyparser/pythonparse.py
pypy/dist/pypy/interpreter/pyparser/test/stdlib_testall.py
pypy/dist/pypy/interpreter/pyparser/test/test_astcompiler.py
pypy/dist/pypy/tool/option.py
pypy/dist/pypy/translator/goal/targetmultiplespaces.py
pypy/dist/pypy/translator/js/main.py
Log:
yay, kill kill kill code! clean up the mess that tool/option.py was after the
introduction of a better way of dealing with configuration. Changes here and
there (a lot of them in javascript stuff, I hope I didn't break anything there).
Modified: pypy/dist/pypy/bin/jscompile.py
==============================================================================
--- pypy/dist/pypy/bin/jscompile.py (original)
+++ pypy/dist/pypy/bin/jscompile.py Tue Dec 5 18:29:14 2006
@@ -9,39 +9,20 @@
import autopath
import sys, os
-from pypy.translator.js.main import rpython2javascript_main, Options
+from pypy.translator.js.main import rpython2javascript_main, js_optiondescr
-from pypy.tool import option
-from py.compat import optparse
-make_option = optparse.make_option
+from pypy.config.config import Config, to_optparse
-def get_options():
- options = []
- config, parser = option.get_standard_options()
-
- options.append(make_option(
- '--view', action='store_true', dest='view',
- help='View flow graphs'))
-
- options.append(make_option(
- '--output', action='store', type='string', dest='output',
- help='File to save results (default output.js)'))
-
- options.append(make_option(
- '-d', '--debug', action='store_true', dest='debug_transform',
- help="Use !EXPERIMENTAL! debug transform to produce tracebacks"
- ))
-
- parser.add_options(options)
- return config, parser
-
def process_options(argv):
- config, parser = get_options()
- return option.process_options(parser, Options, argv[1:])
+ jsconfig = Config(js_optiondescr)
+ parser, to_optparse(jsconfig)
+ parser.disable_interspersed_args()
+ options, args = parser.parse_args(argv)
+ return args, jsconfig
if __name__ == '__main__':
- argv = process_options(sys.argv)
+ args, jsconfig = process_options(sys.argv)
curdir = os.getcwd()
if curdir not in sys.path:
sys.path.insert(0, curdir)
- rpython2javascript_main(argv, Options)
+ rpython2javascript_main(args, jsconfig)
Modified: pypy/dist/pypy/bin/py.py
==============================================================================
--- pypy/dist/pypy/bin/py.py (original)
+++ pypy/dist/pypy/bin/py.py Tue Dec 5 18:29:14 2006
@@ -14,65 +14,36 @@
from pypy.tool import option
from py.compat.optparse import make_option
from pypy.interpreter import main, interactive, error
+from pypy.config.config import OptionDescription, BoolOption, StrOption
+from pypy.config.config import Config, to_optparse
import os, sys
import time
-class Options(option.Options):
- verbose = os.getenv('PYPY_TB')
- interactive = 0
- command = []
- completer = False
- module = None
- module_args = []
-
-def get_main_options():
- config, parser = option.get_standard_options()
-
- options = []
- options.append(make_option(
- '-v', action='store_true', dest='verbose',
- help='show verbose interpreter-level traceback'))
-
- options.append(make_option(
- '-C', action='store_true', dest='completer',
- help='use readline commandline completer'))
-
- options.append(make_option(
- '-i', action="store_true", dest="interactive",
- help="inspect interactively after running script"))
-
- options.append(make_option(
- '-O', action="store_true", dest="optimize",
- help="dummy optimization flag for compatibility with C Python"))
-
- def command_callback(option, opt, value, parser):
- parser.values.command = parser.rargs[:]
- parser.rargs[:] = []
-
- options.append(make_option(
- '-c', action="callback",
- callback=command_callback,
- help="program passed in as CMD (terminates option list)"))
-
- def runmodule_callback(option, opt, value, parser):
- parser.values.module_args = parser.rargs[:]
- parser.values.module = value
- parser.rargs[:] = []
-
- options.append(make_option(
- '-m', action="callback", metavar='NAME',
- callback=runmodule_callback, type="string",
- help="library module to be run as a script (terminates option list)"))
-
- parser.add_options(options)
-
- return config, parser
+cmdline_optiondescr = OptionDescription("interactive", "the options of py.py", [
+ BoolOption("verbose", "show verbose interpreter-level traceback",
+ default=os.getenv("PYPY_TB"), cmdline="-v"),
+ BoolOption("interactive", "inspect interactively after running script",
+ default=False, cmdline="-i"),
+ BoolOption("completer", "use readline commandline completer",
+ default=False, cmdline="-C"),
+ BoolOption("optimize",
+ "dummy optimization flag for compatibility with C Python",
+ default=False, cmdline="-O"),
+ StrOption("runmodule",
+ "library module to be run as a script (terminates option list)",
+ default=None, cmdline="-m"),
+ StrOption("runcommand",
+ "program passed in as CMD (terminates option list)",
+ default=None, cmdline="-c"),
+ ])
def main_(argv=None):
starttime = time.time()
- config, parser = get_main_options()
- args = option.process_options(parser, Options, argv[1:])
- if Options.verbose:
+ config, parser = option.get_standard_options()
+ interactiveconfig = Config(cmdline_optiondescr)
+ to_optparse(interactiveconfig, parser=parser)
+ args = option.process_options(parser, argv[1:])
+ if interactiveconfig.verbose:
error.RECORD_INTERPLEVEL_TRACEBACK = True
# create the object space
@@ -87,21 +58,22 @@
space.setitem(space.sys.w_dict,space.wrap('executable'),space.wrap(argv[0]))
# store the command-line arguments into sys.argv
- go_interactive = Options.interactive
+ go_interactive = interactiveconfig.interactive
banner = ''
exit_status = 0
- if Options.command:
- args = ['-c'] + Options.command[1:]
+ if interactiveconfig.runcommand is not None:
+ args = ['-c'] + args
for arg in args:
space.call_method(space.sys.get('argv'), 'append', space.wrap(arg))
# load the source of the program given as command-line argument
- if Options.command:
+ if interactiveconfig.runcommand is not None:
def doit():
- main.run_string(Options.command[0], space=space)
- elif Options.module:
+ main.run_string(interactiveconfig.runcommand, space=space)
+ elif interactiveconfig.runmodule:
def doit():
- main.run_module(Options.module, Options.module_args, space=space)
+ main.run_module(interactiveconfig.runmodule,
+ args, space=space)
elif args:
scriptdir = os.path.dirname(os.path.abspath(args[0]))
space.call_method(space.sys.get('path'), 'insert',
@@ -118,16 +90,18 @@
try:
def do_start():
space.startup()
- if main.run_toplevel(space, do_start, verbose=Options.verbose):
+ if main.run_toplevel(space, do_start,
+ verbose=interactiveconfig.verbose):
# compile and run it
- if not main.run_toplevel(space, doit, verbose=Options.verbose):
+ if not main.run_toplevel(space, doit,
+ verbose=interactiveconfig.verbose):
exit_status = 1
# start the interactive console
if go_interactive:
con = interactive.PyPyConsole(
- space, verbose=Options.verbose,
- completer=Options.completer)
+ space, verbose=interactiveconfig.verbose,
+ completer=interactiveconfig.completer)
if banner == '':
banner = '%s / %s'%(con.__class__.__name__,
repr(space))
@@ -136,7 +110,7 @@
finally:
def doit():
space.finish()
- main.run_toplevel(space, doit, verbose=Options.verbose)
+ main.run_toplevel(space, doit, verbose=interactiveconfig.verbose)
return exit_status
Modified: pypy/dist/pypy/conftest.py
==============================================================================
--- pypy/dist/pypy/conftest.py (original)
+++ pypy/dist/pypy/conftest.py Tue Dec 5 18:29:14 2006
@@ -1,8 +1,8 @@
import py, sys
-from pypy.interpreter.gateway import app2interp_temp
+from pypy.interpreter.gateway import app2interp_temp
from pypy.interpreter.error import OperationError
-from pypy.tool.pytest import appsupport
-from pypy.tool.option import make_config
+from pypy.tool.pytest import appsupport
+from pypy.tool.option import make_config, make_objspace
from inspect import isclass, getmro
rootdir = py.magic.autopath().dirpath()
@@ -13,43 +13,17 @@
#
Option = py.test.Config.Option
-#class Options:
-# group = "pypy options"
-# optionlist =
-
-def usemodules_callback(option, opt, value, parser):
- parser.values.usemodules.append(value)
-
-# XXX these options should go away
-
-option = py.test.Config.addoptions("pypy options",
- Option('-O', '--objspace', action="store", default=None,
- type="string", dest="objspace",
- help="object space to run tests on."),
- Option('--oldstyle', action="store_true",dest="oldstyle", default=False,
- help="enable oldstyle classes as default metaclass"),
- Option('--nofaking', action="store_true",
- dest="nofaking", default=False,
- help="avoid faking of modules and objects completely."),
- Option('--usemodules', action="callback", type="string", metavar="NAME",
- callback=usemodules_callback, default=[],
- help="(mixed) modules to use."),
- Option('--compiler', action="store", type="string", dest="compiler",
- metavar="[ast|cpython]", default='ast',
- help="""select compiling approach. see pypy/doc/README.compiling"""),
+
+option = py.test.Config.addoptions("pypy options",
Option('--view', action="store_true", dest="view", default=False,
help="view translation tests' flow graphs with Pygame"),
- Option('--gc', action="store", default=None,
- type="choice", dest="gcpolicy",
- choices=['ref', 'boehm', 'none', 'framework', 'exact_boehm'],
- help="GcPolicy class to use for genc tests"),
- Option('-A', '--runappdirect', action="store_true",
+ Option('-A', '--runappdirect', action="store_true",
default=False, dest="runappdirect",
- help="run applevel tests directly on python interpreter (not through PyPy)"),
+ help="run applevel tests directly on python interpreter (not through PyPy)"),
)
_SPACECACHE={}
-def getobjspace(name=None, **kwds):
+def gettestobjspace(name=None, **kwds):
""" helper for instantiating and caching space's for testing.
"""
config = make_config(option, objspace=name, **kwds)
@@ -59,26 +33,23 @@
except KeyError:
if option.runappdirect:
return TinyObjSpace(**kwds)
- mod = __import__('pypy.objspace.%s' % config.objspace.name,
- None, None, ['Space'])
- Space = mod.Space
- try:
- space = Space(config)
+ try:
+ space = make_objspace(config)
except OperationError, e:
check_keyboard_interrupt(e)
- if option.verbose:
- import traceback
- traceback.print_exc()
+ if option.verbose:
+ import traceback
+ traceback.print_exc()
py.test.fail("fatal: cannot initialize objspace: %r" %(Space,))
_SPACECACHE[key] = space
- space.setitem(space.builtin.w_dict, space.wrap('AssertionError'),
+ space.setitem(space.builtin.w_dict, space.wrap('AssertionError'),
appsupport.build_pytest_assertion(space))
space.setitem(space.builtin.w_dict, space.wrap('raises'),
space.wrap(appsupport.app_raises))
space.setitem(space.builtin.w_dict, space.wrap('skip'),
space.wrap(appsupport.app_skip))
space.raises_w = appsupport.raises_w.__get__(space)
- space.eq_w = appsupport.eq_w.__get__(space)
+ space.eq_w = appsupport.eq_w.__get__(space)
return space
class TinyObjSpace(object):
@@ -188,9 +159,6 @@
else:
return IntTestFunction(name, parent=self)
-def gettestobjspace(name=None, **kwds):
- space = getobjspace(name, **kwds)
- return space
def skip_on_missing_buildoption(**ropts):
__tracebackhide__ = True
Modified: pypy/dist/pypy/interpreter/pyparser/pythonparse.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/pythonparse.py (original)
+++ pypy/dist/pypy/interpreter/pyparser/pythonparse.py Tue Dec 5 18:29:14 2006
@@ -8,7 +8,6 @@
from pypy.interpreter.error import OperationError, debug_print
from pypy.interpreter import gateway
from pypy.interpreter.pyparser.error import SyntaxError
-from pypy.tool.option import Options
from pythonlexer import Source, match_encoding_declaration
from pypy.interpreter.astcompiler.consts import CO_FUTURE_WITH_STATEMENT
import pysymbol
@@ -131,8 +130,9 @@
_ver = version
return os.path.join( os.path.dirname(__file__), "data", "Grammar" + _ver ), _ver
-# unfortunately the command line options are not parsed yet
-PYTHON_GRAMMAR, PYPY_VERSION = get_grammar_file( Options.version )
+# unfortunately the command line options are not parsed yet, so it cannot
+# be made configurable yet
+PYTHON_GRAMMAR, PYPY_VERSION = get_grammar_file("2.5a")
def python_grammar(fname):
"""returns a PythonParser build from the specified grammar file"""
Modified: pypy/dist/pypy/interpreter/pyparser/test/stdlib_testall.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/test/stdlib_testall.py (original)
+++ pypy/dist/pypy/interpreter/pyparser/test/stdlib_testall.py Tue Dec 5 18:29:14 2006
@@ -7,7 +7,7 @@
if sys.version[:3] != "2.4":
py.test.skip("expected to work only on 2.4")
import pypy.conftest
- mod.std_space = pypy.conftest.getobjspace('std')
+ mod.std_space = pypy.conftest.gettestobjspace('std')
def check_file_compile(filename):
print 'Compiling:', filename
Modified: pypy/dist/pypy/interpreter/pyparser/test/test_astcompiler.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/test/test_astcompiler.py (original)
+++ pypy/dist/pypy/interpreter/pyparser/test/test_astcompiler.py Tue Dec 5 18:29:14 2006
@@ -7,7 +7,7 @@
def setup_module(mod):
import pypy.conftest
- mod.std_space = pypy.conftest.getobjspace('std')
+ mod.std_space = pypy.conftest.gettestobjspace('std')
from pypy.interpreter.astcompiler import ast, misc, pycodegen
Modified: pypy/dist/pypy/tool/option.py
==============================================================================
--- pypy/dist/pypy/tool/option.py (original)
+++ pypy/dist/pypy/tool/option.py Tue Dec 5 18:29:14 2006
@@ -1,28 +1,14 @@
# This is where the options for py.py are defined.
-# XXX needs clean-up and reorganization.
import os
from pypy.config.pypyoption import get_pypy_config
from pypy.config.config import Config, OptionDescription, to_optparse
from py.compat import optparse
-make_option = optparse.make_option
-
-class Options:
- objspace = "std"
- oldstyle = 0
- nofaking = 0
- parser = "pypy" # "cpython" / "pypy"
- compiler = "ast"
- # "ast" uses interpreter/pyparser & interpreter/astcompiler.py
- # "cpython" uses cpython parser and cpython c-level compiler
- usemodules = []
- version = "2.5a" # "native" / "2.3" / "2.4" / "2.5a"
def run_tb_server(option, opt, value, parser):
from pypy.tool import tb_server
tb_server.start()
-
def get_standard_options():
config = get_pypy_config()
parser = to_optparse(config, useoptions=["objspace.*"])
@@ -32,65 +18,29 @@
help="use web browser for traceback info")
return config, parser
-def process_options(op, input_options, argv=None):
- global Options
- Options = input_options
- # backward compatilibity
- if isinstance(op, list):
- import sys, os
- basename = os.path.basename(sys.argv[0])
- config = Config(OptionDescription(basename, basename, []))
- parser = to_optparse(config)
- parser.add_options(op)
- op = parser
- op.disable_interspersed_args()
- options, args = op.parse_args(argv, input_options)
+def process_options(parser, argv=None):
+ parser.disable_interspersed_args()
+ options, args = parser.parse_args(argv)
return args
def make_config(cmdlineopt, **kwds):
""" make a config from cmdline options (which overrides everything)
and kwds """
- # XXX this whole file should sooner or later go away and the cmd line
- # options be generated from the option description. it's especially messy
- # since we have to check whether the default was actually overwritten
- conf = get_pypy_config()
- if kwds.get("objspace", None) is not None:
- conf.objspace.name = kwds["objspace"]
- if getattr(cmdlineopt, "objspace", None) is not None:
- conf.objspace.name = cmdlineopt.objspace
- modnames = getattr(cmdlineopt, "usemodules", '')
- if isinstance(modnames, str):
- modnames = [mn.strip() for mn in modnames.split(',') if mn.strip()]
- for modname in modnames:
- setattr(conf.objspace.usemodules, modname, True)
- for modname in kwds.get("usemodules", []):
- setattr(conf.objspace.usemodules, modname, True)
- if getattr(cmdlineopt, "nofaking", False) or kwds.get("nofaking", False):
- conf.objspace.nofaking = True
- if getattr(cmdlineopt, "oldstyle", False) or kwds.get("oldstyle", False):
- conf.objspace.std.oldstyle = True
- if hasattr(cmdlineopt, "parser") and cmdlineopt.parser is not None:
- conf.objspace.parser = cmdlineopt.parser
- if kwds.get("compiler") is not None:
- conf.obspace.compiler = kwds['compiler']
- if getattr(cmdlineopt, "compiler", None) is not None:
- conf.objspace.compiler = cmdlineopt.compiler
- for names, value in kwds.iteritems():
- if "." not in names:
- continue
- names = names.split(".")
- subconf = conf
- for name in names[:-1]:
- subconf = getattr(subconf, name)
- setattr(subconf, names[-1], value)
- return conf
+ config = get_pypy_config(translating=False)
+ objspace = kwds.pop("objspace", None)
+ if objspace is not None:
+ config.objspace.name = objspace
+ for modname in kwds.pop("usemodules", []):
+ setattr(config.objspace.usemodules, modname, True)
+ config.set(**kwds)
+ return config
-def make_objspace(conf):
- mod = __import__('pypy.objspace.%s' % conf.objspace.name,
+def make_objspace(config):
+ mod = __import__('pypy.objspace.%s' % config.objspace.name,
None, None, ['Space'])
Space = mod.Space
#conf.objspace.logbytecodes = True
- space = Space(conf)
- return space
+ space = Space(config)
+ return space
Modified: pypy/dist/pypy/translator/goal/targetmultiplespaces.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetmultiplespaces.py (original)
+++ pypy/dist/pypy/translator/goal/targetmultiplespaces.py Tue Dec 5 18:29:14 2006
@@ -1,7 +1,5 @@
import os, sys
-from pypy.tool.option import make_config
-
from pypy.objspace.std.objspace import StdObjSpace
# XXX from pypy.annotation.model import *
# since we are execfile()'ed this would pull some
Modified: pypy/dist/pypy/translator/js/main.py
==============================================================================
--- pypy/dist/pypy/translator/js/main.py (original)
+++ pypy/dist/pypy/translator/js/main.py Tue Dec 5 18:29:14 2006
@@ -11,14 +11,21 @@
from pypy.rlib.nonconst import NonConstant
from pypy.annotation.policy import AnnotatorPolicy
from py.compat import optparse
+from pypy.config.config import OptionDescription, BoolOption, StrOption
+from pypy.config.config import Config, to_optparse
import py
-from pypy.tool import option
-class Options(option.Options):
- view = False
- output = 'output.js'
- debug_transform = False
- use_pdb = True
+js_optiondescr = OptionDescription("jscompile", "", [
+ BoolOption("view", "View flow graphs",
+ default=False, cmdline="--view"),
+ BoolOption("use_pdb", "Use debugger",
+ default=False, cmdline="--pdb"),
+ BoolOption("debug_transform",
+ "Use !EXPERIMENTAL! debug transform to produce tracebacks",
+ default=False, cmdline="-d --debug"),
+ StrOption("output", "File to save results (default output.js)",
+ default="output.js", cmdline="--output")])
+
class FunctionNotFound(Exception):
pass
@@ -39,7 +46,7 @@
return ",".join(func_data.func_code.co_varnames\
[:func_data.func_code.co_argcount])
-def rpython2javascript_main(argv, opts):
+def rpython2javascript_main(argv, jsconfig):
if len(argv) < 2:
print "usage: module <function_names>"
import sys
@@ -49,10 +56,9 @@
module_name = module_name[:-3]
function_names = argv[1:]
mod = __import__(module_name, None, None, ["Module"])
- source = rpython2javascript(mod, function_names, opts=opts)
- if opts.output != '':
- open(opts.output, "w").write(source)
- print "Written file %s" % opts.output
+ source = rpython2javascript(mod, function_names, jsconfig=jsconfig)
+ open(jsconfig.output, "w").write(source)
+ print "Written file %s" % jsconfig.output
# some strange function source
source_ssf_base = """
@@ -106,7 +112,11 @@
print retval
return retval
-def rpython2javascript(mod, function_names, opts=Options, use_pdb=True):
+def rpython2javascript(mod, function_names, jsconfig=None, use_pdb=True):
+ if jsconfig is None:
+ jsconfig = Config(js_optiondescr )
+ if use_pdb:
+ jsconfig.use_pdb = True
module_name = mod.__name__
if not function_names and 'main' in mod.__dict__:
function_names.append('main')
@@ -121,7 +131,8 @@
if func_code.func_code.co_argcount > 0 and func_code.func_code. \
co_argcount != lgt:
raise BadSignature("Function %s does not have default arguments" % func_name)
- source_ssf = get_source_ssf(mod, module_name, function_names, opts.debug_transform)
+ source_ssf = get_source_ssf(mod, module_name, function_names,
+ jsconfig.debug_transform)
exec(source_ssf) in globals()
# now we gonna just cut off not needed function
# XXX: Really do that
@@ -129,12 +140,12 @@
#options.debug_transform = opts.debug_transform
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=True)
- config.translation.debug_transform = opts.debug_transform
+ config.translation.debug_transform = jsconfig.debug_transform
driver = TranslationDriver(config=config)
try:
driver.setup(some_strange_function_which_will_never_be_called, [], policy = JsPolicy())
driver.proceed(["compile_js"])
- if opts.view:
+ if jsconfig.view:
driver.translator.view()
return driver.gen.tmpfile.open().read()
# XXX: Add some possibility to write down selected file
More information about the pypy-svn
mailing list