summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMorgan Goose <morgan.goose@gmail.com>2016-03-26 01:20:52 -0700
committerMorgan Goose <morgan.goose@plangrid.com>2016-03-26 01:22:56 -0700
commitc66d21dca0420b855d52e8639e107af039710a7e (patch)
tree53ea20fd9f60e91c5c6b20aaf0b98b6c2595fc04
parentf60f3b5ef342b256963c9b1de81051b281dc1456 (diff)
downloadpycco-c66d21dca0420b855d52e8639e107af039710a7e.tar.gz
Feature addition to allow directory arguments
This should address the feature request from issue-78, where the request was made to build documentation recursively for all files in a directory and it's subdirectories. https://github.com/pycco-docs/pycco/issues/78
-rw-r--r--pycco/main.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/pycco/main.py b/pycco/main.py
index e95ad73..a02eee2 100644
--- a/pycco/main.py
+++ b/pycco/main.py
@@ -456,6 +456,23 @@ highlight_start = "<div class=\"highlight\"><pre>"
# 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
+ is encountered it will walk the tree for any files
+ """
+ _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])
+ 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."""
@@ -465,7 +482,7 @@ def process(sources, preserve_paths=True, outdir=None, language=None, encoding="
# Make a copy of sources given on the command line. `main()` needs the
# original list when monitoring for changed files.
- sources = sorted(sources)
+ sources = sorted(_flatten_sources(sources))
# Proceed to generating the documentation.
if sources: