diff --git a/yardang/build.py b/yardang/build.py index 390f9c84..49e2ec14 100644 --- a/yardang/build.py +++ b/yardang/build.py @@ -560,7 +560,7 @@ def customize(args): llms_args = {} for config_option, default in { "llms_enabled": False, - "llms_description": "", + "llms_description": get_config(section="description", base="project") or "", "llms_full_build": True, }.items(): toml_key = config_option.replace("llms_", "").replace("_", "-") diff --git a/yardang/tests/test_llms.py b/yardang/tests/test_llms.py index d6343211..90cc0ced 100644 --- a/yardang/tests/test_llms.py +++ b/yardang/tests/test_llms.py @@ -2,6 +2,8 @@ from pathlib import Path from subprocess import Popen +import pytest +import toml from sphinx.cmd.build import build_main from yardang.build import generate_docs_configuration @@ -51,6 +53,37 @@ def test_generated_configuration_enables_yardang_llms(tmp_path, monkeypatch): assert not (tmp_path / "conf.py").exists() +@pytest.mark.parametrize("config_base", ["tool.yardang", "tool.custom.docs"]) +@pytest.mark.parametrize( + ("llms_description", "project_description", "expected"), + [ + (None, "Project overview", "Project overview"), + ("LLM overview", "Project overview", "LLM overview"), + (None, None, "General documentation description"), + ("", "Project overview", "General documentation description"), + ], +) +def test_llms_description_fallback(tmp_path, monkeypatch, config_base, llms_description, project_description, expected): + _write_project(tmp_path) + configuration = toml.load(tmp_path / "pyproject.toml") + if project_description is not None: + configuration["project"]["description"] = project_description + llms_configuration = configuration["tool"]["yardang"]["llms"] + if llms_description is None: + del llms_configuration["description"] + else: + llms_configuration["description"] = llms_description + if config_base == "tool.custom.docs": + configuration["tool"]["custom"] = {"docs": configuration["tool"].pop("yardang")} + (tmp_path / "pyproject.toml").write_text(toml.dumps(configuration)) + monkeypatch.chdir(tmp_path) + + with generate_docs_configuration(config_base=config_base, description="General documentation description") as conf_dir: + conf_content = (Path(conf_dir) / "conf.py").read_text() + + assert f'yardang_llms_description = """{expected}"""' in conf_content + + def test_build_generates_llms_outputs_in_one_sphinx_process(tmp_path, monkeypatch): _write_project(tmp_path) monkeypatch.chdir(tmp_path)