[py-svn] py-trunk commit 88cd8639f646: remove pyrest and _py/rest before first 1.1. release

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Oct 29 12:28:32 CET 2009


# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1256815547 -3600
# Node ID 88cd8639f646211cf2e0b60020fae3d684718211
# Parent e92da679b6f90839a45a02c3c9fae8f8af9de16c
remove pyrest and _py/rest before first 1.1. release

--- a/py/bin/py.rest
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env python
-from _findpy import py
-py.cmdline.pyrest()

--- a/_py/rest/convert.py
+++ /dev/null
@@ -1,163 +0,0 @@
-import py
-
-from _py.process.cmdexec import ExecutionFailed
-# 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))
-

--- a/_py/rest/latex.py
+++ /dev/null
@@ -1,154 +0,0 @@
-import py
-
-from _py.process.cmdexec import ExecutionFailed
-
-font_to_package = {"times": "times", "helvetica": "times",
-                   "new century schoolbock": "newcent", "avant garde": "newcent",
-                   "palatino": "palatino",
-                  }
-sans_serif_fonts = {"helvetica": True,
-                    "avant garde": True,
-                   }
-
-
-def merge_files(pathlist, pagebreak=False):
-    if len(pathlist) == 1:
-        return pathlist[0].read()
-    sectnum = False
-    toc = False
-    result = []
-    includes = {}
-    for path in pathlist:
-        lines = path.readlines()
-        for line in lines:
-            # prevent several table of contents
-            # and especially sectnum several times
-            if ".. contents::" in line:
-                if not toc:
-                    toc = True
-                    result.append(line)
-            elif ".. sectnum::" in line:
-                if not sectnum:
-                    sectnum = True
-                    result.append(line)
-            elif line.strip().startswith(".. include:: "):
-                #XXX slightly unsafe
-                inc = line.strip()[13:]
-                if inc not in includes:
-                    includes[inc] = True
-                    result.append(line)
-            else:
-                result.append(line)
-        if pagebreak:
-            result.append(".. raw:: latex \n\n \\newpage\n\n")
-    if pagebreak:
-        result.pop() #remove the last pagebreak again
-    return "".join(result)
-
-def create_stylesheet(options, path):
-    fill_in = {}
-    if "logo" in options:
-        fill_in["have_logo"] = ""
-        fill_in["logo"] = options["logo"]
-    else:
-        fill_in["have_logo"] = "%"
-        fill_in["logo"] = ""
-    if "font" in options:
-        font = options["font"].lower()
-        fill_in["font_package"] = font_to_package[font]
-        fill_in["specified_font"] = ""
-        fill_in["sans_serif"] = font not in sans_serif_fonts and "%" or ""
-    else:
-        fill_in["specified_font"] = "%"
-        fill_in["sans_serif"] = "%"
-        fill_in["font_package"] = ""
-    if 'toc_depth' in options:
-        fill_in["have_tocdepth"] = ""
-        fill_in["toc_depth"] = options["toc_depth"]
-    else:
-        fill_in["have_tocdepth"] = "%"
-        fill_in["toc_depth"] = ""
-    fill_in["heading"] = options.get("heading", "")
-    template_file = path.join("rest.sty.template")
-    if not template_file.check():
-        template_file = py.path.local(__file__).dirpath("rest.sty.template")
-    return template_file.read() % fill_in
-
-def process_configfile(configfile, debug=False):
-    old = py.path.local()
-    py.path.local(configfile).dirpath().chdir()
-    configfile = py.path.local(configfile)
-    path = configfile.dirpath()
-    configfile_dic = {}
-    py.std.sys.path.insert(0, str(path))
-    py.builtin.execfile(str(configfile), configfile_dic)
-    pagebreak = configfile_dic.get("pagebreak", False)
-    rest_sources = [py.path.local(p)
-                    for p in configfile_dic['rest_sources']]
-    rest = configfile.new(ext='txt')
-    if len(rest_sources) > 1:
-        assert rest not in rest_sources
-    content = merge_files(rest_sources, pagebreak)
-    if len(rest_sources) > 1:
-        rest.write(content)
-    sty = configfile.new(ext='sty')
-    content = create_stylesheet(configfile_dic, path)
-    sty.write(content)
-    rest_options = None
-    if 'rest_options' in configfile_dic:
-        rest_options = configfile_dic['rest_options']
-    process_rest_file(rest, sty.basename, debug, rest_options)
-    #cleanup:
-    if not debug:
-        sty.remove()
-        if rest not in rest_sources:
-            rest.remove()
-    old.chdir()
-
-def process_rest_file(restfile, stylesheet=None, debug=False, rest_options=None):
-    from docutils.core import publish_cmdline
-    if not py.path.local.sysfind("pdflatex"):
-        raise SystemExit("ERROR: pdflatex not found")
-    old = py.path.local()
-    f = py.path.local(restfile)
-    path = f.dirpath()
-    path.chdir()
-    pdf = f.new(ext="pdf")
-    if pdf.check():
-        pdf.remove()
-    tex = f.new(ext="tex").basename
-    options = [f, "--input-encoding=latin-1", "--graphicx-option=auto",
-               "--traceback"]
-    if stylesheet is not None:
-        sty = path.join(stylesheet)
-        if sty.check():
-            options.append('--stylesheet=%s' % (sty.relto(f.dirpath()), ))
-    options.append(f.new(basename=tex))
-    options = map(str, options)
-    if rest_options is not None:
-        options.extend(rest_options)
-    publish_cmdline(writer_name='latex', argv=options)
-    i = 0
-    while i < 10: # there should never be as many as five reruns, but to be sure
-        try:
-            latexoutput = py.process.cmdexec('pdflatex "%s"' % (tex, ))
-        except ExecutionFailed:
-            e = py.std.sys.exc_info()[1]
-            print("ERROR: pdflatex execution failed")
-            print("pdflatex stdout:")
-            print(e.out)
-            print("pdflatex stderr:")
-            print(e.err)
-            raise SystemExit
-        if debug:
-            print(latexoutput)
-        if py.std.re.search("LaTeX Warning:.*Rerun", latexoutput) is None:
-            break
-        i += 1
-            
-    old.chdir()
-    #cleanup:
-    if not debug:
-        for ext in "log aux tex out".split():
-            p = pdf.new(ext=ext)
-            p.remove()

