Skip to content

Commit

Permalink
Merge pull request #121 from athackst/all-doxygen-config-file-formats
Browse files Browse the repository at this point in the history
Add support for whole spec of doxygen config format
  • Loading branch information
JakubAndrysek authored Jan 15, 2025
2 parents 6be6e41 + b781bf8 commit 7b25eda
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 9 deletions.
32 changes: 24 additions & 8 deletions mkdoxy/doxyrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import shutil
import re

from pathlib import Path, PurePath
from subprocess import PIPE, Popen
Expand Down Expand Up @@ -155,17 +156,32 @@ def str2dox_dict(self, dox_str: str) -> dict:
@return: (dict) Dictionary.
"""
dox_dict = {}
dox_str = re.sub(r'\\\s*\n\s*', '', dox_str)
pattern = r'^\s*([^=\s]+)\s*(=|\+=)\s*(.*)$'

try:
for line in dox_str.split("\n"):
if line.strip() == "":
if line.strip() == "" or line.startswith("#"):
continue
key, value = line.split(" = ")
if value == "YES":
dox_dict[key] = True
elif value == "NO":
dox_dict[key] = False
else:
dox_dict[key] = value
match = re.match(pattern, line)
if not match:
raise DoxygenCustomConfigNotValid(
f"Invalid line: '{line}'"
f"In custom Doxygen config file: {self.doxyConfigFile}\n"
f"Make sure the file is in standard Doxygen format."
f"Look at https://mkdoxy.kubaandrysek.cz/usage/advanced/."
)
key, operator, value = match.groups()
value = value.strip()
if operator == '=':
if value == "YES":
dox_dict[key] = True
elif value == "NO":
dox_dict[key] = False
else:
dox_dict[key] = value
if operator == '+=':
dox_dict[key] = f"{dox_dict[key]} {value}"
except ValueError as e:
raise DoxygenCustomConfigNotValid(
f"Invalid custom Doxygen config file: {self.doxyConfigFile}\n"
Expand Down
98 changes: 97 additions & 1 deletion tests/test_doxyrun.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from mkdoxy.doxyrun import DoxygenRun
import pytest
from mkdoxy.doxyrun import DoxygenCustomConfigNotValid, DoxygenRun


def test_dox_dict2str():
Expand Down Expand Up @@ -87,3 +88,98 @@ def test_str2dox_dict():
}

assert result == expected_result


def test_str2dox_dict_expanded_config():
dox_str = (
"# This is a comment \n"
"PROJECT_LOGO =\n"
'ABBREVIATE_BRIEF = "The $name class" \\ \n'
' is \n'
'FILE_PATTERNS = *.c \n'
'FILE_PATTERNS += *.cc\n'
'PREDEFINED = BUILD_DATE DOXYGEN=1\n'
)

doxygen_run = DoxygenRun(
doxygenBinPath="doxygen",
doxygenSource="/path/to/source/files",
tempDoxyFolder="/path/to/temp/folder",
doxyCfgNew={},
)

result = doxygen_run.str2dox_dict(dox_str)

expected_result = {
"PROJECT_LOGO": "",
"ABBREVIATE_BRIEF": '"The $name class" is',
"FILE_PATTERNS": "*.c *.cc",
"PREDEFINED": "BUILD_DATE DOXYGEN=1"
}

assert result == expected_result

def test_str2dox_dict_expanded_config_errors():
doxygen_run = DoxygenRun(
doxygenBinPath="doxygen",
doxygenSource="/path/to/source/files",
tempDoxyFolder="/path/to/temp/folder",
doxyCfgNew={},
)

dox_str = (
"ONLY_KEY\n"
)
error_message = str(f"Invalid line: 'ONLY_KEY'"
f"In custom Doxygen config file: None\n"
f"Make sure the file is in standard Doxygen format."
f"Look at https://mkdoxy.kubaandrysek.cz/usage/advanced/.")

with pytest.raises(DoxygenCustomConfigNotValid, match=error_message):
doxygen_run.str2dox_dict(dox_str)

dox_str = (
"= ONLY_VALUE\n"
)
error_message = str(f"Invalid line: '= ONLY_VALUE'"
f"In custom Doxygen config file: None\n"
f"Make sure the file is in standard Doxygen format."
f"Look at https://mkdoxy.kubaandrysek.cz/usage/advanced/.")

with pytest.raises(DoxygenCustomConfigNotValid, match=error_message):
doxygen_run.str2dox_dict(dox_str)

dox_str = (
"KEY WITH SPACES = VALUE\n"
)
error_message = str(f"Invalid line: 'KEY WITH SPACES = VALUE'"
f"In custom Doxygen config file: None\n"
f"Make sure the file is in standard Doxygen format."
f"Look at https://mkdoxy.kubaandrysek.cz/usage/advanced/.")

with pytest.raises(DoxygenCustomConfigNotValid, match=error_message):
doxygen_run.str2dox_dict(dox_str)

dox_str = (
"BAD_OPERATOR := VALUE\n"
)
error_message = str(f"Invalid line: 'BAD_OPERATOR := VALUE'"
f"In custom Doxygen config file: None\n"
f"Make sure the file is in standard Doxygen format."
f"Look at https://mkdoxy.kubaandrysek.cz/usage/advanced/.")

with pytest.raises(DoxygenCustomConfigNotValid, match=error_message):
doxygen_run.str2dox_dict(dox_str)

dox_str = (
"BAD_MULTILINE = BAD\n"
" VALUE\n"
)
error_message = str(f"Invalid line: ' VALUE'"
f"In custom Doxygen config file: None\n"
f"Make sure the file is in standard Doxygen format."
f"Look at https://mkdoxy.kubaandrysek.cz/usage/advanced/.")

with pytest.raises(DoxygenCustomConfigNotValid, match=error_message):
doxygen_run.str2dox_dict(dox_str)

0 comments on commit 7b25eda

Please sign in to comment.