diff --git a/doc/rtd_build.py b/doc/rtd_build.py index bbca8da2f..2a0a718c2 100644 --- a/doc/rtd_build.py +++ b/doc/rtd_build.py @@ -2,13 +2,6 @@ import sys import subprocess - -if os.environ.get("READTHEDOCS") != "True": - print("This setup.py is supposed to be used only to build documentation in Read the Docs.") - print("Use cmake && make doc instead to build documentation locally") - sys.exit(1) - - DIR = os.path.abspath(os.path.dirname(__file__)) @@ -40,37 +33,43 @@ def generate_bindings_from_dir(in_dir, out_dir): ] + swig_includes + [os.path.join(in_dir, in_file)], cwd=DIR, check=True) -# configure the .in files -configure("Doxyfile.in", "Doxyfile", { - "@CMAKE_SOURCE_DIR@": os.path.join(DIR, "..")}) -configure("conf.py.in", "conf.py", { - "@CMAKE_CURRENT_BINARY_DIR@": DIR, "@AUTOAPI_EXTENSION@": "\'autoapi.extension\',"}) - -# In place replace autodoc directives with autoapidoc directives. -# Our readthedocs workflow uses autoapidoc instead of autodoc because -# it is able to parse code generated by swig without including the -# module -> therefore there is no need for a full build in order to -# generate python docs. -for in_file in os.listdir(os.path.join(DIR + "/api/python")): - if in_file.endswith(".rst"): - file = os.path.join("api/python/", in_file) - configure(file, file, {"autoclass": "autoapiclass"}) - - -# run doxygen manually -print("Running doxygen...") -subprocess.run(["doxygen"], cwd=DIR, check=True) - - -# run swig manually to generate Python bindings which are then used to generate Python API docs -print("Running SWIG...") - -# libdnf5 -# Generate bindings outside of doc dir, into their python bindings dir. This has to match with path provided to autoapi_dirs in conf.py.in -generate_bindings_from_dir(os.path.join( - DIR + "/../bindings/libdnf5"), os.path.join(DIR + "/../bindings/python3/libdnf5")) - -# libdnf5-cli -generate_bindings_from_dir(os.path.join(DIR + "/../bindings/libdnf5_cli"), - os.path.join(DIR + "/../bindings/python3/libdnf5_cli")) - +def main(): + # configure the .in files + configure("Doxyfile.in", "Doxyfile", { + "@CMAKE_SOURCE_DIR@": os.path.join(DIR, "..")}) + configure("conf.py.in", "conf.py", { + "@CMAKE_CURRENT_BINARY_DIR@": DIR, "@AUTOAPI_EXTENSION@": "\'autoapi.extension\',"}) + + # In place replace autodoc directives with autoapidoc directives. + # Our readthedocs workflow uses autoapidoc instead of autodoc because + # it is able to parse code generated by swig without including the + # module -> therefore there is no need for a full build in order to + # generate python docs. + for in_file in os.listdir(os.path.join(DIR + "/api/python")): + if in_file.endswith(".rst"): + file = os.path.join("api/python/", in_file) + configure(file, file, {"autoclass": "autoapiclass"}) + + # run doxygen manually + print("Running doxygen...") + subprocess.run(["doxygen"], cwd=DIR, check=True) + + # run swig manually to generate Python bindings which are then used to generate Python API docs + print("Running SWIG...") + + # libdnf5 + # Generate bindings outside of doc dir, into their python bindings dir. This has to match with path provided to autoapi_dirs in conf.py.in + generate_bindings_from_dir(os.path.join( + DIR + "/../bindings/libdnf5"), os.path.join(DIR + "/../bindings/python3/libdnf5")) + + # libdnf5-cli + generate_bindings_from_dir(os.path.join(DIR + "/../bindings/libdnf5_cli"), + os.path.join(DIR + "/../bindings/python3/libdnf5_cli")) + + +if __name__ == "__main__": + if os.environ.get("READTHEDOCS") != "True": + print("This setup.py is supposed to be used only to build documentation in Read the Docs.") + print("Use cmake && make doc instead to build documentation locally") + sys.exit(1) + main()