@@ -244,7 +244,8 @@ def highlight(sections, language, preserve_paths=True, outdir=None):
244
244
output = output .replace (highlight_start , "" ).replace (highlight_end , "" )
245
245
fragments = re .split (language ["divider_html" ], output )
246
246
for i , section in enumerate (sections ):
247
- section ["code_html" ] = highlight_start + shift (fragments , "" ) + highlight_end
247
+ section ["code_html" ] = highlight_start + \
248
+ shift (fragments , "" ) + highlight_end
248
249
try :
249
250
docs_text = unicode (section ["docs_text" ])
250
251
except UnicodeError :
@@ -280,7 +281,8 @@ def generate_html(source, sections, preserve_paths=True, outdir=None):
280
281
csspath = path .relpath (path .join (outdir , "pycco.css" ), path .split (dest )[0 ])
281
282
282
283
for sect in sections :
283
- sect ["code_html" ] = re .sub (r"\{\{" , r"__DOUBLE_OPEN_STACHE__" , sect ["code_html" ])
284
+ sect ["code_html" ] = re .sub (
285
+ r"\{\{" , r"__DOUBLE_OPEN_STACHE__" , sect ["code_html" ])
284
286
285
287
rendered = pycco_template ({
286
288
"title" : title ,
@@ -364,7 +366,8 @@ def generate_html(source, sections, preserve_paths=True, outdir=None):
364
366
365
367
# The mirror of `divider_text` that we expect Pygments to return. We can split
366
368
# on this to recover the original sections.
367
- l ["divider_html" ] = re .compile (r'\n*<span class="c[1]?">' + l ["symbol" ] + 'DIVIDER</span>\n *' )
369
+ l ["divider_html" ] = re .compile (
370
+ r'\n*<span class="c[1]?">' + l ["symbol" ] + 'DIVIDER</span>\n *' )
368
371
369
372
# Get the Pygments Lexer for this language.
370
373
l ["lexer" ] = lexers .get_lexer_by_name (l ["name" ])
@@ -438,7 +441,8 @@ def remove_control_chars(s):
438
441
# Sanitization regexp copied from
439
442
# http://stackoverflow.com/questions/92438/stripping-non-printable-characters-from-a-string-in-python
440
443
from pycco .compat import pycco_unichr
441
- control_chars = '' .join (map (pycco_unichr , list (range (0 , 32 )) + list (range (127 , 160 ))))
444
+ control_chars = '' .join (
445
+ map (pycco_unichr , list (range (0 , 32 )) + list (range (127 , 160 ))))
442
446
control_char_re = re .compile (u'[{}]' .format (re .escape (control_chars )))
443
447
return control_char_re .sub ('' , s )
444
448
@@ -461,6 +465,23 @@ def ensure_directory(directory):
461
465
highlight_end = "</pre></div>"
462
466
463
467
468
+ def _flatten_sources (sources ):
469
+ """
470
+ This function will iterate through the list of sources and if a directory
471
+ is encountered it will walk the tree for any files
472
+ """
473
+ _sources = []
474
+
475
+ for source in sources :
476
+ if os .path .isdir (source ):
477
+ for dirpath , _ , filenames in os .walk (source ):
478
+ _sources .extend ([os .path .join (dirpath , f ) for f in filenames ])
479
+ else :
480
+ _sources .append (source )
481
+
482
+ return _sources
483
+
484
+
464
485
def process (sources , preserve_paths = True , outdir = None , language = None , encoding = "utf8" , index = False ):
465
486
"""For each source file passed as argument, generate the documentation."""
466
487
@@ -469,7 +490,7 @@ def process(sources, preserve_paths=True, outdir=None, language=None, encoding="
469
490
470
491
# Make a copy of sources given on the command line. `main()` needs the
471
492
# original list when monitoring for changed files.
472
- sources = sorted (sources )
493
+ sources = sorted (_flatten_sources ( sources ) )
473
494
474
495
# Proceed to generating the documentation.
475
496
if sources :
0 commit comments