41 if 'robot' not in sys.modules
and __name__ ==
'__main__':
42 import pythonpathsetter
49 USAGE =
"""Libdoc -- Robot Framework library documentation generator
53 Usage: libdoc [options] library_or_resource output_file
54 or: libdoc [options] library_or_resource list|show|version [names]
56 Libdoc can generate documentation for Robot Framework libraries and resource
57 files. It can generate HTML documentation for humans as well as machine
58 readable spec files in XML and JSON formats. Libdoc also has few special
59 commands to show library or resource information on the console.
61 Libdoc supports all library and resource types and also earlier generated XML
62 and JSON specs can be used as input. If a library needs arguments, they must be
63 given as part of the library name and separated by two colons, for example,
64 like `LibraryName::arg1::arg2`.
66 The easiest way to run Libdoc is using the `libdoc` command created as part of
67 the normal installation. Alternatively it is possible to execute the
68 `robot.libdoc` module directly like `python -m robot.libdoc`, where `python`
69 can be replaced with any supported Python interpreter. Yet another alternative
70 is running the module as a script like `python path/to/robot/libdoc.py`.
72 The separate `libdoc` command and the support for JSON spec files are new in
78 -f --format HTML|XML|JSON|LIBSPEC
79 Specifies whether to generate an HTML output for
80 humans or a machine readable spec file in XML or JSON
81 format. The LIBSPEC format means XML spec with
82 documentations converted to HTML. The default format
83 is got from the output file extension.
84 -s --specdocformat RAW|HTML
85 Specifies the documentation format used with XML and
86 JSON spec files. RAW means preserving the original
87 documentation format and HTML means converting
88 documentation to HTML. The default is RAW with XML
89 spec files and HTML with JSON specs and when using
90 the special LIBSPEC format. New in RF 4.0.
91 -F --docformat ROBOT|HTML|TEXT|REST
92 Specifies the source documentation format. Possible
93 values are Robot Framework's documentation format,
94 HTML, plain text, and reStructuredText. The default
95 value can be specified in library source code and
96 the initial default value is ROBOT.
97 --theme DARK|LIGHT|NONE
98 Use dark or light HTML theme. If this option is not
99 used, or the value is NONE, the theme is selected
100 based on the browser color scheme. New in RF 6.0.
101 -n --name name Sets the name of the documented library or resource.
102 -v --version version Sets the version of the documented library or
104 --quiet Do not print the path of the generated output file
105 to the console. New in RF 4.0.
106 -P --pythonpath path * Additional locations where to search for libraries
108 -h -? --help Print this help.
110 Creating documentation
111 ======================
113 When creating documentation in HTML, XML or JSON format, the output file must
114 be specified as the second argument after the library or resource name or path.
116 Output format is got automatically from the output file extension. In addition
117 to `*.html`, `*.xml` and `*.json` extensions, it is possible to use the special
118 `*.libspec` extensions which means XML spec with actual library and keyword
119 documentation converted to HTML. The format can also be set explicitly using
120 the `--format` option.
124 libdoc src/MyLibrary.py doc/MyLibrary.html
125 libdoc doc/MyLibrary.json doc/MyLibrary.html
126 libdoc --name MyLibrary Remote::10.0.0.42:8270 MyLibrary.xml
127 libdoc MyLibrary MyLibrary.libspec
129 Viewing information on console
130 ==============================
132 Libdoc has three special commands to show information on the console. These
133 commands are used instead of the name of the output file, and they can also
134 take additional arguments.
136 list: List names of the keywords the library/resource contains. Can be
137 limited to show only certain keywords by passing optional patterns as
138 arguments. Keyword is listed if its name contains any given pattern.
139 show: Show library/resource documentation. Can be limited to show only
140 certain keywords by passing names as arguments. Keyword is shown if
141 its name matches any given name. Special argument `intro` will show
142 the library introduction and importing sections.
143 version: Show library version
145 Optional patterns given to `list` and `show` are case and space insensitive.
146 Both also accept `*` and `?` as wildcards.
151 libdoc SeleniumLibrary list browser
152 libdoc Remote::10.0.0.42:8270 show
153 libdoc Dialogs show PauseExecution execute*
154 libdoc SeleniumLibrary show intro
155 libdoc SeleniumLibrary version
157 Alternative execution
158 =====================
160 Libdoc works with all interpreters supported by Robot Framework.
161 In the examples above Libdoc is executed as an
162 installed module, but it can also be executed as a script like
163 `python path/robot/libdoc.py`.
165 For more information about Libdoc and other built-in tools, see
166 http://robotframework.org/robotframework/#built-in-tools.
173 Application.__init__(self, USAGE, arg_limits=(2,), auto_version=
False)
176 if ConsoleViewer.handles(arguments[1]):
177 ConsoleViewer.validate_command(arguments[1], arguments[2:])
178 return options, arguments
179 if len(arguments) > 2:
180 raise DataError(
'Only two arguments allowed when writing output.')
181 return options, arguments
183 def main(self, args, name='', version='', format=None, docformat=None,
184 specdocformat=None, theme=None, pythonpath=None, quiet=False):
186 sys.path = pythonpath + sys.path
187 lib_or_res, output = args[:2]
190 if ConsoleViewer.handles(output):
191 ConsoleViewer(libdoc).view(output, *args[2:])
193 format, specdocformat \
196 or specdocformat ==
'HTML'
197 or format
in (
'JSON',
'LIBSPEC')
and specdocformat !=
'RAW'):
198 libdoc.convert_docs_to_html()
199 libdoc.save(output, format, self.
_validate_theme_validate_theme(theme, format))
201 self.console(os.path.abspath(output))
204 return self.
_validate_validate(
'Doc format', docformat,
'ROBOT',
'TEXT',
'HTML',
'REST')
207 extension = os.path.splitext(output)[1][1:]
208 format = self.
_validate_validate(
'Format', format
or extension,
209 'HTML',
'XML',
'JSON',
'LIBSPEC')
210 specdocformat = self.
_validate_validate(
'Spec doc format', specdocformat,
'RAW',
'HTML')
211 if format ==
'HTML' and specdocformat:
212 raise DataError(
"The --specdocformat option is not applicable with "
214 return format, specdocformat
219 value = value.upper()
220 if value
not in valid:
221 raise DataError(f
"{kind} must be {seq2str(valid, lastsep=' or ')}, "
226 theme = self.
_validate_validate(
'Theme', theme,
'DARK',
'LIGHT',
'NONE')
227 if not theme
or theme ==
'NONE':
230 raise DataError(
"The --theme option is only applicable with HTML outputs.")
249 if arguments
is None:
250 arguments = sys.argv[1:]
251 LibDoc().execute_cli(arguments, exit=exit)
287 def libdoc(library_or_resource, outfile, name='', version='', format=None,
288 docformat=None, specdocformat=None, quiet=False):
290 library_or_resource, outfile, name=name, version=version, format=format,
291 docformat=docformat, specdocformat=specdocformat, quiet=quiet
295 if __name__ ==
'__main__':
def _get_docformat(self, docformat)
def main(self, args, name='', version='', format=None, docformat=None, specdocformat=None, theme=None, pythonpath=None, quiet=False)
def _validate_theme(self, theme, format)
def _validate(self, kind, value, *valid)
def _get_format_and_specdocformat(self, format, specdocformat, output)
def validate(self, options, arguments)
def libdoc_cli(arguments=None, exit=True)
Executes Libdoc similarly as from the command line.
def libdoc(library_or_resource, outfile, name='', version='', format=None, docformat=None, specdocformat=None, quiet=False)
Executes Libdoc.
def LibraryDocumentation(library_or_resource, name=None, version=None, doc_format=None)
Generate keyword documentation for the given library, resource or suite file.