Skip to content

Commit

Permalink
Merge pull request #116 from StreamHPC/fix_settings_windows_path
Browse files Browse the repository at this point in the history
Fix settings windows path, windows test fixes
  • Loading branch information
mb-emag authored Oct 20, 2023
2 parents b9ae21d + aa0324a commit 9e6bf81
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
30 changes: 22 additions & 8 deletions doxysphinx/doxygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import shutil
from dataclasses import dataclass
from pathlib import Path
from typing import Any, Dict, List, Union
from typing import Any, Dict, List, Tuple, Union, cast

import pyjson5

Expand Down Expand Up @@ -98,7 +98,7 @@ def _parse_stdout(text: str) -> ConfigDict:
pure_text = os.linesep.join([line for line in lines if _is_config_line(line)])

ParserElement.set_default_whitespace_chars(" \t")
line_end = LineEnd() if os.linesep == "\n" else White("\r\n")
line_end = White("\r\n") | LineEnd()

doxy_flag = Word(srange("[A-Z_]")) + FollowedBy("=")
list_items = delimited_list(
Expand Down Expand Up @@ -162,6 +162,18 @@ class DoxygenSettingsValidator:
}
"""A dictionary containing further optional settings for the doxygen config."""

@staticmethod
def _normalize_option(key: str, value: Union[str, List[str]]) -> Union[str, List[str]]:
"""Normalize incoming value before comparing to recommended/mandatory setting."""
if key in ("OUTPUT_DIRECTORY", "GENERATE_TAGFILE"):
return Path(cast(str, value)).as_posix()

return value

@classmethod
def _normalize_item(cls, kv: Tuple[str, Union[str, List[str]]]) -> Tuple[str, Union[str, List[str]]]:
return (kv[0], cls._normalize_option(kv[0], kv[1]))

validation_errors: List[str] = []
"""List of the validation errors including the doxyflag with its used and the correct value."""
absolute_out: Path
Expand Down Expand Up @@ -205,10 +217,10 @@ def _validate_doxygen_out_dirs(self, config: ConfigDict, sphinx_source_dir: Path
self.absolute_out = path_resolve(out)
stringified_out = str(out) if out.is_absolute() else f'"{out}" (resolved to "{self.absolute_out}")'

self.mandatory_settings["OUTPUT_DIRECTORY"] = str(config["OUTPUT_DIRECTORY"])
self.mandatory_settings["OUTPUT_DIRECTORY"] = Path(cast(str, config["OUTPUT_DIRECTORY"])).as_posix()

if path_is_relative_to(out, sphinx_source_dir):
self.optional_settings["GENERATE_TAGFILE"] = os.path.relpath(out / "tagfile.xml", doxygen_cwd)
self.optional_settings["GENERATE_TAGFILE"] = out.joinpath("tagfile.xml").relative_to(doxygen_cwd).as_posix()
return True
else:
self.optional_settings["GENERATE_TAGFILE"] = "docs/doxygen/demo/html/tagfile.xml" # default value
Expand All @@ -222,7 +234,7 @@ def _validate_doxygen_recommended_settings(self, settings: ConfigDict) -> bool:
imported_settings = settings
target_settings = self.mandatory_settings
validation_successful = True
if all(item in imported_settings.items() for item in target_settings.items()):
if all(self._normalize_item(item) in imported_settings.items() for item in target_settings.items()):
return validation_successful

contained_settings_target = {
Expand All @@ -238,7 +250,8 @@ def _validate_doxygen_recommended_settings(self, settings: ConfigDict) -> bool:
validation_successful = False

for key in contained_settings_target.keys():
if not contained_settings_target[key] == target_settings[key]:
contained_setting = self._normalize_option(key, contained_settings_target[key])
if not contained_setting == target_settings[key]:
self.validation_errors.append(
(
f"Error: Wrong value {contained_settings_target[key]} for {key}, {target_settings[key]} is required."
Expand All @@ -252,7 +265,7 @@ def _validate_doxygen_optional_settings(self, settings: ConfigDict) -> bool:
imported_settings = settings
target_settings = self.optional_settings
validation_successful = True
if all(item in imported_settings.items() for item in target_settings.items()):
if all(self._normalize_item(item) in imported_settings.items() for item in target_settings.items()):
return validation_successful

contained_settings_target = {
Expand All @@ -268,7 +281,8 @@ def _validate_doxygen_optional_settings(self, settings: ConfigDict) -> bool:
validation_successful = False

for key in contained_settings_target.keys():
if not contained_settings_target[key] == target_settings[key]:
contained_setting = self._normalize_option(key, contained_settings_target[key])
if not contained_setting == target_settings[key]:
self.validation_errors.append(
(
f"Hint: Wrong value {contained_settings_target[key]} for {key}, {target_settings[key]} is recommended."
Expand Down
3 changes: 2 additions & 1 deletion tests/doxygen/test_doxyfile_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def test_doxyfile_reader_lineendings_workasexpected(load_input, expected_config:

@pytest.fixture
def load_input(request):
return request.param.read_text()
# Don't replace newlines with '\n', subprocess.stdout.decode() doesn't either
return request.param.open(newline="").read()


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/doxygen/test_doxysettings_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def update_dict(params: ConfigDict):
(
update_dict({"OUTPUT_DIRECTORY": "/em-hackathon/code"}),
[
f'The doxygen OUTPUT_DIR of "{"/em-hackathon/code" + "/html"}" defined in the doxyfile'
f'The doxygen OUTPUT_DIR of "{Path.cwd().joinpath("/em-hackathon/code", "html")}" defined in the doxyfile'
f' is not in a sub-path of the sphinx source directory "{Path.cwd()}".'
], # wrong output directory
),
Expand Down

0 comments on commit 9e6bf81

Please sign in to comment.