--- a/_py/rest/directive.py
+++ /dev/null
@@ -1,115 +0,0 @@
-# XXX this file is messy since it tries to deal with several docutils versions
-import py
-
-from _py.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('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 = '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)


--- a/testing/rest/data/graphviz.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-This tests the graphviz directive
-=================================
-
-let's embed the cool graphviz example:
-
-.. graphviz:: example1.dot
-   :scale: 50

--- a/testing/pytest/plugin/test_pytest_restdoc.py
+++ b/testing/pytest/plugin/test_pytest_restdoc.py
@@ -45,7 +45,8 @@ class TestDoctest:
     def pytest_funcarg__testdir(self, request):
         testdir = request.getfuncargvalue("testdir")
         assert request.module.__name__ == __name__
-        testdir.makepyfile(confrest="from _py.rest.resthtml import Project")
+        testdir.makepyfile(confrest=
+            "from _py.test.plugin.pytest_restdoc import Project")
         for p in testdir.plugins:
             if p == globals():
                 break

--- a/_py/rest/resthtml.py
+++ /dev/null
@@ -1,87 +0,0 @@
-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 _py.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.open('wb').write(doc)
-    #log("wrote %r" % htmlpath)
-    #if txtpath.check(svnwc=1, versioned=1): 
-    #    info = txtpath.info()
-    #    svninfopath.dump(info) 
-
-if sys.version_info > (3, 0):
-    def _uni(s): return s
-else:
-    def _uni(s):
-        return unicode(s)
-
-rex1 = re.compile(r'.*<body>(.*)</body>.*', re.MULTILINE | re.DOTALL)
-rex2 = re.compile(r'.*<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')

--- a/testing/rest/test_htmlrest.py
+++ /dev/null
@@ -1,20 +0,0 @@
-
-import py
-from _py.rest import resthtml
-from testing.rest.setup import getdata
-
-def setup_module(mod):
-    py.test.importorskip("docutils")
-    if not py.path.local.sysfind("gs") or \
-           not py.path.local.sysfind("dot") or \
-           not py.path.local.sysfind("latex"):
-        py.test.skip("ghostscript, graphviz and latex needed")
-    mod.datadir = getdata()
-
-def test_process_simple():
-    # fallback test: only checks that no exception is raised
-    def rec(p):
-        return p.check(dotfile=0)
-    for x in datadir.visit("*.txt", rec=rec,):
-        yield resthtml.process, x
-

--- a/testing/rest/data/formula1.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-this formula contains a fraction, that means it also contains a backslash:
-:latexformula:`$\frac{x^2}{y^2}$`

