示例#1
0
    def parse(self):
        """Parse `self.input` into a document tree."""

        tree = parse_module(self.input,self.source.source_path)
        self.document = document = make_document(tree)
        #self.document = document = self.new_document()
        #self.parser.parse(self.input, document)
        document.current_source = document.current_line = None
示例#2
0
    def parse(self):
        """Parse `self.input` into a document tree."""

        tree = parse_module(self.input, self.source.source_path)
        self.document = document = make_document(tree)
        #self.document = document = self.new_document()
        #self.parser.parse(self.input, document)
        document.current_source = document.current_line = None
    def testTool(self):
        """Trying to think what to do for packages"""
        # The Reader interface is designed to work with single test entities,
        # either a string or the content of a text file (i.e., a single thing
        # that can be accessed via some sort of "read" method).
        # This doesn't work for packages, where one has multiple files.
        # Thus I suspect that the Reader interface is not appropriate for
        # what I want to do (at least, not without doing it unnecessary
        # violence and making it a lot more complicated).
        # So I need to do things "by hand"...

        source="# A Python comment"
        source_path="test.py"

        # Since a body of text is a Module, not a Package, we'll go straight
        # to it
        nodes = parse_module(source,source_path)

        # That then needs converting to a docutils tree
        document = make_document(nodes)

        # And *that* wants converting to the appropriate output format

        from docutils.writers.pseudoxml import Writer
        writer = Writer()
        writer.document = document
        writer.translate()
        actual_result = writer.output

        wanted_result = """\
<document source="Module test">
    <section class="module" id="module-test" name="module test">
        <title>
            Module test\n"""


        if wanted_result != actual_result:
            print "+++++++++++++++++++++++++ WANT"
            print wanted_result
            print "+++++++++++++++++++++++++ GOT"
            print actual_result
            print "+++++++++++++++++++++++++"

        self.assertEqual(actual_result,wanted_result)
示例#4
0
    def testTool(self):
        """Trying to think what to do for packages"""
        # The Reader interface is designed to work with single test entities,
        # either a string or the content of a text file (i.e., a single thing
        # that can be accessed via some sort of "read" method).
        # This doesn't work for packages, where one has multiple files.
        # Thus I suspect that the Reader interface is not appropriate for
        # what I want to do (at least, not without doing it unnecessary
        # violence and making it a lot more complicated).
        # So I need to do things "by hand"...

        source="# A Python comment"
        source_path="test.py"

        # Since a body of text is a Module, not a Package, we'll go straight
        # to it
        nodes = parse_module(source,source_path)

        # That then needs converting to a docutils tree
        document = make_document(nodes)

        # And *that* wants converting to the appropriate output format

        from docutils.writers.pseudoxml import Writer
        writer = Writer()
        writer.document = document
        writer.translate()
        actual_result = writer.output

        wanted_result = """\
<document source="Module test">
    <section class="module" id="module-test" name="module test">
        <title>
            Module test\n"""


        if wanted_result != actual_result:
            print "+++++++++++++++++++++++++ WANT"
            print wanted_result
            print "+++++++++++++++++++++++++ GOT"
            print actual_result
            print "+++++++++++++++++++++++++"

        self.assertEqual(actual_result,wanted_result)
示例#5
0
            temp=[]
            temp.append(corners[i][0])
            temp.append(corners[i][1])
            temp=np.asarray(temp)
            temp1=[]
            temp1.append(temp)
            temp1=np.asarray(temp1)
            cont.append(temp)
        cont=np.asarray(cont)

        #hull=[]

        #hull.append(cv2.convexHull(cont,False))
        #cv2.drawContours(out_img, hull, 0, (255,255,0),1)
        
        warped = make_document(org, [cont], ratio)
        if(warped.shape[0] > warped.shape[1]):
                warp,_ = image_resize(warped, height=1000)
        else:
                warp,_ = image_resize(warped, width=1000)
        cv2.imshow("doc", warp)
        #cv2.imshow("window", out_img)
        key=cv2.waitKey(0)
        if key==ord("d"):
            raise Exception("ERROR")
        cv2.destroyAllWindows()
        #os.remove(img_path)
    except Exception as e:
        print(e)
        cv2.imshow("ERROR",out_img)
        cv2.waitKey(0)
    def testMakeDocument(self):
        """
        Turn our Package tree into a docutils Document.
        """

        # I've split the wanted result string up into substrings so I can
        # amend it more easily (or so I hope).
        trivial_package = """\
<document source="Package trivial_package">
    <section class="package" id="package-trivial-package" name="package trivial_package">
        <title>
            Package trivial_package\n"""

        # The "xml:space" attribute is by observation, not prediction
        module_init = """\
        <section class="module" id="module-trivial-package-init" name="module trivial_package.__init__">
            <title>
                Module trivial_package.__init__
            <literal_block class="docstring" xml:space="preserve">
                A simple docstring.\n"""

        module_file1 = """\
        <section class="module" id="module-trivial-package-file1" name="module trivial_package.file1">
            <title>
                Module trivial_package.file1
            <literal_block class="docstring" xml:space="preserve">
                This is the first example file. It *does* use reStructuredText.
            <section class="class" id="class-trivial-package-file1-fred" name="class trivial_package.file1.fred">
                <title>
                    Class trivial_package.file1.Fred
                <literal_block class="docstring" xml:space="preserve">
                    An example class - it announces each instance as it is created.\n"""

        module_file2 = """\
        <section class="module" id="module-trivial-package-file2" name="module trivial_package.file2">
            <title>
                Module trivial_package.file2
            <literal_block class="docstring" xml:space="preserve">
                This module is *not* using reStructuredText for its docstrings.\n"""

        non_python_file = """\
        <section class="file" id="file-trivial-package-not-python" name="file trivial_package.not_python">
            <title>
                File trivial_package.not_python
            <paragraph>
                File 
                <literal>
                    not_python
                 is not a Python module.\n"""

        sub_package = """\
        <section class="package" id="package-trivial-package-sub-package" name="package trivial_package.sub_package">
            <title>
                Package trivial_package.sub_package\n"""

        sub_module_init = """\
            <section class="module" id="module-trivial-package-sub-package-init" name="module trivial_package.sub_package.__init__">
                <title>
                    Module trivial_package.sub_package.__init__\n"""

        wanted_result = (trivial_package + module_init + module_file1 +
                         module_file2 + non_python_file + sub_package +
                         sub_module_init)

        tree = parse_package("trivial_package")

        document = make_document(tree)

        actual_result = document.pformat()

        if wanted_result != actual_result:
            print "+++++++++++++++++++++++++ WANT"
            print wanted_result
            print "+++++++++++++++++++++++++ GOT"
            print actual_result
            print "+++++++++++++++++++++++++"

        self.assertEqual(actual_result, wanted_result)
