Esempio n. 1
0
    def handle(self, *args, **options):
        examples_dir = os.path.join(self.root_dir, EXAMPLES_PATH)
        template_dir = os.path.join(self.root_dir, TEMPLATE_PATH)
        docs_dir = os.path.join(self.root_dir, DOCS_TEMPLATE_PATH)

        with open(os.path.join(template_dir, 'doc_template.txt'), 'r') as fdoc:
            doc_template = template(fdoc.read())

        for src_file in PYTHON_TO_PYCCO:
            source = os.path.join(examples_dir, src_file)
            folder = src_file.split('/')[0]
            outdir = os.path.join(docs_dir, folder)

            with open(source, 'r') as fin:
                sections = parse(source, fin.read())
                highlight(source, sections, outdir=outdir)
                rendered = doc_template({
                    "title": src_file,
                    "sections": sections,
                    "source": source,
                })
                result = re.sub(r"__DOUBLE_OPEN_STACHE__", "{{",
                                rendered).encode("utf-8")
            print destination(source, outdir=outdir)
            with open(destination(source, outdir=outdir), "w") as fout:
                fout.write(result)
Esempio n. 2
0
def test_comment_with_only_cross_ref():
    source = (
        '''# ==Link Target==\n\ndef test_link():\n    """[[testing.py#link-target]]"""\n    pass'''
    )
    sections = p.parse(source, PYTHON)
    p.highlight(sections, PYTHON, outdir=tempfile.gettempdir())
    assert sections[1][
        'docs_html'] == '<p><a href="testing.html#link-target">testing.py</a></p>'
Esempio n. 3
0
def test_comment_with_only_cross_ref():
    source = (
        '''# ==Link Target==\n\ndef test_link():\n    """[[testing.py#link-target]]"""\n    pass'''
    )
    sections = p.parse(source, PYTHON)
    p.highlight(sections, PYTHON, outdir=tempfile.gettempdir())
    assert sections[1][
        'docs_html'] == '<p><a href="testing.html#link-target">testing.py</a></p>'
Esempio n. 4
0
def pycco(file_name):
    code = open(file_name, 'rb').read().decode('utf-8')
    language = pyccoLib.get_language(file_name, code)
    sections = pyccoLib.parse(code, language)
    pyccoLib.highlight(sections, language, outdir="docs")

    data = {'file_path': trim_repo_path(file_name), 'sections': sections}
    print('[COUT] CO_JSON_CONTENT {}'.format(json.dumps(data)))

    return True
Esempio n. 5
0
def pycco(file_name, use_yaml):
    code = open(file_name, 'rb').read().decode('utf-8')
    language = pyccoLib.get_language(file_name, code)
    sections = pyccoLib.parse(code, language)
    pyccoLib.highlight(sections, language, outdir="docs")

    data = { 'file_path': trim_repo_path(file_name), 'sections': sections }
    if use_yaml:
        data = anymarkup.serialize(data, 'yaml')
        print('[COUT] CO_YAML_CONTENT {}'.format(str(data)[1:]))
    else:
        print('[COUT] CO_JSON_CONTENT {}'.format(json.dumps(data)))


    return True
Esempio n. 6
0
def test_indented_block():

    code = '''"""To install Pycco, simply

    pip install pycco
"""
'''
    parsed = p.parse(code, PYTHON)
    highlighted = p.highlight(parsed, PYTHON, outdir=tempfile.gettempdir())
    pre_block = highlighted[0]['docs_html']
    assert '<pre>' in pre_block
    assert '</pre>' in pre_block
Esempio n. 7
0
def test_indented_block():

    code = '''"""To install Pycco, simply

    pip install pycco
"""
'''
    parsed = p.parse(code, PYTHON)
    highlighted = p.highlight(parsed, PYTHON, outdir=tempfile.gettempdir())
    pre_block = highlighted[0]['docs_html']
    assert '<pre>' in pre_block
    assert '</pre>' in pre_block