--- a/testing/rest/test_rst2pdf.py
+++ /dev/null
@@ -1,50 +0,0 @@
-import py
-from _py.rest.latex import process_configfile, process_rest_file
-from testing.rest.setup import getdata
-
-docutils = py.test.importorskip("docutils")
-
-def setup_module(mod):
-    if not py.path.local.sysfind("gs") or \
-           not py.path.local.sysfind("dot") or \
-           not py.path.local.sysfind("latex"):
-        py.test.skip("ghostscript, graphviz and latex needed")
-    mod.datadir = getdata()
-
-class TestRst2Pdf(object):
-    def _process_rest_file(self):
-        part2 = datadir.join("part1.txt")
-        pdf = part2.new(ext="pdf")
-        process_rest_file(part2)
-        assert pdf.check()
-        pdf.remove()
-
-    def _process_configfile(self):
-        config = datadir.join("example.rst2pdfconfig")
-        pdf = config.new(ext="pdf")
-        tex = datadir.join('example.tex')
-        process_configfile(config, debug=True)
-        assert pdf.check()
-        assert tex.check()
-        texcontent = tex.read()
-        assert "Generated by" in texcontent
-        assert "Docutils" in texcontent
-        process_configfile(config, debug=False)
-        assert pdf.check()
-        assert not tex.check()
-        pdf.remove()
-
-    def _process_all(self):
-        # fallback test: only checks that no exception is raised
-        def rec(p):
-            return p.check(dotfile=0)
-
-        for x in datadir.visit("*.rst2pdfconfig", rec=rec):
-            process_configfile(x)
-        for x in datadir.visit("*.txt", rec=rec):
-            process_rest_file(x)
-
-    def test_rst2pdf(self):
-        self._process_rest_file()
-        self._process_configfile()
-        self._process_all()

--- a/testing/rest/data/example.rst2pdfconfig
+++ /dev/null
@@ -1,3 +0,0 @@
-rest_sources = ['part1.txt', 'part2.txt']
-
-rest_options = ["--use-latex-toc", "--generator"] # generator is easy to test

--- a/py/bin/win32/py.rest.cmd
+++ /dev/null
@@ -1,2 +0,0 @@
- at echo off
-python "%~dp0\..\py.rest" %*

--- a/setup.py
+++ b/setup.py
@@ -31,14 +31,14 @@ def main():
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
         author='holger krekel, Guido Wesdorp, Carl Friedrich Bolz, Armin Rigo, Maciej Fijalkowski & others',
         author_email='holger at merlinux.eu',
-        entry_points={'console_scripts': ['py.cleanup = py.cmdline:pycleanup',
-                                          'py.convert_unittest = py.cmdline:pyconvert_unittest',
-                                          'py.countloc = py.cmdline:pycountloc',
-                                          'py.lookup = py.cmdline:pylookup',
-                                          'py.rest = py.cmdline:pyrest',
-                                          'py.svnwcrevert = py.cmdline:pysvnwcrevert',
-                                          'py.test = py.cmdline:pytest',
-                                          'py.which = py.cmdline:pywhich']},
+        entry_points={'console_scripts': [
+            'py.cleanup = py.cmdline:pycleanup',
+            'py.convert_unittest = py.cmdline:pyconvert_unittest',
+            'py.countloc = py.cmdline:pycountloc',
+            'py.lookup = py.cmdline:pylookup',
+            'py.svnwcrevert = py.cmdline:pysvnwcrevert',
+            'py.test = py.cmdline:pytest',
+            'py.which = py.cmdline:pywhich']},
         classifiers=['Development Status :: 4 - Beta',
                      'Intended Audience :: Developers',
                      'License :: OSI Approved :: MIT License',
@@ -52,7 +52,6 @@ def main():
                      'Programming Language :: Python'],
         packages=['py',
                   '_py',
-                  '_py.builtin',
                   '_py.cmdline',
                   '_py.code',
                   '_py.compat',
@@ -61,7 +60,6 @@ def main():
                   '_py.path',
                   '_py.path.gateway',
                   '_py.process',
-                  '_py.rest',
                   '_py.test',
                   '_py.test.dist',
                   '_py.test.looponfail',
@@ -73,7 +71,6 @@ def main():
                              'bin/py.convert_unittest',
                              'bin/py.countloc',
                              'bin/py.lookup',
-                             'bin/py.rest',
                              'bin/py.svnwcrevert',
                              'bin/py.test',
                              'bin/py.which',
@@ -81,11 +78,9 @@ def main():
                              'bin/win32/py.convert_unittest.cmd',
                              'bin/win32/py.countloc.cmd',
                              'bin/win32/py.lookup.cmd',
-                             'bin/win32/py.rest.cmd',
                              'bin/win32/py.svnwcrevert.cmd',
                              'bin/win32/py.test.cmd',
                              'bin/win32/py.which.cmd',],
