Skip to content

Commit

Permalink
Merge pull request #90 from JakubAndrysek/doxygen-path-check
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubAndrysek committed Apr 2, 2024
2 parents ebfa436 + fde20ba commit 929b14e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
4 changes: 1 addition & 3 deletions docs/usage/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mkdocs serve
## Configure custom Doxygen binary

By default, the plugin will use the `doxygen` binary from the system path. You can configure a custom binary using the `doxygen-bin-path` option.
If `doxygen-bin-path` is not found, the plugin will raise DoxygenBinPathNotValid exception.

- addad by [thb-sb](https://github.com/thb-sb)

Expand All @@ -34,6 +35,3 @@ plugins:
doxygen-bin-path: /path/to/doxygen
...
```


Hi, I have released new version, please try it and let me know if it has been fixed. Thanks
29 changes: 29 additions & 0 deletions mkdoxy/doxyrun.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import hashlib
import logging
import os
import shutil

from pathlib import Path, PurePath
from subprocess import PIPE, Popen
Expand Down Expand Up @@ -40,6 +42,14 @@ def __init__(
@param tempDoxyFolder: (str) Temporary folder for Doxygen.
@param doxyCfgNew: (dict) New Doxygen config options that will be added to the default config (new options will overwrite default options)
""" # noqa: E501

if not self.is_doxygen_valid_path(doxygenBinPath):
raise DoxygenBinPathNotValid(
f"Invalid Doxygen binary path: {doxygenBinPath}\n"
f"Make sure Doxygen is installed and the path is correct.\n"
f"Look at https://mkdoxy.kubaandrysek.cz/usage/advanced/#configure-custom-doxygen-binary."
)

self.doxygenBinPath: str = doxygenBinPath
self.doxygenSource: str = doxygenSource
self.tempDoxyFolder: str = tempDoxyFolder
Expand All @@ -62,6 +72,20 @@ def __init__(
self.doxyCfg.update(self.doxyCfgNew)
self.doxyCfgStr: str = self.dox_dict2str(self.doxyCfg)

def is_doxygen_valid_path(self, doxygen_bin_path: str) -> bool:
"""! Check if the Doxygen binary path is valid.
@details Accepts a full path or just 'doxygen' if it exists in the system's PATH.
@param doxygen_bin_path: (str) The path to the Doxygen binary or just 'doxygen'.
@return: (bool) True if the Doxygen binary path is valid, False otherwise.
"""
# If the path is just 'doxygen', search for it in the system's PATH
if doxygen_bin_path.lower() == "doxygen":
return shutil.which("doxygen") is not None

# Use pathlib to check if the provided full path is a file and executable
path = Path(doxygen_bin_path)
return path.is_file() and os.access(path, os.X_OK)

# Source of dox_dict2str: https://xdress-fabio.readthedocs.io/en/latest/_modules/xdress/doxygen.html#XDressPlugin
def dox_dict2str(self, dox_dict: dict) -> str:
"""! Convert a dictionary to a string that can be written to a doxygen config file.
Expand Down Expand Up @@ -155,3 +179,8 @@ def getOutputFolder(self) -> PurePath:
@return: (PurePath) Path to the XML output folder.
"""
return Path.joinpath(Path(self.tempDoxyFolder), Path("xml"))


# not valid path exception
class DoxygenBinPathNotValid(Exception):
pass

0 comments on commit 929b14e

Please sign in to comment.