[pypy-svn] r69120 - in pypy/branch/py11/pypy: . annotation/test bin config config/test doc doc/config doc/statistic jit/backend jit/backend/x86 jit/tl jit/tl/spli jit/tl/test jit/tool lang/gameboy/tool lang/js lang/js/test/ecma lang/prolog/interpreter lang/scheme lang/smalltalk/tool lib/distributed lib/test2 module/__builtin__/test module/_codecs/test module/_sre/test module/sys/test rlib/parsing/test rlib/rsdl/test rpython/microbench tool tool/algo/test tool/pytest tool/rest tool/test translator translator/benchmark translator/c translator/c/test translator/cli/test translator/goal translator/goal/test2 translator/microbench/pybench translator/platform translator/sandbox translator/sandbox/test translator/test translator/tool
hpk at codespeak.net
hpk at codespeak.net
Tue Nov 10 16:01:03 CET 2009
Author: hpk
Date: Tue Nov 10 16:01:00 2009
New Revision: 69120
Added:
pypy/branch/py11/pypy/tool/difftime.py (contents, props changed)
pypy/branch/py11/pypy/tool/rest/
pypy/branch/py11/pypy/tool/rest/__init__.py (contents, props changed)
pypy/branch/py11/pypy/tool/rest/convert.py (contents, props changed)
pypy/branch/py11/pypy/tool/rest/directive.py (contents, props changed)
pypy/branch/py11/pypy/tool/rest/rest.py (contents, props changed)
pypy/branch/py11/pypy/tool/rest/rst.py (contents, props changed)
Modified:
pypy/branch/py11/pypy/annotation/test/autopath.py
pypy/branch/py11/pypy/bin/autopath.py
pypy/branch/py11/pypy/config/autopath.py
pypy/branch/py11/pypy/config/makerestdoc.py
pypy/branch/py11/pypy/config/test/test_makerestdoc.py
pypy/branch/py11/pypy/conftest.py
pypy/branch/py11/pypy/doc/config/autopath.py
pypy/branch/py11/pypy/doc/confrest_oldpy.py
pypy/branch/py11/pypy/doc/statistic/confrest.py
pypy/branch/py11/pypy/jit/backend/autopath.py
pypy/branch/py11/pypy/jit/backend/x86/autopath.py
pypy/branch/py11/pypy/jit/tl/autopath.py
pypy/branch/py11/pypy/jit/tl/spli/autopath.py
pypy/branch/py11/pypy/jit/tl/test/test_pypyjit.py
pypy/branch/py11/pypy/jit/tool/autopath.py
pypy/branch/py11/pypy/lang/gameboy/tool/autopath.py
pypy/branch/py11/pypy/lang/js/autopath.py
pypy/branch/py11/pypy/lang/js/test/ecma/conftest.py
pypy/branch/py11/pypy/lang/prolog/interpreter/autopath.py
pypy/branch/py11/pypy/lang/scheme/autopath.py
pypy/branch/py11/pypy/lang/smalltalk/tool/autopath.py
pypy/branch/py11/pypy/lib/distributed/socklayer.py
pypy/branch/py11/pypy/lib/test2/autopath.py
pypy/branch/py11/pypy/module/__builtin__/test/autopath.py
pypy/branch/py11/pypy/module/_codecs/test/autopath.py
pypy/branch/py11/pypy/module/_sre/test/autopath.py
pypy/branch/py11/pypy/module/_sre/test/test_app_sre.py
pypy/branch/py11/pypy/module/sys/test/autopath.py
pypy/branch/py11/pypy/rlib/parsing/test/autopath.py
pypy/branch/py11/pypy/rlib/rsdl/test/autopath.py
pypy/branch/py11/pypy/rpython/microbench/autopath.py
pypy/branch/py11/pypy/test_all.py
pypy/branch/py11/pypy/tool/algo/test/autopath.py
pypy/branch/py11/pypy/tool/ansi_mandelbrot.py
pypy/branch/py11/pypy/tool/ansi_print.py
pypy/branch/py11/pypy/tool/autopath.py
pypy/branch/py11/pypy/tool/genstatistic.py
pypy/branch/py11/pypy/tool/pytest/appsupport.py
pypy/branch/py11/pypy/tool/pytest/autopath.py
pypy/branch/py11/pypy/tool/statistic_over_time.py
pypy/branch/py11/pypy/tool/test/autopath.py
pypy/branch/py11/pypy/tool/test/test_pytestsupport.py
pypy/branch/py11/pypy/translator/autopath.py
pypy/branch/py11/pypy/translator/benchmark/autopath.py
pypy/branch/py11/pypy/translator/c/autopath.py
pypy/branch/py11/pypy/translator/c/test/autopath.py
pypy/branch/py11/pypy/translator/cli/test/autopath.py
pypy/branch/py11/pypy/translator/goal/autopath.py
pypy/branch/py11/pypy/translator/goal/test2/autopath.py
pypy/branch/py11/pypy/translator/microbench/pybench/autopath.py
pypy/branch/py11/pypy/translator/platform/__init__.py
pypy/branch/py11/pypy/translator/sandbox/autopath.py
pypy/branch/py11/pypy/translator/sandbox/test/autopath.py
pypy/branch/py11/pypy/translator/test/autopath.py
pypy/branch/py11/pypy/translator/tool/autopath.py
Log:
* put some internal rest-related and
doc-generation files that pypy relied on
into pypy/tool/rest
* use pytest-1.1' py.impl.* instead of py.__ magic
* have autopath look for "pypy" for import tweaks
Modified: pypy/branch/py11/pypy/annotation/test/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/annotation/test/autopath.py (original)
+++ pypy/branch/py11/pypy/annotation/test/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/bin/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/bin/autopath.py (original)
+++ pypy/branch/py11/pypy/bin/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/config/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/config/autopath.py (original)
+++ pypy/branch/py11/pypy/config/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/config/makerestdoc.py
==============================================================================
--- pypy/branch/py11/pypy/config/makerestdoc.py (original)
+++ pypy/branch/py11/pypy/config/makerestdoc.py Tue Nov 10 16:01:00 2009
@@ -1,6 +1,6 @@
import py
-from py.__.rest.rst import Rest, Paragraph, Strong, ListItem, Title, Link
-from py.__.rest.rst import Directive, Em, Quote, Text
+from pypy.tool.rest.rst import Rest, Paragraph, Strong, ListItem, Title, Link
+from pypy.tool.rest.rst import Directive, Em, Quote, Text
from pypy.config.config import ChoiceOption, BoolOption, StrOption, IntOption
from pypy.config.config import FloatOption, OptionDescription, Option, Config
@@ -212,7 +212,7 @@
""" register a :config: ReST link role for use in documentation. """
try:
from docutils.parsers.rst import directives, states, roles
- from py.__.rest.directive import register_linkrole
+ from py.impl.rest.directive import register_linkrole
except ImportError:
return
# enable :config: link role
Modified: pypy/branch/py11/pypy/config/test/test_makerestdoc.py
==============================================================================
--- pypy/branch/py11/pypy/config/test/test_makerestdoc.py (original)
+++ pypy/branch/py11/pypy/config/test/test_makerestdoc.py Tue Nov 10 16:01:00 2009
@@ -1,7 +1,7 @@
from pypy.config.config import *
from pypy.config.makerestdoc import make_cmdline_overview
-from py.__.misc.rest import process as restcheck
+from pypy.tool.rest.rest import process as restcheck
tempdir = py.test.ensuretemp('config')
Modified: pypy/branch/py11/pypy/conftest.py
==============================================================================
--- pypy/branch/py11/pypy/conftest.py (original)
+++ pypy/branch/py11/pypy/conftest.py Tue Nov 10 16:01:00 2009
@@ -1,5 +1,5 @@
import py, sys, os
-from py.__.test.outcome import Failed
+from py.impl.test.outcome import Failed
from pypy.interpreter.gateway import app2interp_temp
from pypy.interpreter.error import OperationError
from pypy.tool.pytest import appsupport
Modified: pypy/branch/py11/pypy/doc/config/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/doc/config/autopath.py (original)
+++ pypy/branch/py11/pypy/doc/config/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/doc/confrest_oldpy.py
==============================================================================
--- pypy/branch/py11/pypy/doc/confrest_oldpy.py (original)
+++ pypy/branch/py11/pypy/doc/confrest_oldpy.py Tue Nov 10 16:01:00 2009
@@ -1,6 +1,6 @@
import py
-from py.__.misc.rest import convert_rest_html, strip_html_header
-from py.__.misc.difftime import worded_time
+from pypy.tool.rest.rest import convert_rest_html, strip_html_header
+from pypy.tool.difftime import worded_time
html = py.xml.html
Modified: pypy/branch/py11/pypy/doc/statistic/confrest.py
==============================================================================
--- pypy/branch/py11/pypy/doc/statistic/confrest.py (original)
+++ pypy/branch/py11/pypy/doc/statistic/confrest.py Tue Nov 10 16:01:00 2009
@@ -1,5 +1,5 @@
import py
-from py.__.doc.confrest import *
+from py.impl.doc.confrest import *
class PyPyPage(Page):
def fill_menubar(self):
Modified: pypy/branch/py11/pypy/jit/backend/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/jit/backend/autopath.py (original)
+++ pypy/branch/py11/pypy/jit/backend/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/jit/backend/x86/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/jit/backend/x86/autopath.py (original)
+++ pypy/branch/py11/pypy/jit/backend/x86/autopath.py Tue Nov 10 16:01:00 2009
@@ -21,7 +21,6 @@
"""
-
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
into sys.path. If the parent directories don't have the part
@@ -33,13 +32,31 @@
except NameError:
head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
+ error = None
while head:
partdir = head
head, tail = os.path.split(head)
if tail == part:
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
+ if not os.path.exists(checkfile):
+ error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
else:
- raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+ error = "Cannot find the parent directory %r of the path %r" % (
+ partdir, this_dir)
+ if not error:
+ # check for bogus end-of-line style (e.g. files checked out on
+ # Windows and moved to Unix)
+ f = open(__file__.replace('.pyc', '.py'), 'r')
+ data = f.read()
+ f.close()
+ if data.endswith('\r\n') or data.endswith('\r'):
+ error = ("Bad end-of-line style in the .py files. Typically "
+ "caused by a zip file or a checkout done on Windows and "
+ "moved to Unix or vice-versa.")
+ if error:
+ raise EnvironmentError("Invalid source tree - bogus checkout! " +
+ error)
pypy_root = os.path.join(head, '')
try:
@@ -109,6 +126,9 @@
# set guaranteed attributes
pypydir, this_dir = __dirinfo('pypy')
+import py
+libpythondir = str(py.path.local(pypydir).dirpath().join('lib-python', '2.5.2'))
+libpythonmodifieddir = str(py.path.local(libpythondir).dirpath().join('modified-2.5.2'))
if __name__ == '__main__':
__clone()
Modified: pypy/branch/py11/pypy/jit/tl/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/jit/tl/autopath.py (original)
+++ pypy/branch/py11/pypy/jit/tl/autopath.py Tue Nov 10 16:01:00 2009
@@ -21,7 +21,6 @@
"""
-
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
into sys.path. If the parent directories don't have the part
@@ -33,13 +32,31 @@
except NameError:
head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
+ error = None
while head:
partdir = head
head, tail = os.path.split(head)
if tail == part:
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
+ if not os.path.exists(checkfile):
+ error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
else:
- raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+ error = "Cannot find the parent directory %r of the path %r" % (
+ partdir, this_dir)
+ if not error:
+ # check for bogus end-of-line style (e.g. files checked out on
+ # Windows and moved to Unix)
+ f = open(__file__.replace('.pyc', '.py'), 'r')
+ data = f.read()
+ f.close()
+ if data.endswith('\r\n') or data.endswith('\r'):
+ error = ("Bad end-of-line style in the .py files. Typically "
+ "caused by a zip file or a checkout done on Windows and "
+ "moved to Unix or vice-versa.")
+ if error:
+ raise EnvironmentError("Invalid source tree - bogus checkout! " +
+ error)
pypy_root = os.path.join(head, '')
try:
@@ -109,6 +126,9 @@
# set guaranteed attributes
pypydir, this_dir = __dirinfo('pypy')
+import py
+libpythondir = str(py.path.local(pypydir).dirpath().join('lib-python', '2.5.2'))
+libpythonmodifieddir = str(py.path.local(libpythondir).dirpath().join('modified-2.5.2'))
if __name__ == '__main__':
__clone()
Modified: pypy/branch/py11/pypy/jit/tl/spli/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/jit/tl/spli/autopath.py (original)
+++ pypy/branch/py11/pypy/jit/tl/spli/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/jit/tl/test/test_pypyjit.py
==============================================================================
--- pypy/branch/py11/pypy/jit/tl/test/test_pypyjit.py (original)
+++ pypy/branch/py11/pypy/jit/tl/test/test_pypyjit.py Tue Nov 10 16:01:00 2009
@@ -21,7 +21,7 @@
def check_crasher(func_name):
try:
JIT_EXECUTABLE.sysexec(CRASH_FILE, func_name)
- except py.__.process.cmdexec.ExecutionFailed, e:
+ except py.impl.process.cmdexec.ExecutionFailed, e:
print "stderr"
print "------"
print e.err
Modified: pypy/branch/py11/pypy/jit/tool/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/jit/tool/autopath.py (original)
+++ pypy/branch/py11/pypy/jit/tool/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/lang/gameboy/tool/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/lang/gameboy/tool/autopath.py (original)
+++ pypy/branch/py11/pypy/lang/gameboy/tool/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/lang/js/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/lang/js/autopath.py (original)
+++ pypy/branch/py11/pypy/lang/js/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/lang/js/test/ecma/conftest.py
==============================================================================
--- pypy/branch/py11/pypy/lang/js/test/ecma/conftest.py (original)
+++ pypy/branch/py11/pypy/lang/js/test/ecma/conftest.py Tue Nov 10 16:01:00 2009
@@ -2,7 +2,7 @@
from pypy.lang.js.interpreter import *
from pypy.lang.js.jsobj import W_Array, JsBaseExcept
from pypy.rlib.parsing.parsing import ParseError
-from py.__.test.outcome import Failed, ExceptionFailure
+from py.impl.test.outcome import Failed, ExceptionFailure
import pypy.lang.js as js
from pypy.lang.js import interpreter
Modified: pypy/branch/py11/pypy/lang/prolog/interpreter/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/lang/prolog/interpreter/autopath.py (original)
+++ pypy/branch/py11/pypy/lang/prolog/interpreter/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/lang/scheme/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/lang/scheme/autopath.py (original)
+++ pypy/branch/py11/pypy/lang/scheme/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/lang/smalltalk/tool/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/lang/smalltalk/tool/autopath.py (original)
+++ pypy/branch/py11/pypy/lang/smalltalk/tool/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/lib/distributed/socklayer.py
==============================================================================
--- pypy/branch/py11/pypy/lib/distributed/socklayer.py (original)
+++ pypy/branch/py11/pypy/lib/distributed/socklayer.py Tue Nov 10 16:01:00 2009
@@ -1,7 +1,7 @@
import py
from socket import socket
-from py.__.green.msgstruct import decodemessage, message
+from py.impl.green.msgstruct import decodemessage, message
from socket import socket, AF_INET, SOCK_STREAM
import marshal
import sys
Modified: pypy/branch/py11/pypy/lib/test2/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/lib/test2/autopath.py (original)
+++ pypy/branch/py11/pypy/lib/test2/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/module/__builtin__/test/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/module/__builtin__/test/autopath.py (original)
+++ pypy/branch/py11/pypy/module/__builtin__/test/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/module/_codecs/test/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/module/_codecs/test/autopath.py (original)
+++ pypy/branch/py11/pypy/module/_codecs/test/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/module/_sre/test/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/module/_sre/test/autopath.py (original)
+++ pypy/branch/py11/pypy/module/_sre/test/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/module/_sre/test/test_app_sre.py
==============================================================================
--- pypy/branch/py11/pypy/module/_sre/test/test_app_sre.py (original)
+++ pypy/branch/py11/pypy/module/_sre/test/test_app_sre.py Tue Nov 10 16:01:00 2009
@@ -3,7 +3,7 @@
from py.test import raises, skip
from pypy.interpreter.gateway import app2interp_temp
from pypy.conftest import gettestobjspace, option
-from py.__.test.outcome import Skipped
+from py.impl.test.outcome import Skipped
def init_globals_hack(space):
space.appexec([space.wrap(autopath.this_dir)], """(this_dir):
Modified: pypy/branch/py11/pypy/module/sys/test/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/module/sys/test/autopath.py (original)
+++ pypy/branch/py11/pypy/module/sys/test/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/rlib/parsing/test/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/rlib/parsing/test/autopath.py (original)
+++ pypy/branch/py11/pypy/rlib/parsing/test/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/rlib/rsdl/test/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/rlib/rsdl/test/autopath.py (original)
+++ pypy/branch/py11/pypy/rlib/rsdl/test/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/rpython/microbench/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/rpython/microbench/autopath.py (original)
+++ pypy/branch/py11/pypy/rpython/microbench/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/test_all.py
==============================================================================
--- pypy/branch/py11/pypy/test_all.py (original)
+++ pypy/branch/py11/pypy/test_all.py Tue Nov 10 16:01:00 2009
@@ -1,6 +1,6 @@
#! /usr/bin/env python
-if __name__ == '__main__':
+if __name__ == '__main__':
import tool.autopath
- import py
- py.test.cmdline.main()
+ import py
+ py.cmdline.pytest()
Modified: pypy/branch/py11/pypy/tool/algo/test/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/tool/algo/test/autopath.py (original)
+++ pypy/branch/py11/pypy/tool/algo/test/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/tool/ansi_mandelbrot.py
==============================================================================
--- pypy/branch/py11/pypy/tool/ansi_mandelbrot.py (original)
+++ pypy/branch/py11/pypy/tool/ansi_mandelbrot.py Tue Nov 10 16:01:00 2009
@@ -1,6 +1,6 @@
import sys
-from py.__.io.terminalwriter import ansi_print, get_terminal_width
+from py.impl.io.terminalwriter import ansi_print, get_terminal_width
"""
Black 0;30 Dark Gray 1;30
Modified: pypy/branch/py11/pypy/tool/ansi_print.py
==============================================================================
--- pypy/branch/py11/pypy/tool/ansi_print.py (original)
+++ pypy/branch/py11/pypy/tool/ansi_print.py Tue Nov 10 16:01:00 2009
@@ -4,7 +4,7 @@
import sys
-from py.__.io.terminalwriter import ansi_print
+from py.impl.io.terminalwriter import ansi_print
from pypy.tool.ansi_mandelbrot import Driver
class AnsiLog:
Modified: pypy/branch/py11/pypy/tool/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/tool/autopath.py (original)
+++ pypy/branch/py11/pypy/tool/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Added: pypy/branch/py11/pypy/tool/difftime.py
==============================================================================
--- (empty file)
+++ pypy/branch/py11/pypy/tool/difftime.py Tue Nov 10 16:01:00 2009
@@ -0,0 +1,32 @@
+import py
+
+_time_desc = {
+ 1 : 'second', 60 : 'minute', 3600 : 'hour', 86400 : 'day',
+ 2628000 : 'month', 31536000 : 'year', }
+
+def worded_diff_time(ctime):
+ difftime = py.std.time.time() - ctime
+ keys = _time_desc.keys()
+ keys.sort()
+ for i, key in py.builtin.enumerate(keys):
+ if key >=difftime:
+ break
+ l = []
+ keylist = keys[:i]
+
+ keylist.reverse()
+ for key in keylist[:1]:
+ div = int(difftime / key)
+ if div==0:
+ break
+ difftime -= div * key
+ plural = div > 1 and 's' or ''
+ l.append('%d %s%s' %(div, _time_desc[key], plural))
+ return ", ".join(l) + " ago "
+
+_months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
+ 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
+
+def worded_time(ctime):
+ tm = py.std.time.gmtime(ctime)
+ return "%s %d, %d" % (_months[tm.tm_mon-1], tm.tm_mday, tm.tm_year)
Modified: pypy/branch/py11/pypy/tool/genstatistic.py
==============================================================================
--- pypy/branch/py11/pypy/tool/genstatistic.py (original)
+++ pypy/branch/py11/pypy/tool/genstatistic.py Tue Nov 10 16:01:00 2009
@@ -1,7 +1,7 @@
import autopath
import py
-from py.__.misc.cmdline import countloc
+from py.impl.misc.cmdline import countloc
from py.xml import raw
pypydir = py.path.local(autopath.pypydir)
Modified: pypy/branch/py11/pypy/tool/pytest/appsupport.py
==============================================================================
--- pypy/branch/py11/pypy/tool/pytest/appsupport.py (original)
+++ pypy/branch/py11/pypy/tool/pytest/appsupport.py Tue Nov 10 16:01:00 2009
@@ -1,9 +1,10 @@
import autopath
import py
-from py.__.magic import exprinfo
+import py.impl.code.assertion
+from py.impl.code import _assertionold as exprinfo
from pypy.interpreter import gateway
from pypy.interpreter.error import OperationError
-from py.__.test.outcome import ExceptionFailure
+from py.impl.test.outcome import ExceptionFailure
# ____________________________________________________________
Modified: pypy/branch/py11/pypy/tool/pytest/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/tool/pytest/autopath.py (original)
+++ pypy/branch/py11/pypy/tool/pytest/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Added: pypy/branch/py11/pypy/tool/rest/__init__.py
==============================================================================
Added: pypy/branch/py11/pypy/tool/rest/convert.py
==============================================================================
--- (empty file)
+++ pypy/branch/py11/pypy/tool/rest/convert.py Tue Nov 10 16:01:00 2009
@@ -0,0 +1,163 @@
+import py
+
+ExecutionFailed = py.process.cmdexec.Error
+# utility functions to convert between various formats
+
+format_to_dotargument = {"png": "png",
+ "eps": "ps",
+ "ps": "ps",
+ "pdf": "ps",
+ }
+
+def ps2eps(ps):
+ # XXX write a pure python version
+ if not py.path.local.sysfind("ps2epsi") and \
+ not py.path.local.sysfind("ps2eps"):
+ raise SystemExit("neither ps2eps nor ps2epsi found")
+ try:
+ eps = ps.new(ext=".eps")
+ py.process.cmdexec('ps2epsi "%s" "%s"' % (ps, eps))
+ except ExecutionFailed:
+ py.process.cmdexec('ps2eps -l -f "%s"' % ps)
+
+def ps2pdf(ps, compat_level="1.2"):
+ if not py.path.local.sysfind("gs"):
+ raise SystemExit("ERROR: gs not found")
+ pdf = ps.new(ext=".pdf")
+ options = dict(OPTIONS="-dSAFER -dCompatibilityLevel=%s" % compat_level,
+ infile=ps, outfile=pdf)
+ cmd = ('gs %(OPTIONS)s -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite '
+ '"-sOutputFile=%(outfile)s" %(OPTIONS)s -c .setpdfwrite '
+ '-f "%(infile)s"') % options
+ py.process.cmdexec(cmd)
+ return pdf
+
+def eps2pdf(eps):
+ # XXX write a pure python version
+ if not py.path.local.sysfind("epstopdf"):
+ raise SystemExit("ERROR: epstopdf not found")
+ py.process.cmdexec('epstopdf "%s"' % eps)
+
+def dvi2eps(dvi, dest=None):
+ if dest is None:
+ dest = eps.new(ext=".eps")
+ command = 'dvips -q -E -n 1 -D 600 -p 1 -o "%s" "%s"' % (dest, dvi)
+ if not py.path.local.sysfind("dvips"):
+ raise SystemExit("ERROR: dvips not found")
+ py.process.cmdexec(command)
+
+def convert_dot(fn, new_extension):
+ if not py.path.local.sysfind("dot"):
+ raise SystemExit("ERROR: dot not found")
+ result = fn.new(ext=new_extension)
+ print result
+ arg = "-T%s" % (format_to_dotargument[new_extension], )
+ py.std.os.system('dot "%s" "%s" > "%s"' % (arg, fn, result))
+ if new_extension == "eps":
+ ps = result.new(ext="ps")
+ result.move(ps)
+ ps2eps(ps)
+ ps.remove()
+ elif new_extension == "pdf":
+ # convert to eps file first, to get the bounding box right
+ eps = result.new(ext="eps")
+ ps = result.new(ext="ps")
+ result.move(ps)
+ ps2eps(ps)
+ eps2pdf(eps)
+ ps.remove()
+ eps.remove()
+ return result
+
+
+class latexformula2png(object):
+ def __init__(self, formula, dest, temp=None):
+ self.formula = formula
+ try:
+ import Image
+ self.Image = Image
+ self.scale = 2 # create a larger image
+ self.upscale = 5 # create the image upscale times larger, then scale it down
+ except ImportError:
+ self.scale = 2
+ self.upscale = 1
+ self.Image = None
+ self.output_format = ('pngmono', 'pnggray', 'pngalpha')[2]
+ if temp is None:
+ temp = py.test.ensuretemp("latexformula")
+ self.temp = temp
+ self.latex = self.temp.join('formula.tex')
+ self.dvi = self.temp.join('formula.dvi')
+ self.eps = self.temp.join('formula.eps')
+ self.png = self.temp.join('formula.png')
+ self.saveas(dest)
+
+ def saveas(self, dest):
+ self.gen_latex()
+ self.gen_dvi()
+ dvi2eps(self.dvi, self.eps)
+ self.gen_png()
+ self.scale_image()
+ self.png.copy(dest)
+
+ def gen_latex(self):
+ self.latex.write ("""
+ \\documentclass{article}
+ \\pagestyle{empty}
+ \\begin{document}
+
+ %s
+ \\pagebreak
+
+ \\end{document}
+ """ % (self.formula))
+
+ def gen_dvi(self):
+ origdir = py.path.local()
+ self.temp.chdir()
+ py.process.cmdexec('latex "%s"' % (self.latex))
+ origdir.chdir()
+
+ def gen_png(self):
+ tempdir = py.path.local.mkdtemp()
+
+ re_bbox = py.std.re.compile('%%BoundingBox:\s*(\d+) (\d+) (\d+) (\d+)')
+ eps = self.eps.read()
+ x1, y1, x2, y2 = [int(i) for i in re_bbox.search(eps).groups()]
+ X = x2 - x1 + 2
+ Y = y2 - y1 + 2
+ mx = -x1
+ my = -y1
+ ps = self.temp.join('temp.ps')
+ source = self.eps
+ ps.write("""
+ 1 1 1 setrgbcolor
+ newpath
+ -1 -1 moveto
+ %(X)d -1 lineto
+ %(X)d %(Y)d lineto
+ -1 %(Y)d lineto
+ closepath
+ fill
+ %(mx)d %(my)d translate
+ 0 0 0 setrgbcolor
+ (%(source)s) run
+
+ """ % locals())
+
+ sx = int((x2 - x1) * self.scale * self.upscale)
+ sy = int((y2 - y1) * self.scale * self.upscale)
+ res = 72 * self.scale * self.upscale
+ command = ('gs -q -g%dx%d -r%dx%d -sDEVICE=%s -sOutputFile="%s" '
+ '-dNOPAUSE -dBATCH "%s"') % (
+ sx, sy, res, res, self.output_format, self.png, ps)
+ py.process.cmdexec(command)
+
+ def scale_image(self):
+ if self.Image is None:
+ return
+ image = self.Image.open(str(self.png))
+ image.resize((image.size[0] / self.upscale,
+ image.size[1] / self.upscale),
+ self.Image.ANTIALIAS).save(str(self.png))
+
Added: pypy/branch/py11/pypy/tool/rest/directive.py
==============================================================================
--- (empty file)
+++ pypy/branch/py11/pypy/tool/rest/directive.py Tue Nov 10 16:01:00 2009
@@ -0,0 +1,115 @@
+# XXX this file is messy since it tries to deal with several docutils versions
+import py
+
+from pypy.tool.rest.convert import convert_dot, latexformula2png
+
+import sys
+import docutils
+from docutils import nodes
+from docutils.parsers.rst import directives, states, roles
+from docutils.parsers.rst.directives import images
+
+if hasattr(images, "image"):
+ directives_are_functions = True
+else:
+ directives_are_functions = False
+
+try:
+ from docutils.utils import unescape # docutils version > 0.3.5
+except ImportError:
+ from docutils.parsers.rst.states import unescape # docutils 0.3.5
+
+if not directives_are_functions:
+ ImageClass = images.Image
+
+else:
+ class ImageClass(object):
+ option_spec = images.image.options
+ def run(self):
+ return images.image(u'image',
+ self.arguments,
+ self.options,
+ self.content,
+ self.lineno,
+ self.content_offset,
+ self.block_text,
+ self.state,
+ self.state_machine)
+
+
+backend_to_image_format = {"html": "png", "latex": "pdf"}
+
+class GraphvizDirective(ImageClass):
+ def convert(self, fn, path):
+ path = py.path.local(path).dirpath()
+ dot = path.join(fn)
+ result = convert_dot(dot, backend_to_image_format[_backend])
+ return result.relto(path)
+
+ def run(self):
+ newname = self.convert(self.arguments[0],
+ self.state.document.settings._source)
+ text = self.block_text.replace("graphviz", "image", 1)
+ self.block_text = text.replace(self.arguments[0], newname, 1)
+ self.name = u'image'
+ self.arguments = [newname]
+ return ImageClass.run(self)
+
+ def old_interface(self):
+ def f(name, arguments, options, content, lineno,
+ content_offset, block_text, state, state_machine):
+ for arg in "name arguments options content lineno " \
+ "content_offset block_text state state_machine".split():
+ setattr(self, arg, locals()[arg])
+ return self.run()
+ f.arguments = (1, 0, 1)
+ f.options = self.option_spec
+ return f
+
+
+_backend = None
+def set_backend_and_register_directives(backend):
+ #XXX this is only used to work around the inflexibility of docutils:
+ # a directive does not know the target format
+ global _backend
+ _backend = backend
+ if not directives_are_functions:
+ directives.register_directive("graphviz", GraphvizDirective)
+ else:
+ directives.register_directive("graphviz",
+ GraphvizDirective().old_interface())
+ roles.register_canonical_role("latexformula", latexformula_role)
+
+def latexformula_role(name, rawtext, text, lineno, inliner,
+ options={}, content=[]):
+ if _backend == 'latex':
+ options['format'] = 'latex'
+ return roles.raw_role(name, rawtext, text, lineno, inliner,
+ options, content)
+ else:
+ # XXX: make the place of the image directory configurable
+ sourcedir = py.path.local(inliner.document.settings._source).dirpath()
+ imagedir = sourcedir.join("img")
+ if not imagedir.check():
+ imagedir.mkdir()
+ # create halfway senseful imagename:
+ # use hash of formula + alphanumeric characters of it
+ # could
+ imagename = "%s_%s.png" % (
+ hash(text), "".join([c for c in text if c.isalnum()]))
+ image = imagedir.join(imagename)
+ latexformula2png(unescape(text, True), image)
+ imagenode = nodes.image(image.relto(sourcedir), uri=image.relto(sourcedir))
+ return [imagenode], []
+latexformula_role.content = True
+latexformula_role.options = {}
+
+def register_linkrole(role_name, callback):
+ def source_role(name, rawtext, text, lineno, inliner, options={},
+ content=[]):
+ text, target = callback(name, text)
+ reference_node = nodes.reference(rawtext, text, name=text, refuri=target)
+ return [reference_node], []
+ source_role.content = True
+ source_role.options = {}
+ roles.register_canonical_role(role_name, source_role)
Added: pypy/branch/py11/pypy/tool/rest/rest.py
==============================================================================
--- (empty file)
+++ pypy/branch/py11/pypy/tool/rest/rest.py Tue Nov 10 16:01:00 2009
@@ -0,0 +1,81 @@
+import py
+import sys, os, traceback
+import re
+
+if hasattr(sys.stdout, 'fileno') and os.isatty(sys.stdout.fileno()):
+ def log(msg):
+ print msg
+else:
+ def log(msg):
+ pass
+
+def convert_rest_html(source, source_path, stylesheet=None, encoding='latin1'):
+ from pypy.tool.rest import directive
+ """ return html latin1-encoded document for the given input.
+ source a ReST-string
+ sourcepath where to look for includes (basically)
+ stylesheet path (to be used if any)
+ """
+ from docutils.core import publish_string
+ directive.set_backend_and_register_directives("html")
+ kwargs = {
+ 'stylesheet' : stylesheet,
+ 'stylesheet_path': None,
+ 'traceback' : 1,
+ 'embed_stylesheet': 0,
+ 'output_encoding' : encoding,
+ #'halt' : 0, # 'info',
+ 'halt_level' : 2,
+ }
+ # docutils uses os.getcwd() :-(
+ source_path = os.path.abspath(str(source_path))
+ prevdir = os.getcwd()
+ try:
+ #os.chdir(os.path.dirname(source_path))
+ return publish_string(source, source_path, writer_name='html',
+ settings_overrides=kwargs)
+ finally:
+ os.chdir(prevdir)
+
+def process(txtpath, encoding='latin1'):
+ """ process a textfile """
+ log("processing %s" % txtpath)
+ assert txtpath.check(ext='.txt')
+ if isinstance(txtpath, py.path.svnwc):
+ txtpath = txtpath.localpath
+ htmlpath = txtpath.new(ext='.html')
+ #svninfopath = txtpath.localpath.new(ext='.svninfo')
+
+ style = txtpath.dirpath('style.css')
+ if style.check():
+ stylesheet = style.basename
+ else:
+ stylesheet = None
+ content = unicode(txtpath.read(), encoding)
+ doc = convert_rest_html(content, txtpath, stylesheet=stylesheet, encoding=encoding)
+ htmlpath.write(doc)
+ #log("wrote %r" % htmlpath)
+ #if txtpath.check(svnwc=1, versioned=1):
+ # info = txtpath.info()
+ # svninfopath.dump(info)
+
+rex1 = re.compile(ur'.*<body>(.*)</body>.*', re.MULTILINE | re.DOTALL)
+rex2 = re.compile(ur'.*<div class="document">(.*)</div>.*', re.MULTILINE | re.DOTALL)
+
+def strip_html_header(string, encoding='utf8'):
+ """ return the content of the body-tag """
+ uni = unicode(string, encoding)
+ for rex in rex1,rex2:
+ match = rex.search(uni)
+ if not match:
+ break
+ uni = match.group(1)
+ return uni
+
+class Project: # used for confrest.py files
+ def __init__(self, sourcepath):
+ self.sourcepath = sourcepath
+ def process(self, path):
+ return process(path)
+ def get_htmloutputpath(self, path):
+ return path.new(ext='html')
Added: pypy/branch/py11/pypy/tool/rest/rst.py
==============================================================================
--- (empty file)
+++ pypy/branch/py11/pypy/tool/rest/rst.py Tue Nov 10 16:01:00 2009
@@ -0,0 +1,417 @@
+
+""" reStructuredText generation tools
+
+ provides an api to build a tree from nodes, which can be converted to
+ ReStructuredText on demand
+
+ note that not all of ReST is supported, a usable subset is offered, but
+ certain features aren't supported, and also certain details (like how links
+ are generated, or how escaping is done) can not be controlled
+"""
+
+from __future__ import generators
+
+import py
+
+def escape(txt):
+ """escape ReST markup"""
+ if not isinstance(txt, str) and not isinstance(txt, unicode):
+ txt = str(txt)
+ # XXX this takes a very naive approach to escaping, but it seems to be
+ # sufficient...
+ for c in '\\*`|:_':
+ txt = txt.replace(c, '\\%s' % (c,))
+ return txt
+
+class RestError(Exception):
+ """ raised on containment errors (wrong parent) """
+
+class AbstractMetaclass(type):
+ def __new__(cls, *args):
+ obj = super(AbstractMetaclass, cls).__new__(cls, *args)
+ parent_cls = obj.parentclass
+ if parent_cls is None:
+ return obj
+ if not isinstance(parent_cls, list):
+ class_list = [parent_cls]
+ else:
+ class_list = parent_cls
+ if obj.allow_nesting:
+ class_list.append(obj)
+
+ for _class in class_list:
+ if not _class.allowed_child:
+ _class.allowed_child = {obj:True}
+ else:
+ _class.allowed_child[obj] = True
+ return obj
+
+class AbstractNode(object):
+ """ Base class implementing rest generation
+ """
+ sep = ''
+ __metaclass__ = AbstractMetaclass
+ parentclass = None # this exists to allow parent to know what
+ # children can exist
+ allow_nesting = False
+ allowed_child = {}
+ defaults = {}
+
+ _reg_whitespace = py.std.re.compile('\s+')
+
+ def __init__(self, *args, **kwargs):
+ self.parent = None
+ self.children = []
+ for child in args:
+ self._add(child)
+ for arg in kwargs:
+ setattr(self, arg, kwargs[arg])
+
+ def join(self, *children):
+ """ add child nodes
+
+ returns a reference to self
+ """
+ for child in children:
+ self._add(child)
+ return self
+
+ def add(self, child):
+ """ adds a child node
+
+ returns a reference to the child
+ """
+ self._add(child)
+ return child
+
+ def _add(self, child):
+ if child.__class__ not in self.allowed_child:
+ raise RestError("%r cannot be child of %r" % \
+ (child.__class__, self.__class__))
+ self.children.append(child)
+ child.parent = self
+
+ def __getitem__(self, item):
+ return self.children[item]
+
+ def __setitem__(self, item, value):
+ self.children[item] = value
+
+ def text(self):
+ """ return a ReST string representation of the node """
+ return self.sep.join([child.text() for child in self.children])
+
+ def wordlist(self):
+ """ return a list of ReST strings for this node and its children """
+ return [self.text()]
+
+class Rest(AbstractNode):
+ """ Root node of a document """
+
+ sep = "\n\n"
+ def __init__(self, *args, **kwargs):
+ AbstractNode.__init__(self, *args, **kwargs)
+ self.links = {}
+
+ def render_links(self, check=False):
+ """render the link attachments of the document"""
+ assert not check, "Link checking not implemented"
+ if not self.links:
+ return ""
+ link_texts = []
+ # XXX this could check for duplicates and remove them...
+ for link, target in self.links.iteritems():
+ link_texts.append(".. _`%s`: %s" % (escape(link), target))
+ return "\n" + "\n".join(link_texts) + "\n\n"
+
+ def text(self):
+ outcome = []
+ if (isinstance(self.children[0], Transition) or
+ isinstance(self.children[-1], Transition)):
+ raise ValueError, ('document must not begin or end with a '
+ 'transition')
+ for child in self.children:
+ outcome.append(child.text())
+
+ # always a trailing newline
+ text = self.sep.join([i for i in outcome if i]) + "\n"
+ return text + self.render_links()
+
+class Transition(AbstractNode):
+ """ a horizontal line """
+ parentclass = Rest
+
+ def __init__(self, char='-', width=80, *args, **kwargs):
+ self.char = char
+ self.width = width
+ super(Transition, self).__init__(*args, **kwargs)
+
+ def text(self):
+ return (self.width - 1) * self.char
+
+class Paragraph(AbstractNode):
+ """ simple paragraph """
+
+ parentclass = Rest
+ sep = " "
+ indent = ""
+ width = 80
+
+ def __init__(self, *args, **kwargs):
+ # make shortcut
+ args = list(args)
+ for num, arg in py.builtin.enumerate(args):
+ if isinstance(arg, str):
+ args[num] = Text(arg)
+ super(Paragraph, self).__init__(*args, **kwargs)
+
+ def text(self):
+ texts = []
+ for child in self.children:
+ texts += child.wordlist()
+
+ buf = []
+ outcome = []
+ lgt = len(self.indent)
+
+ def grab(buf):
+ outcome.append(self.indent + self.sep.join(buf))
+
+ texts.reverse()
+ while texts:
+ next = texts[-1]
+ if not next:
+ texts.pop()
+ continue
+ if lgt + len(self.sep) + len(next) <= self.width or not buf:
+ buf.append(next)
+ lgt += len(next) + len(self.sep)
+ texts.pop()
+ else:
+ grab(buf)
+ lgt = len(self.indent)
+ buf = []
+ grab(buf)
+ return "\n".join(outcome)
+
+class SubParagraph(Paragraph):
+ """ indented sub paragraph """
+
+ indent = " "
+
+class Title(Paragraph):
+ """ title element """
+
+ parentclass = Rest
+ belowchar = "="
+ abovechar = ""
+
+ def text(self):
+ txt = self._get_text()
+ lines = []
+ if self.abovechar:
+ lines.append(self.abovechar * len(txt))
+ lines.append(txt)
+ if self.belowchar:
+ lines.append(self.belowchar * len(txt))
+ return "\n".join(lines)
+
+ def _get_text(self):
+ txt = []
+ for node in self.children:
+ txt += node.wordlist()
+ return ' '.join(txt)
+
+class AbstractText(AbstractNode):
+ parentclass = [Paragraph, Title]
+ start = ""
+ end = ""
+ def __init__(self, _text):
+ self._text = _text
+
+ def text(self):
+ text = self.escape(self._text)
+ return self.start + text + self.end
+
+ def escape(self, text):
+ if not isinstance(text, str) and not isinstance(text, unicode):
+ text = str(text)
+ if self.start:
+ text = text.replace(self.start, '\\%s' % (self.start,))
+ if self.end and self.end != self.start:
+ text = text.replace(self.end, '\\%s' % (self.end,))
+ return text
+
+class Text(AbstractText):
+ def wordlist(self):
+ text = escape(self._text)
+ return self._reg_whitespace.split(text)
+
+class LiteralBlock(AbstractText):
+ parentclass = Rest
+ start = '::\n\n'
+
+ def text(self):
+ if not self._text.strip():
+ return ''
+ text = self.escape(self._text).split('\n')
+ for i, line in py.builtin.enumerate(text):
+ if line.strip():
+ text[i] = ' %s' % (line,)
+ return self.start + '\n'.join(text)
+
+class Em(AbstractText):
+ start = "*"
+ end = "*"
+
+class Strong(AbstractText):
+ start = "**"
+ end = "**"
+
+class Quote(AbstractText):
+ start = '``'
+ end = '``'
+
+class Anchor(AbstractText):
+ start = '_`'
+ end = '`'
+
+class Footnote(AbstractText):
+ def __init__(self, note, symbol=False):
+ raise NotImplemented('XXX')
+
+class Citation(AbstractText):
+ def __init__(self, text, cite):
+ raise NotImplemented('XXX')
+
+class ListItem(Paragraph):
+ allow_nesting = True
+ item_chars = '*+-'
+
+ def text(self):
+ idepth = self.get_indent_depth()
+ indent = self.indent + (idepth + 1) * ' '
+ txt = '\n\n'.join(self.render_children(indent))
+ ret = []
+ item_char = self.item_chars[idepth]
+ ret += [indent[len(item_char)+1:], item_char, ' ', txt[len(indent):]]
+ return ''.join(ret)
+
+ def render_children(self, indent):
+ txt = []
+ buffer = []
+ def render_buffer(fro, to):
+ if not fro:
+ return
+ p = Paragraph(indent=indent, *fro)
+ p.parent = self.parent
+ to.append(p.text())
+ for child in self.children:
+ if isinstance(child, AbstractText):
+ buffer.append(child)
+ else:
+ if buffer:
+ render_buffer(buffer, txt)
+ buffer = []
+ txt.append(child.text())
+
+ render_buffer(buffer, txt)
+ return txt
+
+ def get_indent_depth(self):
+ depth = 0
+ current = self
+ while (current.parent is not None and
+ isinstance(current.parent, ListItem)):
+ depth += 1
+ current = current.parent
+ return depth
+
+class OrderedListItem(ListItem):
+ item_chars = ["#."] * 5
+
+class DListItem(ListItem):
+ item_chars = None
+ def __init__(self, term, definition, *args, **kwargs):
+ self.term = term
+ super(DListItem, self).__init__(definition, *args, **kwargs)
+
+ def text(self):
+ idepth = self.get_indent_depth()
+ indent = self.indent + (idepth + 1) * ' '
+ txt = '\n\n'.join(self.render_children(indent))
+ ret = []
+ ret += [indent[2:], self.term, '\n', txt]
+ return ''.join(ret)
+
+class Link(AbstractText):
+ start = '`'
+ end = '`_'
+
+ def __init__(self, _text, target):
+ self._text = _text
+ self.target = target
+ self.rest = None
+
+ def text(self):
+ if self.rest is None:
+ self.rest = self.find_rest()
+ if self.rest.links.get(self._text, self.target) != self.target:
+ raise ValueError('link name %r already in use for a different '
+ 'target' % (self.target,))
+ self.rest.links[self._text] = self.target
+ return AbstractText.text(self)
+
+ def find_rest(self):
+ # XXX little overkill, but who cares...
+ next = self
+ while next.parent is not None:
+ next = next.parent
+ return next
+
+class InternalLink(AbstractText):
+ start = '`'
+ end = '`_'
+
+class LinkTarget(Paragraph):
+ def __init__(self, name, target):
+ self.name = name
+ self.target = target
+
+ def text(self):
+ return ".. _`%s`:%s\n" % (self.name, self.target)
+
+class Substitution(AbstractText):
+ def __init__(self, text, **kwargs):
+ raise NotImplemented('XXX')
+
+class Directive(Paragraph):
+ indent = ' '
+ def __init__(self, name, *args, **options):
+ self.name = name
+ self.content = options.pop('content', [])
+ children = list(args)
+ super(Directive, self).__init__(*children)
+ self.options = options
+
+ def text(self):
+ # XXX not very pretty...
+ namechunksize = len(self.name) + 2
+ self.children.insert(0, Text('X' * namechunksize))
+ txt = super(Directive, self).text()
+ txt = '.. %s::%s' % (self.name, txt[namechunksize + 3:],)
+ options = '\n'.join([' :%s: %s' % (k, v) for (k, v) in
+ self.options.iteritems()])
+ if options:
+ txt += '\n%s' % (options,)
+
+ if self.content:
+ txt += '\n'
+ for item in self.content:
+ assert item.parentclass == Rest, 'only top-level items allowed'
+ assert not item.indent
+ item.indent = ' '
+ txt += '\n' + item.text()
+
+ return txt
+
Modified: pypy/branch/py11/pypy/tool/statistic_over_time.py
==============================================================================
--- pypy/branch/py11/pypy/tool/statistic_over_time.py (original)
+++ pypy/branch/py11/pypy/tool/statistic_over_time.py Tue Nov 10 16:01:00 2009
@@ -1,5 +1,5 @@
import py
-from py.__.misc.cmdline.countloc import get_loccount
+from py.impl.misc.cmdline.countloc import get_loccount
import datetime
import time
Modified: pypy/branch/py11/pypy/tool/test/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/tool/test/autopath.py (original)
+++ pypy/branch/py11/pypy/tool/test/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/tool/test/test_pytestsupport.py
==============================================================================
--- pypy/branch/py11/pypy/tool/test/test_pytestsupport.py (original)
+++ pypy/branch/py11/pypy/tool/test/test_pytestsupport.py Tue Nov 10 16:01:00 2009
@@ -1,5 +1,5 @@
import autopath
-from py.__.magic import exprinfo
+from py.impl.code import _assertionold as exprinfo
from pypy.interpreter.error import OperationError
from pypy.interpreter.gateway import app2interp_temp
from pypy.interpreter.argument import Arguments
Modified: pypy/branch/py11/pypy/translator/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/translator/autopath.py (original)
+++ pypy/branch/py11/pypy/translator/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/translator/benchmark/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/translator/benchmark/autopath.py (original)
+++ pypy/branch/py11/pypy/translator/benchmark/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/translator/c/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/translator/c/autopath.py (original)
+++ pypy/branch/py11/pypy/translator/c/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/translator/c/test/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/translator/c/test/autopath.py (original)
+++ pypy/branch/py11/pypy/translator/c/test/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/translator/cli/test/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/translator/cli/test/autopath.py (original)
+++ pypy/branch/py11/pypy/translator/cli/test/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/translator/goal/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/translator/goal/autopath.py (original)
+++ pypy/branch/py11/pypy/translator/goal/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/translator/goal/test2/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/translator/goal/test2/autopath.py (original)
+++ pypy/branch/py11/pypy/translator/goal/test2/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/translator/microbench/pybench/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/translator/microbench/pybench/autopath.py (original)
+++ pypy/branch/py11/pypy/translator/microbench/pybench/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/translator/platform/__init__.py
==============================================================================
--- pypy/branch/py11/pypy/translator/platform/__init__.py (original)
+++ pypy/branch/py11/pypy/translator/platform/__init__.py Tue Nov 10 16:01:00 2009
@@ -6,7 +6,7 @@
import sys, py, os
from pypy.tool.ansi_print import ansi_log
-from py.__.code import safe_repr
+from py.impl.code.code import safe_repr
log = py.log.Producer("platform")
py.log.setconsumer("platform", ansi_log)
@@ -33,9 +33,9 @@
def __repr__(self):
if self.err:
- return "<CompilationError err=%s>" % safe_repr._repr(self.err)
+ return "<CompilationError err=%s>" % safe_repr(self.err)
else:
- return "<CompilationError out=%s>" % safe_repr._repr(self.out)
+ return "<CompilationError out=%s>" % safe_repr(self.out)
__str__ = __repr__
Modified: pypy/branch/py11/pypy/translator/sandbox/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/translator/sandbox/autopath.py (original)
+++ pypy/branch/py11/pypy/translator/sandbox/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/translator/sandbox/test/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/translator/sandbox/test/autopath.py (original)
+++ pypy/branch/py11/pypy/translator/sandbox/test/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/translator/test/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/translator/test/autopath.py (original)
+++ pypy/branch/py11/pypy/translator/test/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
Modified: pypy/branch/py11/pypy/translator/tool/autopath.py
==============================================================================
--- pypy/branch/py11/pypy/translator/tool/autopath.py (original)
+++ pypy/branch/py11/pypy/translator/tool/autopath.py Tue Nov 10 16:01:00 2009
@@ -37,8 +37,7 @@
partdir = head
head, tail = os.path.split(head)
if tail == part:
- # check if "../py/__init__.py" exists
- checkfile = os.path.join(partdir, os.pardir, 'py', '__init__.py')
+ checkfile = os.path.join(partdir, os.pardir, 'pypy', '__init__.py')
if not os.path.exists(checkfile):
error = "Cannot find %r" % (os.path.normpath(checkfile),)
break
More information about the Pypy-commit
mailing list