-                        '_py': ['rest/rest.sty.template']},
         zip_safe=True,
     )
 

--- a/testing/rest/setup.py
+++ /dev/null
@@ -1,11 +0,0 @@
-import py
-
-rootdir = py.path.local(__file__).dirpath()
-mydatadir = py.path.local(__file__).dirpath('data')
-
-def getdata():
-    rel = mydatadir.relto(rootdir)
-    tmpdir = py.test.ensuretemp(rel.replace(rootdir.sep, '_'))
-    mydatadir.copy(tmpdir)
-    return tmpdir
-

--- a/testing/rest/test_directive.py
+++ /dev/null
@@ -1,63 +0,0 @@
-import py
-
-docutils = py.test.importorskip("docutils")
-from _py.rest import directive, resthtml
-from _py.rest.latex import process_rest_file
-from testing.rest.setup import getdata
-
-def setup_module(mod):
-    mod.datadir = getdata()
-    mod.testdir = py.test.ensuretemp("rest")
-
-class TestGraphviz(object):
-    def _graphviz_html(self):
-        if not py.path.local.sysfind("dot"):
-            py.test.skip("graphviz needed")
-        directive.set_backend_and_register_directives("html")
-        if not py.path.local.sysfind("svn"):
-            py.test.skip("svn needed")
-        txt = datadir.join("graphviz.txt")
-        html = txt.new(ext="html")
-        png = datadir.join("example1.png")
-        resthtml.process(txt)
-        assert html.check()
-        assert png.check()
-        html_content = html.read()
-        assert png.basename in html_content
-        html.remove()
-        png.remove()
-        
-    def _graphviz_pdf(self):
-        for exe in 'dot latex epstopdf ps2eps'.split():
-            if  not py.path.local.sysfind(exe):
-                py.test.skip("%r needed" %(exe,))
-
-        directive.set_backend_and_register_directives("latex")
-        txt = py.path.local(datadir.join("graphviz.txt"))
-        pdf = txt.new(ext="pdf")
-        dotpdf = datadir.join("example1.pdf")
-        process_rest_file(txt)
-        assert pdf.check()
-        assert dotpdf.check()
-        pdf.remove()
-        dotpdf.remove()
-
-    def test_graphviz(self):
-        self._graphviz_html()
-        self._graphviz_pdf()
-
-def test_own_links():
-    def callback(name, text):
-        assert name == "foo"
-        return "bar xyz", "http://codespeak.net/noclue"
-    directive.register_linkrole("foo", callback)
-    txt = testdir.join("link-role.txt")
-    txt.write("""
-:foo:`whatever`
-""")
-    html = txt.new(ext="html")
-    resthtml.process(txt)
-    assert html.check()
-    htmlcontent = html.read()
-    assert "http://codespeak.net/noclue" in htmlcontent
-    assert "bar xyz" in htmlcontent

--- a/testing/rest/data/part1.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-.. contents::
-
-This is the first part of the example rest file
-===============================================
-
-
-some content.
-
-fancy subsection heading
--------------------------
-
-some more content.
-
-really stupid document
-------------------------
-
-we are all thankful that it ends now.
-
-

--- a/testing/rest/test_convert.py
+++ /dev/null
@@ -1,30 +0,0 @@
-import py
-from _py.rest.convert import convert_dot, latexformula2png
-from testing.rest.setup import getdata
-
-def setup_module(mod):
-    required = 'gs', 'dot', 'latex', 'epstopdf', 
-    for exe in required:
-        if not py.path.local.sysfind(exe):
-            py.test.skip("%r not found, required: %r" %(exe, required))
-    mod.datadir = getdata()
-
-def test_convert_dot():
-    # XXX not really clear that the result is valid pdf/eps
-    dot = datadir.join("example1.dot")
-    convert_dot(dot, "pdf")
-    pdf = dot.new(ext="pdf")
-    assert pdf.check()
-    pdf.remove()
-    convert_dot(dot, "eps")
-    eps = dot.new(ext="eps")
-    assert eps.check()
-    eps.remove()
-
-def test_latexformula():
-    png = datadir.join("test.png")
-    formula = r'$$Entropy(T) = - \sum^{m}_{j=1}  \frac{|T_j|}{|T|} \log \frac{|T_j|}{|T|}$$'
-    #does not crash
-    latexformula2png(formula, png)
-    assert png.check()
-    png.remove()

--- a/_py/cmdline/pyrest.py
+++ /dev/null
@@ -1,82 +0,0 @@
-#!/usr/bin/env python
-"""
-invoke 
-
-    py.rest filename1.txt directory 
-
-to generate html files from ReST.
-
-It is also possible to generate pdf files using the --topdf option.
-
-http://docutils.sourceforge.net/docs/user/rst/quickref.html
-
-"""
-
-import os, sys
-import py
-
-if hasattr(sys.stdout, 'fileno') and os.isatty(sys.stdout.fileno()):
-    def log(msg):
-        print(msg)
-else:
-    def log(msg):
-        pass
-
-
-parser = py.std.optparse.OptionParser(usage=__doc__)
-parser.add_option("--topdf", action="store_true", dest="topdf", default=False,
-                  help="generate pdf files")
-parser.add_option("--stylesheet", dest="stylesheet", default=None,
-                  help="use specified latex style sheet")
-parser.add_option("--debug", action="store_true", dest="debug",
-                  default=False,
-                  help="print debug output and don't delete files")
-
-
-def main():
-    try:
-        from _py.rest import directive, resthtml 
-        from _py.rest.latex import process_rest_file, process_configfile
-    except ImportError:
-        e = sys.exc_info()[1]
-        print(str(e))
-        sys.exit(1)
-
-    (options, args) = parser.parse_args()
-
-    if len(args) == 0:
-        filenames = [py.path.svnwc()]
-    else:
-        filenames = [py.path.svnwc(x) for x in args]
-    
-    if options.topdf:
-        directive.set_backend_and_register_directives("latex")
-        
-    for p in filenames:
-        if not p.check():
-            log("path %s not found, ignoring" % p)
-            continue
-        def fil(p):
-            return p.check(fnmatch='*.txt', versioned=True)
-        def rec(p):
-            return p.check(dotfile=0)
-        if p.check(dir=1):
-            for x in p.visit(fil, rec):
-                resthtml.process(x)
-        elif p.check(file=1):
-            if p.ext == ".rst2pdfconfig":
-                directive.set_backend_and_register_directives("latex")
-                process_configfile(p, options.debug)
-            else:
-                if options.topdf:
-                    cfg = p.new(ext=".rst2pdfconfig")
-                    if cfg.check():
-                        print("using config file %s" % (cfg, ))
-                        process_configfile(cfg, options.debug)
-                    else:
-                        process_rest_file(p.localpath,
-                                          options.stylesheet,
-                                      options.debug)
-                else:
-                    resthtml.process(p)
-

--- a/doc/changelog.txt
+++ b/doc/changelog.txt
@@ -1,6 +1,11 @@
 Changes between 1.0.2 and '1.1.0b1'
 =====================================
 
+* remove py.rest tool and internal namespace - it was
+  never really advertised and can still be used with
+  the old release if needed.  If there is interest 
+  it could be revived into its own tool i guess.
+
 * fix issue48 and issue59: raise an Error if the module
   from an imported test file does not seem to come from 
   the filepath - avoids "same-name" confusion that has


--- a/_py/rest/rest.sty.template
+++ /dev/null
@@ -1,26 +0,0 @@
-\usepackage{fancyhdr}
-\usepackage{lastpage}
-\pagestyle{fancy}
-\usepackage[pdftex]{graphicx}
-
-%(have_tocdepth)s\setcounter{tocdepth}{%(toc_depth)s}
-
-%(sans_serif)s\renewcommand{\familydefault}{\sfdefault}
-%(specified_font)s\usepackage{%(font_package)s}
-\lhead{
-\begin{tabular}{l}
-\textbf{\Large %(heading)s}\tabularnewline
-\thepage\ of \pageref{LastPage},  \today
-\tabularnewline
-\tabularnewline
-\end{tabular}
-}
-\rhead{
-%(have_logo)s\includegraphics[height=4\baselineskip]{%(logo)s}
-}
-\cfoot{}
-\addtolength{\headheight}{3\baselineskip}
-\addtolength{\headheight}{0.61pt}
-\setlength\parskip{\medskipamount}
-\setlength\parindent{0pt}
-

