Skip to content

Commit

Permalink
Enhance docs of Libdoc's public API. Fixes #4520.
Browse files Browse the repository at this point in the history
  • Loading branch information
pekkaklarck committed Oct 28, 2022
1 parent acc61b8 commit 6c92dd4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/robot/libdoc.py
Expand Up @@ -23,10 +23,12 @@
python -m robot.libdoc
python path/to/robot/libdoc.py
Instead of ``python`` it is possible to use also other Python interpreters.
This module also exposes the following public API:
This module also provides :func:`libdoc` and :func:`libdoc_cli` functions
that can be used programmatically. Other code is for internal usage.
- :func:`libdoc_cli` function for simple command line tools.
- :func:`libdoc` function as a high level programmatic API.
- :func:`~robot.libdocpkg.builder.LibraryDocumentation` as the API to generate
:class:`~robot.libdocpkg.model.LibraryDoc` instances.
Libdoc itself is implemented in the :mod:`~robot.libdocpkg` package.
"""
Expand Down Expand Up @@ -255,7 +257,7 @@ def libdoc(library_or_resource, outfile, name='', version='', format=None,
:param library_or_resource: Name or path of the library or resource
file to be documented.
:param outfile: Path path to the file where to write outputs.
:param outfile: Path to the file where to write outputs.
:param name: Custom name to give to the documented library or resource.
:param version: Version to give to the documented library or resource.
:param format: Specifies whether to generate HTML, XML or JSON output.
Expand Down
5 changes: 1 addition & 4 deletions src/robot/libdocpkg/__init__.py
Expand Up @@ -15,10 +15,7 @@

"""Implements the `Libdoc` tool.
The command line entry point and programmatic interface for Libdoc
are provided by the separate :mod:`robot.libdoc` module.
This package is considered stable but it is not part of the public API.
The public Libdoc API is exposed via the :mod:`robot.libdoc` module.
"""

from .builder import LibraryDocumentation
Expand Down
28 changes: 26 additions & 2 deletions src/robot/libdocpkg/builder.py
Expand Up @@ -27,8 +27,32 @@
XML_EXTENSIONS = ('xml', 'libspec')


def LibraryDocumentation(library_or_resource, name=None, version=None,
doc_format=None):
def LibraryDocumentation(library_or_resource, name=None, version=None, doc_format=None):
"""Generate keyword documentation for the given library, resource or suite file.
:param library_or_resource:
Name or path of the library, or path of a resource or a suite file.
:param name:
Set name with the given value.
:param version:
Set version to the given value.
:param doc_format:
Set documentation format to the given value.
:return:
:class:`~.model.LibraryDoc` instance.
This factory method is the recommended API to generate keyword documentation
programmatically. It should be imported via the :mod:`robot.libdoc` module.
Example::
from robot.libdoc import LibraryDocumentation
lib = LibraryDocumentation('OperatingSystem')
print(lib.name, lib.version)
for kw in lib.keywords:
print(kw.name)
"""
builder = DocumentationBuilder(library_or_resource)
libdoc = _build(builder, library_or_resource)
if name:
Expand Down
4 changes: 4 additions & 0 deletions src/robot/libdocpkg/model.py
Expand Up @@ -27,6 +27,7 @@


class LibraryDoc:
"""Documentation for a library, a resource file or a suite file."""

def __init__(self, name='', doc='', version='', type='LIBRARY', scope='TEST',
doc_format='ROBOT', source=None, lineno=-1):
Expand Down Expand Up @@ -67,10 +68,12 @@ def doc_format(self, format):

@setter
def inits(self, inits):
"""Initializer docs as :class:`~KeywordDoc` instances."""
return self._process_keywords(inits)

@setter
def keywords(self, kws):
"""Keyword docs as :class:`~KeywordDoc` instances."""
return self._process_keywords(kws)

@setter
Expand Down Expand Up @@ -146,6 +149,7 @@ def to_json(self, indent=None, include_private=True, theme=None):


class KeywordDoc(Sortable):
"""Documentation for a single keyword or an initializer."""

def __init__(self, name='', args=None, doc='', shortdoc='', tags=(), private=False,
deprecated=False, source=None, lineno=-1, parent=None):
Expand Down
4 changes: 4 additions & 0 deletions utest/libdoc/test_libdoc_api.py
Expand Up @@ -43,6 +43,10 @@ def test_quiet(self):
with open(output) as f:
assert '"name": "String"' in f.read()

def test_LibraryDocumentation(self):
doc = libdoc.LibraryDocumentation('OperatingSystem')
assert_equal(doc.name, 'OperatingSystem')


if __name__ == '__main__':
unittest.main()

0 comments on commit 6c92dd4

Please sign in to comment.