Skip to content

Commit

Permalink
doc rtd_build: use proper main() function
Browse files Browse the repository at this point in the history
  • Loading branch information
gotmax23 authored and kontura committed Dec 18, 2023
1 parent e42da64 commit 837bcef
Showing 1 changed file with 40 additions and 41 deletions.
81 changes: 40 additions & 41 deletions doc/rtd_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))


Expand Down Expand Up @@ -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()

0 comments on commit 837bcef

Please sign in to comment.