If you are getting ImportErrors, you might want to check whether your virtualenv is active and also whether the Python path is set appropriately. libdoc takes a --pythonpath arg just like pybot.
There is no builtin way to crawl directories looking for libraries because it is impossible to know what is intended to be a library from other Python files.
Here's a script that we use that creates docs for libraries and resource files. It puts the HTML/doc files right next to the source files.
Perhaps this will help you get started with your own script.
It all depends on os.walk, which is useful for crawling under directories.
Python files that start with _ are ignored, as well as some specified ones.
import fnmatch
import os
from os import walk
from os.path import join, dirname, abspath, splitext
from subprocess import check_call
THIS_DIR = dirname(abspath(__file__))
EXCLUDED_LIBS = ['Activities', 'RewardsPlanUser']
def get_libraries():
matches = []
dirs = ('api', 'selenium')
for dir_ in dirs:
for root, _, filenames in walk(join(THIS_DIR, dir_)):
for filename in fnmatch.filter(filenames, '[!_]*.py'):
matches.append(join(root, filename))
return matches
def get_resource_files():
matches = []
dirs = ('api/Tests/Keywords', 'selenium/Keywords')
for dir_ in dirs:
for root, _, filenames in walk(join(THIS_DIR, dir_)):
for filename in fnmatch.filter(filenames, '[!_]*.robot'):
matches.append(join(root, filename))
for filename in fnmatch.filter(filenames, '[!_]*.txt'):
matches.append(join(root, filename))
return matches
def save_docs(paths):
for path in paths:
without_ext = splitext(path)[0]
tail_no_ext = os.path.split(without_ext)[1]
if tail_no_ext in EXCLUDED_LIBS:
continue
out_file = without_ext + '.html'
args = ['python', '-m', 'robot.libdoc', path, out_file]
check_call(args)
if __name__ == '__main__':
print "Generating documentation for libraries"
paths = get_libraries()
save_docs(paths)
print "Generating documentation for resource files"
paths = get_resource_files()
save_docs(paths)
print "Documentation generated successfully."