[LIBDOC] Generate doc for all libraries contained in subfolders

1,028 views
Skip to first unread message

Chuck

unread,
Jul 26, 2017, 3:23:35 PM7/26/17
to robotframework-users
Hi everyone,

I'm able to generate the documentation for a specific keyword library (placed in folder /A/AA/AAA) using this command :
python -m robot.libdoc MyLibrary.txt MyLib.html

However, I would like to generate the documentation for all the keyword libraries placed in sub-folders of A/.
For exemple with testdoc, you can generate documentation for multiple test cases files place in sub-folder of A/ using 
python -m robot.testdoc A/ MyTestDoc.html

How can I do the same thing with libdoc ? 
Might be a noob question sorry but wasn't able to do it got an ImportError at every try.


Thanks a lot guys !

Kevin O.

unread,
Jul 27, 2017, 11:34:33 AM7/27/17
to robotframework-users
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.

Cheers,
Kevin

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."

Pekka Klärck

unread,
Jul 29, 2017, 5:51:31 AM7/29/17
to Kevin Ormbrek, robotframework-users
Nice script Kevin! Libdoc also has a programmatic API that the script
could use too. Here's Robot's own generator script that doesn't crawl
but is somewhat similar:
https://github.com/robotframework/robotframework/blob/master/doc/libraries/lib2html.py

Having a built-in way in Libdoc to process directories would be handy.
Anyone interested to look at it?

Cheers,
.peke
> --
> You received this message because you are subscribed to the Google Groups
> "robotframework-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to robotframework-u...@googlegroups.com.
> To post to this group, send email to robotframe...@googlegroups.com.
> Visit this group at https://groups.google.com/group/robotframework-users.
> For more options, visit https://groups.google.com/d/optout.



--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org
Reply all
Reply to author
Forward
0 new messages