Skip to content

Commit

Permalink
autopep8 results, will squash if acceptable
Browse files Browse the repository at this point in the history
  • Loading branch information
goosemo committed Apr 5, 2016
1 parent 1479ee5 commit 83ffef5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
16 changes: 10 additions & 6 deletions pycco/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ def highlight(sections, language, preserve_paths=True, outdir=None):
output = output.replace(highlight_start, "").replace(highlight_end, "")
fragments = re.split(language["divider_html"], output)
for i, section in enumerate(sections):
section["code_html"] = highlight_start + shift(fragments, "") + highlight_end
section["code_html"] = highlight_start + \
shift(fragments, "") + highlight_end
try:
docs_text = unicode(section["docs_text"])
except UnicodeError:
Expand Down Expand Up @@ -280,7 +281,8 @@ def generate_html(source, sections, preserve_paths=True, outdir=None):
csspath = path.relpath(path.join(outdir, "pycco.css"), path.split(dest)[0])

for sect in sections:
sect["code_html"] = re.sub(r"\{\{", r"__DOUBLE_OPEN_STACHE__", sect["code_html"])
sect["code_html"] = re.sub(
r"\{\{", r"__DOUBLE_OPEN_STACHE__", sect["code_html"])

rendered = pycco_template({
"title": title,
Expand Down Expand Up @@ -360,7 +362,8 @@ def generate_html(source, sections, preserve_paths=True, outdir=None):

# The mirror of `divider_text` that we expect Pygments to return. We can split
# on this to recover the original sections.
l["divider_html"] = re.compile(r'\n*<span class="c[1]?">' + l["symbol"] + 'DIVIDER</span>\n*')
l["divider_html"] = re.compile(
r'\n*<span class="c[1]?">' + l["symbol"] + 'DIVIDER</span>\n*')

# Get the Pygments Lexer for this language.
l["lexer"] = lexers.get_lexer_by_name(l["name"])
Expand Down Expand Up @@ -434,7 +437,8 @@ def remove_control_chars(s):
# Sanitization regexp copied from
# http://stackoverflow.com/questions/92438/stripping-non-printable-characters-from-a-string-in-python
from pycco.compat import pycco_unichr
control_chars = ''.join(map(pycco_unichr, list(range(0, 32)) + list(range(127, 160))))
control_chars = ''.join(
map(pycco_unichr, list(range(0, 32)) + list(range(127, 160))))
control_char_re = re.compile(u'[{}]'.format(re.escape(control_chars)))
return control_char_re.sub('', s)

Expand All @@ -456,6 +460,7 @@ def ensure_directory(directory):
# The end of each Pygments highlight block.
highlight_end = "</pre></div>"


def _flatten_sources(sources):
"""
This function will iterate through the list of sources and if a directory
Expand All @@ -466,14 +471,13 @@ def _flatten_sources(sources):
for source in sources:
if os.path.isdir(source):
for dirpath, _, filenames in os.walk(source):
_sources.extend([os.path.join(dirpath,f) for f in filenames])
_sources.extend([os.path.join(dirpath, f) for f in filenames])
else:
_sources.append(source)

return _sources



def process(sources, preserve_paths=True, outdir=None, language=None, encoding="utf8", index=False):
"""For each source file passed as argument, generate the documentation."""

Expand Down
13 changes: 9 additions & 4 deletions tests/test_pycco.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def test_shift(fragments, default):
@given(text(), booleans(), text(min_size=1))
@example("/foo", True, "0")
def test_destination(filepath, preserve_paths, outdir):
dest = p.destination(filepath, preserve_paths=preserve_paths, outdir=outdir)
dest = p.destination(
filepath, preserve_paths=preserve_paths, outdir=outdir)
assert dest.startswith(outdir)
assert dest.endswith(".html")

Expand Down Expand Up @@ -65,12 +66,14 @@ 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>'
assert sections[1][
'docs_html'] == '<p><a href="testing.html#link-target">testing.py</a></p>'


@given(text(), text())
def test_get_language_specify_language(source, code):
assert p.get_language(source, code, language="python") == p.languages['.py']
assert p.get_language(
source, code, language="python") == p.languages['.py']

with pytest.raises(ValueError):
p.get_language(source, code, language="non-existent")
Expand Down Expand Up @@ -99,7 +102,8 @@ def test_get_language_bad_code(code):

@given(text(max_size=64))
def test_ensure_directory(dir_name):
tempdir = os.path.join(tempfile.gettempdir(), str(int(time.time())), dir_name)
tempdir = os.path.join(tempfile.gettempdir(),
str(int(time.time())), dir_name)

# Use sanitization from function, but only for housekeeping. We
# pass in the unsanitized string to the function.
Expand Down Expand Up @@ -162,6 +166,7 @@ def test_generate_index(path_lists, outdir_list):
outdir = os.path.join(*outdir_list)
generate_index.generate_index(file_paths, outdir=outdir)


def test_flatten_sources(tmpdir):
sources = [str(tmpdir)]
expected_sources = []
Expand Down

0 comments on commit 83ffef5

Please sign in to comment.