Skip to content

Commit

Permalink
Use Autoapi instead of Autodoc to generate Python docs
Browse files Browse the repository at this point in the history
Autoapi uses a custom parser to read in the doc strings and doesn't need
to include the python modules.
This allows to generate the docs even without full build of the library,
we just need to run swig but there is no need to compile the library
with the swig layer to create working Python module.
  • Loading branch information
kontura committed Jan 24, 2023
1 parent 704a7f7 commit 5ce8f5a
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions dnf5.spec
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ BuildRequires: pkgconfig(zck) >= %{zchunk_version}
BuildRequires: python3dist(breathe)
BuildRequires: python3dist(sphinx) >= 4.1.2
BuildRequires: python3dist(sphinx-rtd-theme)
BuildRequires: python3dist(sphinx-autoapi)
%endif

%if %{with sanitizers}
Expand Down
2 changes: 1 addition & 1 deletion doc/api/python/libdnf5_base_base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Base
====


.. autoclass:: libdnf5.base.Base
.. autoapiclass:: libdnf5.base.Base
:members:
2 changes: 1 addition & 1 deletion doc/api/python/libdnf5_base_goal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Goal
====


.. autoclass:: libdnf5.base.Goal
.. autoapiclass:: libdnf5.base.Goal
:members:
2 changes: 1 addition & 1 deletion doc/api/python/libdnf5_repo_repo_query.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ RepoQuery
=========


.. autoclass:: libdnf5.repo.RepoQuery
.. autoapiclass:: libdnf5.repo.RepoQuery
:members:
4 changes: 2 additions & 2 deletions doc/api/python/libdnf5_rpm_package.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Package
=======

.. autoclass:: libdnf5.rpm.Package
.. autoapiclass:: libdnf5.rpm.Package
:members:


Checksum
--------

.. autoclass:: libdnf5.rpm.Checksum
.. autoapiclass:: libdnf5.rpm.Checksum
:members:
2 changes: 1 addition & 1 deletion doc/api/python/libdnf5_rpm_package_query.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ PackageQuery
============


.. autoclass:: libdnf5.rpm.PackageQuery
.. autoapiclass:: libdnf5.rpm.PackageQuery
:members:
16 changes: 15 additions & 1 deletion doc/conf.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ except NameError:
libdnf_docdir = os.path.abspath(".")

sys.path.insert(0, os.path.join(libdnf_docdir, "sphinx"))
sys.path.insert(0, os.path.join(libdnf_docdir, "../bindings/python3"))

# -- Project information -----------------------------------------------------

Expand All @@ -40,11 +39,26 @@ needs_sphinx = '4.1.2'
# ones.
extensions = [
'breathe',
'autoapi.extension',
# In order to use directives (autoapiclass) we need autodoc extension:
# https://sphinx-autoapi.readthedocs.io/en/latest/reference/directives.html
'sphinx.ext.autodoc',
]
breathe_projects = {'dnf5': '@CMAKE_CURRENT_BINARY_DIR@/xml/'}
breathe_default_project = 'dnf5'

autoapi_type = 'python'
autoapi_dirs = ['@CMAKE_CURRENT_BINARY_DIR@/../bindings/python3/libdnf5', '@CMAKE_CURRENT_BINARY_DIR@/../bindings/python3/libdnf5_cli']
autoapi_root = "api/python/autoapi"
autoapi_python_use_implicit_namespaces = True

# We don't want to automatically generate the full documentation.
# Instead we use directives, this allows greater control and both
# cpp and python docs can have the same look and layout.
autoapi_generate_api_docs = False
autoapi_add_toctree_entry = False
autoapi_add_objects_to_toctree = False

if sphinx.version_info[:3] > (4, 0, 0):
tags.add('sphinx4')
extensions += ['dbusdoc']
Expand Down
1 change: 1 addition & 0 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
breathe
sphinx-autoapi

0 comments on commit 5ce8f5a

Please sign in to comment.