--- a/doc/confrest.py
+++ b/doc/confrest.py
@@ -1,5 +1,6 @@
 import py
-from _py.rest.resthtml import convert_rest_html, strip_html_header 
+
+from _py.test.plugin.pytest_restdoc import convert_rest_html, strip_html_header
 
 html = py.xml.html 
 
@@ -284,5 +285,3 @@ def relpath(p1, p2, sep=os.path.sep, bac
     if tolist_diff:
         return sep.join([back,]*(backcount-1) + tolist_diff)
     return sep.join([back,]*(backcount) + tolist[commonindex:])
-
-

--- a/testing/rest/data/formula.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-Euklids proof about the infinitude of primes
-============================================
-
-If there were only a finite amount of primes then there would be a largest
-prime :latexformula:`p`. However, the number :latexformula:`p! + 1` is not
-divisible by any number :latexformula:`1, ..., p`. Therefore, a prime dividing
-:latexformula:`p! + 1` has to be bigger than :latexformula:`p`. Therefore there
-is an infinite number of primes. 

--- a/_py/test/plugin/pytest_restdoc.py
+++ b/_py/test/plugin/pytest_restdoc.py
@@ -2,7 +2,7 @@
 perform ReST syntax, local and remote reference tests on .rst/.txt files. 
 """
 import py
-import sys
+import sys, os, re
 
 def pytest_addoption(parser):
     group = parser.getgroup("ReST", "ReST documentation check options")
@@ -87,12 +87,11 @@ class ReSTSyntaxTest(py.test.collect.Ite
             py.test.fail("docutils processing failed, see captured stderr") 
 
     def register_linkrole(self):
-        from _py.rest import directive
-        directive.register_linkrole('api', self.resolve_linkrole)
-        directive.register_linkrole('source', self.resolve_linkrole)
-
-        # XXX fake sphinx' "toctree" and refs
-        directive.register_linkrole('ref', self.resolve_linkrole)
+        #directive.register_linkrole('api', self.resolve_linkrole)
+        #directive.register_linkrole('source', self.resolve_linkrole)
+#
+#        # XXX fake sphinx' "toctree" and refs
+#        directive.register_linkrole('ref', self.resolve_linkrole)
         
         from docutils.parsers.rst import directives
         def toctree_directive(name, arguments, options, content, lineno,
@@ -349,3 +348,85 @@ def localrefcheck(tryfn, path, lineno):
         else: 
             py.test.fail("anchor reference error %s#%s in %s:%d" %(
                 tryfn, anchor, path.basename, lineno+1))
+
+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'):
+    """ 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
+    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.open('wb').write(doc)
+    #log("wrote %r" % htmlpath)
+    #if txtpath.check(svnwc=1, versioned=1): 
+    #    info = txtpath.info()
+    #    svninfopath.dump(info) 
+
+if sys.version_info > (3, 0):
+    def _uni(s): return s
+else:
+    def _uni(s):
+        return unicode(s)
+
+rex1 = re.compile(r'.*<body>(.*)</body>.*', re.MULTILINE | re.DOTALL)
+rex2 = re.compile(r'.*<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')

--- a/py/__init__.py
+++ b/py/__init__.py
@@ -37,11 +37,9 @@ _py.apipkg.initpkg(__name__, dict(
     },
     cmdline = {
         'pytest':     '_py.cmdline.pytest:main',
-        'pyrest':     '_py.cmdline.pyrest:main',
         'pylookup':   '_py.cmdline.pylookup:main',
         'pycountloc': '_py.cmdline.pycountlog:main',
         'pytest':     '_py.test.cmdline:main',
-        'pyrest':     '_py.cmdline.pyrest:main',
         'pylookup':   '_py.cmdline.pylookup:main',
         'pycountloc': '_py.cmdline.pycountloc:main',
         'pycleanup':  '_py.cmdline.pycleanup:main',

--- a/testing/rest/data/example1.dot
+++ /dev/null
@@ -1,3 +0,0 @@
-digraph G {
-    a -> b -> c -> d;
-}

--- a/testing/rest/data/tocdepth.rst2pdfconfig
+++ /dev/null
@@ -1,5 +0,0 @@
-rest_sources = ['part1.txt', 'part2.txt']
-
-rest_options = ["--use-latex-toc", "--generator"] # generator is easy to test
-
-toc_depth = 1

--- a/testing/rest/data/part2.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-This is the second part of the test file
-=========================================
-
-.. contents::
-
-the text in it is not much more interesting.
-



More information about the pytest-commit mailing list