[pypy-svn] r17794 - in pypy/dist/pypy: interpreter module/sys module/sys/test
arigo at codespeak.net
arigo at codespeak.net
Fri Sep 23 15:41:54 CEST 2005
Author: arigo
Date: Fri Sep 23 15:41:45 2005
New Revision: 17794
Added:
pypy/dist/pypy/module/sys/version.py (contents, props changed)
Modified:
pypy/dist/pypy/interpreter/mixedmodule.py
pypy/dist/pypy/module/sys/__init__.py
pypy/dist/pypy/module/sys/test/test_sysmodule.py
Log:
* the svn revision number in sys.pypy_version_info should be computed
from the last checkin of the 'pypy' directory, not of the
'pypy/module/sys/__init__.py' file.
* moved version-related numbers and algorithms to module/sys/version.py.
* avoid an infinite loop in the super-Evil hack of mixedmodule.py
Modified: pypy/dist/pypy/interpreter/mixedmodule.py
==============================================================================
--- pypy/dist/pypy/interpreter/mixedmodule.py (original)
+++ pypy/dist/pypy/interpreter/mixedmodule.py Fri Sep 23 15:41:45 2005
@@ -125,8 +125,9 @@
try:
value = eval(spec, d)
except NameError, ex:
- #assert name not in d, "huh, am i looping?"
name = ex.args[0].split("'")[1] # super-Evil
+ if name in d:
+ raise # propagate the NameError
try:
d[name] = __import__(pkgroot+'.'+name, None, None, [name])
except ImportError:
Modified: pypy/dist/pypy/module/sys/__init__.py
==============================================================================
--- pypy/dist/pypy/module/sys/__init__.py (original)
+++ pypy/dist/pypy/module/sys/__init__.py Fri Sep 23 15:41:45 2005
@@ -48,13 +48,12 @@
'executable' : 'space.wrap("py.py")',
'copyright' : 'space.wrap("MIT-License")',
- 'api_version' : 'space.wrap(1012)',
- 'version_info' : 'space.wrap((2,4,1, "alpha", 42))',
- 'version' : 'space.wrap("2.4.1 (pypy 0.7.1 build)")',
- 'pypy_version_info' : """space.wrap((0,7,1, "alpha",
- int('$Revision$'[11:-1])))""",
+ 'api_version' : 'version.get_api_version(space)',
+ 'version_info' : 'version.get_version_info(space)',
+ 'version' : 'version.get_version(space)',
+ 'pypy_version_info' : 'version.get_pypy_version_info(space)',
'pypy_svn_url' : 'space.wrap("$HeadURL$"[10:-29])',
- 'hexversion' : 'space.wrap(0x020401a0)',
+ 'hexversion' : 'version.get_hexversion(space)',
'ps1' : 'space.wrap(">>>> ")',
'ps2' : 'space.wrap(".... ")',
Modified: pypy/dist/pypy/module/sys/test/test_sysmodule.py
==============================================================================
--- pypy/dist/pypy/module/sys/test/test_sysmodule.py (original)
+++ pypy/dist/pypy/module/sys/test/test_sysmodule.py Fri Sep 23 15:41:45 2005
@@ -18,34 +18,6 @@
space.sys.get('__stdout__')
class AppTestAppSysTests:
- def test_path_exists(self):
- import sys
- assert hasattr(sys, 'path'), "sys.path gone missing"
- def test_modules_exists(self):
- import sys
- assert hasattr(sys, 'modules'), "sys.modules gone missing"
- def test_dict_exists(self):
- import sys
- assert hasattr(sys, '__dict__'), "sys.__dict__ gone missing"
- def test_name_exists(self):
- import sys
- assert hasattr(sys, '__name__'), "sys.__name__ gone missing"
- def test_builtin_module_names_exists(self):
- import sys
- assert hasattr(sys, 'builtin_module_names'), (
- "sys.builtin_module_names gone missing")
- def test_warnoptions_exists(self):
- import sys
- assert hasattr(sys, 'warnoptions'), (
- "sys.warnoptions gone missing")
- def test_hexversion_exists(self):
- import sys
- assert hasattr(sys, 'hexversion'), (
- "sys.hexversion gone missing")
- def test_platform_exists(self):
- import sys
- assert hasattr(sys, 'platform'), "sys.platform gone missing"
-
def test_sys_in_modules(self):
import sys
modules = sys.modules
@@ -97,15 +69,13 @@
raise AssertionError, "ZeroDivisionError not caught"
def app_test_io():
- #space.appexec([], """():
- import sys
- assert isinstance(sys.stdout, file)
- assert isinstance(sys.__stdout__, file)
- assert isinstance(sys.stderr, file)
- assert isinstance(sys.__stderr__, file)
- assert isinstance(sys.stdin, file)
- assert isinstance(sys.__stdin__, file)
- #""")
+ import sys
+ assert isinstance(sys.stdout, file)
+ assert isinstance(sys.__stdout__, file)
+ assert isinstance(sys.stderr, file)
+ assert isinstance(sys.__stderr__, file)
+ assert isinstance(sys.stdin, file)
+ assert isinstance(sys.__stdin__, file)
class AppTestSysModulePortedFromCPython:
@@ -338,6 +308,9 @@
#)
def test_attributes(self):
+ assert sys.__name__ == 'sys'
+ assert isinstance(sys.modules, dict)
+ assert isinstance(sys.path, list)
assert isinstance(sys.api_version, int)
assert isinstance(sys.argv, list)
assert sys.byteorder in ("little", "big")
@@ -351,6 +324,7 @@
assert isinstance(sys.platform, basestring)
assert isinstance(sys.prefix, basestring)
assert isinstance(sys.version, basestring)
+ assert isinstance(sys.warnoptions, list)
vi = sys.version_info
assert isinstance(vi, tuple)
assert len(vi) == 5
@@ -373,3 +347,18 @@
finally:
sys.settrace(None)
assert len(counts) == 1
+
+ def test_pypy_attributes(self):
+ assert isinstance(sys.pypy_objspaceclass, str)
+ assert isinstance(sys.pypy_svn_url, str)
+ vi = sys.pypy_version_info
+ assert isinstance(vi, tuple)
+ assert len(vi) == 5
+ assert isinstance(vi[0], int)
+ assert isinstance(vi[1], int)
+ assert isinstance(vi[2], int)
+ assert vi[3] in ("alpha", "beta", "candidate", "final")
+ assert isinstance(vi[4], int) or vi[4] == '?'
+
+ def test_allattributes(self):
+ sys.__dict__ # check that we don't crash initializing any attribute
Added: pypy/dist/pypy/module/sys/version.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/sys/version.py Fri Sep 23 15:41:45 2005
@@ -0,0 +1,70 @@
+"""
+Version numbers exposed by PyPy through the 'sys' module.
+"""
+import os
+from pypy.interpreter import autopath
+
+
+CPYTHON_VERSION = (2, 4, 1, "alpha", 42)
+CPYTHON_API_VERSION = 1012
+
+PYPY_VERSION = (0, 7, 1, "alpha", '?')
+# the last item is replaced by the svn revision ^^^
+
+
+# ____________________________________________________________
+
+def get_api_version(space):
+ return space.wrap(CPYTHON_API_VERSION)
+
+def get_version_info(space):
+ return space.wrap(CPYTHON_VERSION)
+
+def get_version(space):
+ return space.wrap("%d.%d.%d (pypy %d.%d.%d build)" % (
+ CPYTHON_VERSION[0],
+ CPYTHON_VERSION[1],
+ CPYTHON_VERSION[2],
+ PYPY_VERSION[0],
+ PYPY_VERSION[1],
+ PYPY_VERSION[2]))
+
+def get_hexversion(space):
+ return space.wrap(tuple2hex(CPYTHON_VERSION))
+
+def get_pypy_version_info(space):
+ ver = PYPY_VERSION
+ ver = ver[:-1] + (svn_revision(),)
+ return space.wrap(ver)
+
+def tuple2hex(ver):
+ d = {'alpha': 0xA,
+ 'beta': 0xB,
+ 'candidate': 0xC,
+ 'final': 0xF,
+ }
+ subver = ver[4]
+ if not (0 <= subver <= 9):
+ subver = 0
+ return (ver[0] << 24 |
+ ver[1] << 16 |
+ ver[2] << 8 |
+ d[ver[3]] << 4 |
+ subver)
+
+def svn_revision():
+ "Return the last-changed svn revision number."
+ # NB. we hack the number directly out of the .svn directory to avoid
+ # to depend on an external 'svn' executable in the path.
+ rev = '?'
+ try:
+ f = open(os.path.join(autopath.pypydir, '.svn', 'entries'), 'r')
+ for line in f:
+ line = line.strip()
+ if line.startswith('committed-rev="') and line.endswith('"'):
+ rev = int(line[15:-1])
+ break
+ f.close()
+ except (IOError, OSError):
+ pass
+ return rev
More information about the Pypy-commit
mailing list