diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2018-05-20 19:53:53 +0200 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2018-05-20 19:53:53 +0200 |
commit | 194ed0b87c2a24a7f5bf8c092ab745b317031ad3 (patch) | |
tree | fa24681082988a94e77db2534af0f0f55f022bff | |
parent | 5292ffb366f97e4dc611dfd49a1dca7d1e934f4c (diff) | |
download | gitlab-194ed0b87c2a24a7f5bf8c092ab745b317031ad3.tar.gz |
[docs] update the sphinx extension for v4 objects
-rw-r--r-- | docs/ext/docstrings.py | 21 | ||||
-rw-r--r-- | docs/ext/gl_tmpl.j2 | 5 | ||||
-rw-r--r-- | docs/ext/manager_tmpl.j2 | 106 | ||||
-rw-r--r-- | docs/ext/object_tmpl.j2 | 32 |
4 files changed, 32 insertions, 132 deletions
diff --git a/docs/ext/docstrings.py b/docs/ext/docstrings.py index 32c5da1..5035f4f 100644 --- a/docs/ext/docstrings.py +++ b/docs/ext/docstrings.py @@ -53,23 +53,6 @@ class GitlabDocstring(GoogleDocstring): super(GitlabDocstring, self).__init__(docstring, config, app, what, name, obj, options) - if name and name.startswith('gitlab.v4.objects'): - return - - if getattr(self._obj, '__name__', None) == 'Gitlab': - mgrs = [] - gl = self._obj('http://dummy', private_token='dummy') - for item in vars(gl).items(): - if hasattr(item[1], 'obj_cls'): - mgrs.append(item) - self._parsed_lines.extend(self._build_doc('gl_tmpl.j2', - mgrs=sorted(mgrs))) - - # BaseManager - elif hasattr(self._obj, 'obj_cls') and self._obj.obj_cls is not None: + if name.startswith('gitlab.v4.objects') and name.endswith('Manager'): self._parsed_lines.extend(self._build_doc('manager_tmpl.j2', - cls=self._obj.obj_cls)) - # GitlabObject - elif hasattr(self._obj, 'canUpdate') and self._obj.canUpdate: - self._parsed_lines.extend(self._build_doc('object_tmpl.j2', - obj=self._obj)) + cls=self._obj)) diff --git a/docs/ext/gl_tmpl.j2 b/docs/ext/gl_tmpl.j2 deleted file mode 100644 index dbccbcc..0000000 --- a/docs/ext/gl_tmpl.j2 +++ /dev/null @@ -1,5 +0,0 @@ -{% for attr, mgr in mgrs %} -.. attribute:: {{ attr }} - - {{ mgr.__class__ | classref() }} manager for {{ mgr.obj_cls | classref() }} objects. -{% endfor %} diff --git a/docs/ext/manager_tmpl.j2 b/docs/ext/manager_tmpl.j2 index fee8a56..6e71c0c 100644 --- a/docs/ext/manager_tmpl.j2 +++ b/docs/ext/manager_tmpl.j2 @@ -1,84 +1,38 @@ -Manager for {{ cls | classref() }} objects. - -{% if cls.canUpdate %} -{{ cls | classref() }} objects can be updated. -{% else %} -{{ cls | classref() }} objects **cannot** be updated. +{% if cls._list_filters %} +**Object listing filters** +{% for item in cls._list_filters %} +- ``{{ item }}`` +{% endfor %} {% endif %} -{% if cls.canList %} -.. method:: list(**kwargs) - - Returns a list of objects of type {{ cls | classref() }}. - - Available keys for ``kwargs`` are: - - {% for k in cls.requiredListAttrs %} - * ``{{ k }}`` (required) - {% endfor %} - {% for k in cls.optionalListAttrs %} - * ``{{ k }}`` (optional) - {% endfor %} - * ``per_page`` (int): number of item per page. May be limited by the server. - * ``page`` (int): page to retrieve - * ``all`` (bool): iterate over all the pages and return all the entries - * ``sudo`` (string or int): run the request as another user (requires admin - permissions) +{% if cls._create_attrs %} +**Object Creation** +{% if cls._create_attrs[0] %} +Mandatory attributes: +{% for item in cls._create_attrs[0] %} +- ``{{ item }}`` +{% endfor %} {% endif %} - -{% if cls.canGet %} -{% if cls.getRequiresId %} -.. method:: get(id, **kwargs) - - Get a single object of type {{ cls | classref() }} using its ``id``. -{% else %} -.. method:: get(**kwargs) - - Get a single object of type {{ cls | classref() }}. +{% if cls._create_attrs[1] %} +Optional attributes: +{% for item in cls._create_attrs[1] %} +- ``{{ item }}`` +{% endfor %} {% endif %} - - Available keys for ``kwargs`` are: - - {% for k in cls.requiredGetAttrs %} - * ``{{ k }}`` (required) - {% endfor %} - {% for k in cls.optionalGetAttrs %} - * ``{{ k }}`` (optional) - {% endfor %} - * ``sudo`` (string or int): run the request as another user (requires admin - permissions) {% endif %} -{% if cls.canCreate %} -.. method:: create(data, **kwargs) - - Create an object of type {{ cls | classref() }}. - - ``data`` is a dict defining the object attributes. Available attributes are: - - {% for a in cls.requiredUrlAttrs %} - * ``{{ a }}`` (required if not discovered on the parent objects) - {% endfor %} - {% for a in cls.requiredCreateAttrs %} - * ``{{ a }}`` (required) - {% endfor %} - {% for a in cls.optionalCreateAttrs %} - * ``{{ a }}`` (optional) - {% endfor %} - - Available keys for ``kwargs`` are: - - * ``sudo`` (string or int): run the request as another user (requires admin - permissions) +{% if cls._update_attrs %} +**Object update** +{% if cls._update_attrs[0] %} +Mandatory attributes for object update: +{% for item in cls._update_attrs[0] %} +- ``{{ item }}`` +{% endfor %} +{% endif %} +{% if cls._update_attrs[1] %} +Optional attributes for object update: +{% for item in cls._update_attrs[1] %} +- ``{{ item }}`` +{% endfor %} {% endif %} - -{% if cls.canDelete %} -.. method:: delete(id, **kwargs) - - Delete the object with ID ``id``. - - Available keys for ``kwargs`` are: - - * ``sudo`` (string or int): run the request as another user (requires admin - permissions) {% endif %} diff --git a/docs/ext/object_tmpl.j2 b/docs/ext/object_tmpl.j2 deleted file mode 100644 index 4bb9070..0000000 --- a/docs/ext/object_tmpl.j2 +++ /dev/null @@ -1,32 +0,0 @@ -{% for attr_name, cls, dummy in obj.managers %} -.. attribute:: {{ attr_name }} - - {{ cls | classref() }} - Manager for {{ cls.obj_cls | classref() }} objects. - -{% endfor %} - -.. method:: save(**kwargs) - - Send the modified object to the GitLab server. The following attributes are - sent: - -{% if obj.requiredUpdateAttrs or obj.optionalUpdateAttrs %} - {% for a in obj.requiredUpdateAttrs %} - * ``{{ a }}`` (required) - {% endfor %} - {% for a in obj.optionalUpdateAttrs %} - * ``{{ a }}`` (optional) - {% endfor %} -{% else %} - {% for a in obj.requiredCreateAttrs %} - * ``{{ a }}`` (required) - {% endfor %} - {% for a in obj.optionalCreateAttrs %} - * ``{{ a }}`` (optional) - {% endfor %} -{% endif %} - - Available keys for ``kwargs`` are: - - * ``sudo`` (string or int): run the request as another user (requires admin - permissions) |