Skip to content

Commit

Permalink
DOC: Avoid running examples twice (#26)
Browse files Browse the repository at this point in the history
* DOC: Avoid running examples twice

* CI: Add ON_CI environment variable

* DOC: Only keep doctree to shorten CI/CD

* CI: Use env var SPHINXBUILD_KEEP_DOCTREEDIR

* REFACT: Update comment

Co-authored-by: Devin <38879940+dcrawforAtAnsys@users.noreply.github.com>

---------

Co-authored-by: Devin <38879940+dcrawforAtAnsys@users.noreply.github.com>
  • Loading branch information
SMoraisAnsys and Devin-Crawford authored Feb 26, 2024
1 parent c11c59c commit ee332e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ jobs:
.venv\Scripts\Activate.ps1
pip install --extra-index-url https://wheels.vtk.org .[ci]
# Use environment variable to keep the doctree and avoid redundant build for PDF pages
- name: Create HTML documentation
run: |
echo "SPHINXBUILD_KEEP_DOCTREEDIR=1" >> $GITHUB_ENV
.venv\Scripts\Activate.ps1
. .\doc\make.bat html
Expand All @@ -123,8 +125,11 @@ jobs:
path: doc/_build/html
retention-days: 7

# Use environment variable to remove the doctree after the build of PDF pages
# Keeping doctree could cause an issue, see https://github.com/ansys/pyaedt/pull/3844/files
- name: Create PDF documentation
run: |
echo "SPHINXBUILD_KEEP_DOCTREEDIR=0" >> $GITHUB_ENV
.venv\Scripts\Activate.ps1
. .\doc\make.bat pdf
Expand Down
18 changes: 11 additions & 7 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,16 @@ def directory_size(directory_path):

def remove_doctree(app, exception):
"""Remove the .doctree directory created during the documentation build."""
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.")

# 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(os.getenv("SPHINXBUILD_KEEP_DOCTREEDIR", False)):
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 copy_examples(app):
Expand All @@ -98,9 +104,9 @@ def copy_examples(app):
def remove_examples(app, exception):
"""Remove the doc/source/examples directory created during the documentation build."""
destination_dir = pathlib.Path(app.srcdir) / "examples"

size = directory_size(destination_dir)
logger.info(f"Removing directory {destination_dir} ({size} MB).")

shutil.rmtree(destination_dir, ignore_errors=True)
logger.info(f"Directory removed.")

Expand Down Expand Up @@ -283,7 +289,6 @@ def setup(app):
"sphinx.ext.autodoc",
"sphinx.ext.todo",
"sphinx.ext.autosummary",
"sphinx.ext.intersphinx",
"sphinx.ext.coverage",
"sphinx_copybutton",
"sphinx_design",
Expand All @@ -292,7 +297,6 @@ def setup(app):
"recommonmark",
"numpydoc",
"ansys_sphinx_theme.extension.linkcode",
# "myst_parser"
]

# MathJax config
Expand Down

0 comments on commit ee332e0

Please sign in to comment.