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)
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>'
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
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
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
def test_ensure_multiline_string_support(): code = '''x = """ how about this? """ y = z # is this where it should be? # how did this get so *BIG!* def x(): """how would you fix? """''' docs_code_tuple_list = p.parse(code,PYTHON) assert docs_code_tuple_list[0]['docs_text'] == '' assert "#" not in docs_code_tuple_list[1]['docs_text']
def test_ensure_multiline_string_support(): code = '''x = """ multi-line-string """ y = z # comment # *comment with formatting* def x(): """multi-line-string """''' docs_code_tuple_list = p.parse(code, PYTHON) assert docs_code_tuple_list[0]['docs_text'] == '' assert "#" not in docs_code_tuple_list[1]['docs_text']
def test_parse(choice, source): l = get_language(choice) parsed = p.parse(source, l) for s in parsed: assert {"code_text", "docs_text"} == set(s.keys())
def test_multi_line_leading_spaces(): source = "# This is a\n# comment that\n# is indented\n" source += FOO_FUNCTION parsed = p.parse(source, PYTHON) # The resulting comment has leading spaces stripped out. assert parsed[0]["docs_text"] == "This is a\ncomment that\nis indented\n"
def test_skip_coding_directive(): source = "# -*- coding: utf-8 -*-\n" + FOO_FUNCTION parsed = p.parse(source, PYTHON) for section in parsed: assert "coding" not in section['code_text']
def test_parse(data, source): lang = get_language(data) parsed = p.parse(source, lang) for s in parsed: assert {"code_text", "docs_text"} == set(s.keys())