ansys / ansys-sphinx-theme

PyData-based Sphinx theme from the PyAnsys community
https://sphinxdocs.ansys.com
MIT License
22 stars 5 forks source link

Bug located in `get_autoapi_templates_dir_relative_path` #466

Open mhoeijm opened 4 weeks ago

mhoeijm commented 4 weeks ago

šŸ” Before submitting the issue

šŸž Description of the bug

Hi all,

My local documentation build fails since I cannot use get_autoapi_templates_dir_relative_path in conf.py when ansys-sphinx-theme is installed on a different mount than the conf.py. Relative paths cannot be resolved when on different mounts:

Traceback (most recent call last):
  File "C:\ProgramData\miniforge3\envs\my-python-env\lib\site-packages\sphinx\config.py", line 358, in eval_config_file
    exec(code, namespace)  # NoQA: S102
  File "D:\development\my-package\doc\source\conf.py", line 136, in <module>
    autoapi_template_dir = get_autoapi_templates_dir_relative_path(Path(__file__))
  File "C:\ProgramData\miniforge3\envs\my-python-env\lib\site-packages\ansys_sphinx_theme\__init__.py", line 101, in get_autoapi_templates_dir_relative_path       
    return os.path.relpath(str(AUTOAPI_TEMPLATES_PATH.absolute()), start=str(path.absolute()))
  File "C:\ProgramData\miniforge3\envs\my-python-env\lib\ntpath.py", line 718, in relpath
    raise ValueError("path is on mount %r, start on mount %r" % (
ValueError: path is on mount 'C:', start on mount 'D:'

Essentially this means that ansys-sphinx-theme must always be installed on the same mount as the package/conf.py that wishes to use the autoapi template.

My current workaround is to specify the absolute path to the autoapi templates directory in conf.py:

# Not working:
# autoapi_template_dir = get_autoapi_templates_dir_relative_path(Path(__file__))
# Local workaround:
autoapi_template_dir = r"C:\ProgramData\miniforge3\envs\my-python-env\Lib\site-packages\ansys_sphinx_theme\theme\ansys_sphinx_theme\_templates\autoapi"

šŸ“ Steps to reproduce

from ansys_sphinx_theme import get_autoapi_templates_dir_relative_path
from pathlib import Path

get_autoapi_templates_dir_relative_path(Path("D:"))

šŸ’» Which operating system are you using?

Windows

šŸ“€ Which ANSYS version are you using?

No response

šŸ Which Python version are you using?

3.10

šŸ“¦ Installed packages

ansys-sphinx-theme
Revathyvenugopal162 commented 3 weeks ago

472 is fixing the issue with the depth, once this PR closes and after a Patch release, using the autoapi theme option should resolves this issue https://sphinxdocs.ansys.com/version/stable/user-guide/autoapi.html

Revathyvenugopal162 commented 2 weeks ago

Ansys sphinx theme v1.0.7 is out with required fixes. We can test it in pyansys heart @mhoeijm and close this issue if it fixes.

mhoeijm commented 2 weeks ago

Thanks @Revathyvenugopal162. Unfortunately this still does not work for me (in a fresh 3.10 environment with just ansys-sphinx-theme installed):

from ansys_sphinx_theme import get_autoapi_templates_dir_relative_path
from pathlib import Path

get_autoapi_templates_dir_relative_path(Path("D:"))

Note that my virtual environment is on C:

Revathyvenugopal162 commented 2 weeks ago

It's no longer necessary to import this function from the Ansys Sphinx theme; autoapi is now a theme option. I've opened a PR to address this issue in PyAnsys Heart and have updated the dependencies (Sphinx and AutoAPI) as part of the PR. If needed, I can also include a link to the documentation in the PR.