aboutsummaryrefslogtreecommitdiff
path: root/pypy
diff options
context:
space:
mode:
authorAlexander Schremmer <alex-bitbucket@alexanderweb.de>2007-09-26 11:42:02 +0000
committerAlexander Schremmer <alex-bitbucket@alexanderweb.de>2007-09-26 11:42:02 +0000
commit6801cde2b780a175c7f875b24f6747696e0ca7b3 (patch)
tree46142d544be4b87561695efb158b4c19b05c7cf5 /pypy
parentYay! zlib seems to be basically working. (diff)
downloadpypy-6801cde2b780a175c7f875b24f6747696e0ca7b3.tar.gz
pypy-6801cde2b780a175c7f875b24f6747696e0ca7b3.tar.bz2
pypy-6801cde2b780a175c7f875b24f6747696e0ca7b3.zip
Move the oldstyle translation option to py.py and app_main.py to make it setable at runtime.
Diffstat (limited to 'pypy')
-rwxr-xr-xpypy/bin/py.py11
-rw-r--r--pypy/config/pypyoption.py4
-rw-r--r--pypy/lib/pyontology/test/test_sparql.py2
-rw-r--r--pypy/objspace/std/objspace.py20
-rw-r--r--pypy/objspace/std/test/test_index.py4
-rw-r--r--pypy/translator/goal/app_main.py26
-rw-r--r--pypy/translator/goal/targetpypystandalone.py4
7 files changed, 31 insertions, 40 deletions
diff --git a/pypy/bin/py.py b/pypy/bin/py.py
index 848e057184..c396a2705f 100755
--- a/pypy/bin/py.py
+++ b/pypy/bin/py.py
@@ -37,6 +37,9 @@ cmdline_optiondescr = OptionDescription("interactive", "the options of py.py", [
StrOption("runcommand",
"program passed in as CMD (terminates option list)",
default=None, cmdline="-c"),
+ BoolOption("oldstyle_classes",
+ "Use old-style classes by default.",
+ default=False, cmdline="-k --oldstyle"),
])
pypy_init = gateway.applevel('''
@@ -73,11 +76,9 @@ def main_(argv=None):
space = option.make_objspace(config)
space._starttime = starttime
- #assert 'pypy.tool.udir' not in sys.modules, (
- # "running py.py should not import pypy.tool.udir, which is\n"
- # "only for testing or translating purposes.")
- # ^^^ _socket and other rctypes-based modules need udir
- space.setitem(space.sys.w_dict,space.wrap('executable'),space.wrap(argv[0]))
+ space.setitem(space.sys.w_dict, space.wrap('executable'), space.wrap(argv[0]))
+ if interactiveconfig.oldstyle_classes:
+ space.setitem(space.builtin.w_dict, space.wrap('__metaclass__'), space.w_classobj)
# store the command-line arguments into sys.argv
go_interactive = interactiveconfig.interactive
diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
index 9c433069a9..5be1e2b17f 100644
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -235,10 +235,6 @@ pypy_optiondescription = OptionDescription("objspace", "Object Space Options", [
"special case the 'list[integer]' expressions",
default=False),
- BoolOption("oldstyle",
- "specify whether the default metaclass should be classobj",
- default=False, cmdline="--oldstyle"),
-
BoolOption("logspaceoptypes",
"a instrumentation option: before exit, print the types seen by "
"certain simpler bytecodes",
diff --git a/pypy/lib/pyontology/test/test_sparql.py b/pypy/lib/pyontology/test/test_sparql.py
index fe0021bd83..bbf6ecbddc 100644
--- a/pypy/lib/pyontology/test/test_sparql.py
+++ b/pypy/lib/pyontology/test/test_sparql.py
@@ -500,4 +500,4 @@ def check_have_oldstyle():
if check_have_oldstyle():
TestXMLRPC = _TestXMLRPC
else:
- py.test.skip('Please build PyPy with --oldstyle, needed by xmlrpclib')
+ py.test.skip('Please run PyPy with --oldstyle, needed by xmlrpclib')
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
index afadbe4f35..da7b7231e7 100644
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -48,10 +48,6 @@ class StdObjSpace(ObjSpace, DescrOperation):
PACKAGE_PATH = 'objspace.std'
- def setoptions(self, **kwds):
- if "oldstyle" in kwds:
- self.config.objspace.std.oldstyle = kwds["oldstyle"]
-
def initialize(self):
"NOT_RPYTHON: only for initializing the space."
self._typecache = Cache()
@@ -253,11 +249,9 @@ class StdObjSpace(ObjSpace, DescrOperation):
""")
self.w_dict.__flags__ = old_flags
- if self.config.objspace.std.oldstyle:
- self.enable_old_style_classes_as_default_metaclass()
-
# final setup
self.setup_builtin_modules()
+
# Adding transparent proxy call
if self.config.objspace.std.withtproxy:
w___pypy__ = self.getbuiltinmodule("__pypy__")
@@ -268,16 +262,7 @@ class StdObjSpace(ObjSpace, DescrOperation):
self.setattr(w___pypy__, self.wrap('get_tproxy_controller'),
self.wrap(app_proxy_controller))
- def enable_old_style_classes_as_default_metaclass(self):
- self.setitem(self.builtin.w_dict, self.wrap('__metaclass__'), self.w_classobj)
- def enable_new_style_classes_as_default_metaclass(self):
- space = self
- try:
- self.delitem(self.builtin.w_dict, self.wrap('__metaclass__'))
- except OperationError, e:
- if not e.match(space, space.w_KeyError):
- raise
def setup_old_style_classes(self):
"""NOT_RPYTHON"""
@@ -292,6 +277,9 @@ class StdObjSpace(ObjSpace, DescrOperation):
self.w_classobj = w_classobj
self.w_instance = w_instance
+ def force_old_style_classes(self):
+ self.setitem(self.builtin.w_dict, self.wrap('__metaclass__'), self.w_classobj)
+
def create_builtin_module(self, pyname, publicname):
"""NOT_RPYTHON
helper function which returns the wrapped module and its dict.
diff --git a/pypy/objspace/std/test/test_index.py b/pypy/objspace/std/test/test_index.py
index 7482f8e73d..8ae0b2e936 100644
--- a/pypy/objspace/std/test/test_index.py
+++ b/pypy/objspace/std/test/test_index.py
@@ -3,7 +3,9 @@ from pypy.conftest import gettestobjspace
class AppTest_IndexProtocol:
def setup_class(self):
- self.space = gettestobjspace(oldstyle=True)
+ self.space = gettestobjspace()
+ self.space.force_old_style_classes()
+
w_oldstyle = self.space.appexec([], """():
class oldstyle:
def __index__(self):
diff --git a/pypy/translator/goal/app_main.py b/pypy/translator/goal/app_main.py
index a5042f1582..b3c3fa6226 100644
--- a/pypy/translator/goal/app_main.py
+++ b/pypy/translator/goal/app_main.py
@@ -3,15 +3,16 @@
# See test/test_app_main.
"""
options:
- -i inspect interactively after running script
- -O dummy optimization flag for compatibility with C Python
- -c CMD program passed in as CMD (terminates option list)
- -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
+ -i inspect interactively after running script
+ -O dummy optimization flag for compatibility with C Python
+ -c CMD program passed in as CMD (terminates option list)
+ -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)
+ -k, --oldstyle use old-style classes instead of newstyle classes everywhere
+ --version print the PyPy version
+ --info print translation information about this PyPy executable
"""
import sys, os
@@ -179,6 +180,7 @@ def entry_point(executable, argv):
i = 0
run_module = False
run_stdin = False
+ oldstyle_classes = False
while i < len(argv):
arg = argv[i]
if not arg.startswith('-'):
@@ -216,6 +218,8 @@ def entry_point(executable, argv):
return 2
run_module = True
break
+ elif arg in ('-k', '--oldstyle'):
+ oldstyle_classes = True
elif arg == '--':
i += 1
break # terminates option list
@@ -235,6 +239,10 @@ def entry_point(executable, argv):
mainmodule = type(sys)('__main__')
sys.modules['__main__'] = mainmodule
+ if oldstyle_classes:
+ import __builtin__
+ __builtin__.__metaclass__ = __builtin__._classobj
+
if import_site:
try:
import site
diff --git a/pypy/translator/goal/targetpypystandalone.py b/pypy/translator/goal/targetpypystandalone.py
index aa08b1a959..dbc0b12ea2 100644
--- a/pypy/translator/goal/targetpypystandalone.py
+++ b/pypy/translator/goal/targetpypystandalone.py
@@ -170,10 +170,6 @@ class PyPyTarget(object):
def get_entry_point(self, config):
space = make_objspace(config)
- if not config.objspace.std.oldstyle:
- # disable translation of the whole of classobjinterp.py
- StdObjSpace.setup_old_style_classes = lambda self: None
-
# manually imports app_main.py
filename = os.path.join(this_dir, 'app_main.py')
w_dict = space.newdict()