diff --git a/packages/sphinx-codelinks/docs/changelog.rst b/packages/sphinx-codelinks/docs/changelog.rst index d6a42e46d..c16116b6e 100644 --- a/packages/sphinx-codelinks/docs/changelog.rst +++ b/packages/sphinx-codelinks/docs/changelog.rst @@ -59,6 +59,13 @@ New and Improved Sphinx-Needs workspace declares and type-checks against. There is no upper bound: Sphinx caps docutils per series itself. +- 🐛 ``src_trace_projects`` declared directly in ``conf.py`` are normalised before + ``src-trace`` reads them. + + Projects configured without ``ubproject.toml`` now get the same typed + ``source_discover_config`` and ``analyse_config`` objects as TOML-backed projects, so a + ``src-trace`` directive no longer fails with ``KeyError: 'source_discover_config'``. + - 🐛 ``sphinx_codelinks.__version__`` reported ``"0.1.0"``. It had said so since the first commit, through seven releases, while the distribution diff --git a/packages/sphinx-codelinks/src/sphinx_codelinks/config.py b/packages/sphinx-codelinks/src/sphinx_codelinks/config.py index 54bc9d3ad..e817ba188 100644 --- a/packages/sphinx-codelinks/src/sphinx_codelinks/config.py +++ b/packages/sphinx-codelinks/src/sphinx_codelinks/config.py @@ -637,6 +637,9 @@ class CodeLinksConfig: @classmethod def from_sphinx(cls, sphinx_config: _SphinxConfig) -> "CodeLinksConfig": obj = cls() + src_trace_projects = getattr(sphinx_config, "src_trace_projects", None) + if isinstance(src_trace_projects, dict): + generate_project_configs(src_trace_projects) super().__setattr__(obj, "_sphinx_config", sphinx_config) return obj diff --git a/packages/sphinx-codelinks/tests/test_src_trace.py b/packages/sphinx-codelinks/tests/test_src_trace.py index 0b458d73e..25d74f235 100644 --- a/packages/sphinx-codelinks/tests/test_src_trace.py +++ b/packages/sphinx-codelinks/tests/test_src_trace.py @@ -795,6 +795,32 @@ def _traced_project(root: Path, conf_extra: str, files: dict[str, str]) -> None: _PROJECT_P = '[codelinks.projects.p.source_discover]\nsrc_dir = "./src"\ncomment_type = "python"\n' +def test_conf_py_projects_are_normalized_for_src_trace( + tmp_path: Path, + make_app: Callable[..., SphinxTestApp], +) -> None: + """Projects declared in ``conf.py`` get the same typed config as TOML projects.""" + _traced_project( + tmp_path, + "src_trace_config_from_toml = None\n" + "src_trace_projects = {\n" + " 'p': {\n" + " 'source_discover': {\n" + " 'src_dir': './src',\n" + " 'comment_type': 'python',\n" + " },\n" + " 'analyse': {},\n" + " },\n" + "}\n", + {"src/a.py": _MARKER.format(tag="CONFPY")}, + ) + app = make_app(srcdir=tmp_path, freshenv=True) + app.build() + + html = Path(app.outdir, "index.html").read_text(encoding="utf-8") + assert "IMPL_CONFPY" in html + + def test_symlinked_toml_anchors_at_the_links_directory( tmp_path: Path, make_app: Callable[..., SphinxTestApp],