Skip to content

Commit

Permalink
CI: Improve time to create PDF file
Browse files Browse the repository at this point in the history
Note: Now we leverage the doctree to create the PDF file after
the HTML file. The doctree is then deleted to avoid the issue
we had with the upload step

Related to: #3844
  • Loading branch information
SMoraisAnsys committed Mar 13, 2024
1 parent 04193e2 commit 24ea96c
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from docutils.parsers.rst import Directive
from docutils import nodes
from sphinx import addnodes
from sphinx.util import logging
import shutil

# <-----------------Override the sphinx pdf builder---------------->
Expand All @@ -40,6 +41,12 @@ def visit_desc_content(self, node: Element) -> None:

# <----------------- End of sphinx pdf builder override---------------->


logger = logging.getLogger(__name__)


# Sphinx event hooks

class PrettyPrintDirective(Directive):
"""Renders a constant using ``pprint.pformat`` and inserts into the document."""
required_arguments = 1
Expand Down Expand Up @@ -69,10 +76,29 @@ def autodoc_skip_member(app, what, name, obj, skip, options):
# return True if exclude else None


def directory_size(directory_path):
"""Compute the size (in mega bytes) of a directory."""
res = 0
for path, _, files in os.walk(directory_path):
for f in files:
fp = os.path.join(path, f)
res += os.stat(fp).st_size
# Convert in mega bytes
res /= 1e6
return res

def remove_doctree(app, exception):
"""Remove the .doctree directory created during the documentation build.
"""
shutil.rmtree(app.doctreedir)
"""Remove the .doctree directory created during the documentation build."""

# Keep the doctree to avoid creating it twice. This is typically helpful in CI/CD
# where we want to build both HTML and PDF pages.
if bool(int(os.getenv("SPHINXBUILD_KEEP_DOCTREEDIR", "0"))):
logger.info(f"Keeping directory {app.doctreedir}.")
else:
size = directory_size(app.doctreedir)
logger.info(f"Removing doctree {app.doctreedir} ({size} MB).")
shutil.rmtree(app.doctreedir, ignore_errors=True)
logger.info(f"Doctree removed.")


def setup(app):
Expand Down Expand Up @@ -324,7 +350,6 @@ def setup(app):
"api_key": os.getenv("MEILISEARCH_PUBLIC_API_KEY", ""),
"index_uids": {
f"pyaedt-v{get_version_match(__version__).replace('.', '-')}": "PyAEDT",
f"pyedb-v{get_version_match(__version__).replace('.', '-')}": "EDB API",
},
},
}
Expand Down

0 comments on commit 24ea96c

Please sign in to comment.