import transform
from docutils.writers.html4css1 import Writer
from docutils.frontend import OptionParser

usage = '%prog [options] [<package-directory> | <python-file> [html-file]]'
description = ('Generates .html documentation for the given Python package'
               ' or module.')

writer = Writer()

option_parser = OptionParser(components=[writer],
                             usage=usage,
                             description=description)

settings = option_parser.parse_args(sys.argv[1:])

source_path = settings._source
target_path = settings._destination

nodes = parse_package_or_module(source_path)

# That then needs converting to a docutils tree
document = transform.make_document(nodes, settings)

# And *that* wants converting to the appropriate output format
try:
    target = open(target_path, "w")
    writer.write(document, target)
finally:
    target.close()
示例#8
0
from package import parse_package_or_module
import transform
from docutils.writers.html4css1 import Writer
from docutils.frontend import OptionParser

usage = '%prog [options] [<package-directory> | <python-file> [html-file]]'
description = ('Generates .html documentation for the given Python package'
               ' or module.')

writer = Writer()

option_parser = OptionParser(components=[writer],
                             usage=usage,description=description)

settings = option_parser.parse_args(sys.argv[1:])

source_path = settings._source
target_path = settings._destination

nodes = parse_package_or_module(source_path)

# That then needs converting to a docutils tree
document = transform.make_document(nodes,settings)

# And *that* wants converting to the appropriate output format
try:
    target = open(target_path,"w")
    writer.write(document,target)
finally:
    target.close()
示例#9
0
    def testMakeDocument(self):
        """
        Turn our Package tree into a docutils Document.
        """

        # I've split the wanted result string up into substrings so I can
        # amend it more easily (or so I hope).
        trivial_package = """\
<document source="Package trivial_package">
    <section class="package" id="package-trivial-package" name="package trivial_package">
        <title>
            Package trivial_package\n"""

        # The "xml:space" attribute is by observation, not prediction
        module_init = """\
        <section class="module" id="module-trivial-package-init" name="module trivial_package.__init__">
            <title>
                Module trivial_package.__init__
            <literal_block class="docstring" xml:space="preserve">
                A simple docstring.\n"""

        module_file1 = """\
        <section class="module" id="module-trivial-package-file1" name="module trivial_package.file1">
            <title>
                Module trivial_package.file1
            <literal_block class="docstring" xml:space="preserve">
                This is the first example file. It *does* use reStructuredText.
            <section class="class" id="class-trivial-package-file1-fred" name="class trivial_package.file1.fred">
                <title>
                    Class trivial_package.file1.Fred
                <literal_block class="docstring" xml:space="preserve">
                    An example class - it announces each instance as it is created.\n"""

        module_file2 = """\
        <section class="module" id="module-trivial-package-file2" name="module trivial_package.file2">
            <title>
                Module trivial_package.file2
            <literal_block class="docstring" xml:space="preserve">
                This module is *not* using reStructuredText for its docstrings.\n"""

        non_python_file = """\
        <section class="file" id="file-trivial-package-not-python" name="file trivial_package.not_python">
            <title>
                File trivial_package.not_python
            <paragraph>
                File 
                <literal>
                    not_python
                 is not a Python module.\n"""

        sub_package = """\
        <section class="package" id="package-trivial-package-sub-package" name="package trivial_package.sub_package">
            <title>
                Package trivial_package.sub_package\n"""

        sub_module_init = """\
            <section class="module" id="module-trivial-package-sub-package-init" name="module trivial_package.sub_package.__init__">
                <title>
                    Module trivial_package.sub_package.__init__\n"""

        wanted_result = (trivial_package + module_init + module_file1 +
                         module_file2 + non_python_file + sub_package +
                         sub_module_init)

        tree = parse_package("trivial_package")

        document = make_document(tree)

        actual_result = document.pformat()

        if wanted_result != actual_result:
            print "+++++++++++++++++++++++++ WANT"
            print wanted_result
            print "+++++++++++++++++++++++++ GOT"
            print actual_result
            print "+++++++++++++++++++++++++"

        self.assertEqual(actual_result,wanted_result)