Skip to content

Commit d0dc1c4

Browse files
fix: autoapi relative directory path wrt tox env (#494)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 0a0d6b8 commit d0dc1c4

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

doc/changelog.d/494.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix: ``autoapi`` relative directory path wrt ``tox`` env

src/ansys_sphinx_theme/extension/autoapi.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"""Module containing an extension for creating Sphinx AutoAPI templates for the Ansys Sphinx Theme.""" # noqa: E501
2424

2525
import os
26+
from pathlib import Path
2627
from typing import Any, Dict
2728

2829
from sphinx.application import Sphinx
@@ -79,11 +80,15 @@ def prepare_jinja_env(jinja_env) -> None:
7980
app.config["autoapi_member_order"] = autoapi.get("member_order", "bysource")
8081

8182
# HACK: The ``autoapi_dirs`` should be given as a relative path to the conf.py.
82-
relative_autoapi_dir = os.path.relpath(
83-
autoapi.get("directory", "src/ansys"), start=str(app.confdir / "conf.py")
84-
)
85-
app.config["autoapi_dirs"] = [relative_autoapi_dir]
86-
print(f"AutoAPI directories: {app.config['autoapi_dirs']}")
83+
autoapi_dir = autoapi.get("directory", "src/ansys")
84+
# assume the docs are in doc/source directory
85+
root_dir = Path(app.srcdir).resolve().parent.parent
86+
path_to_autoapi_dir = (root_dir / autoapi_dir).resolve()
87+
if path_to_autoapi_dir.exists():
88+
relative_autoapi_dir = os.path.relpath(path_to_autoapi_dir, start=app.srcdir)
89+
else:
90+
relative_autoapi_dir = autoapi_dir
91+
app.config["autoapi_dirs"] = [str(relative_autoapi_dir)]
8792

8893

8994
def setup(app: Sphinx) -> Dict[str, Any]:

0 commit comments

Comments
 (0)