From 849e3a516174755550506822b1eda5e9439fff4f Mon Sep 17 00:00:00 2001 From: Carl Gay Date: Sat, 7 Jun 2025 07:56:56 -0400 Subject: [PATCH] deft new application: set primary_domain Also reworked dylanize-sphinx-config to be a bit more robust to html_theme not being present in the original config generated by sphinx-quickstart. --- sources/commands/new-library.dylan | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/sources/commands/new-library.dylan b/sources/commands/new-library.dylan index 041a36a..61b2551 100644 --- a/sources/commands/new-library.dylan +++ b/sources/commands/new-library.dylan @@ -179,7 +179,7 @@ define function generate-sphinx-doc exit-status end function; -// Modify doc/source/conf.py to import dylan.domain and use the Furo theme. +// Modify doc/source/conf.py to import dylan.domain etc. define function dylanize-sphinx-config (config-file :: ) => () let lines = fs/with-open-file (stream = config-file, direction: #"input") @@ -190,20 +190,29 @@ define function dylanize-sphinx-config reverse(lines)) end end; + let imports = "\n" + "import os, sys\n" + "sys.path.insert(0, os.path.abspath('../../_packages/sphinx-extensions/current/src/sphinxcontrib'))\n" + "import dylan.domain\n"; + // We can't just append to the file because we want to replace the html_theme setting + // and imports need to come before 'extensions' is processed. fs/with-open-file (stream = config-file, direction: #"output", if-exists: #"replace") iterate loop (lines = lines, imports-done? = #f) - if (~empty?(lines)) + if (empty?(lines)) + // Write whatever extra Dylan config we need at the end of the file. + write(stream, + "\n" + "# -- Standard settings for Dylan documentation --------------------------\n" + "primary_domain = 'dylan'\n" + "html_theme = 'furo'\n"); + else let line = head(lines); - if (~imports-done? & ~starts-with?(line, "#")) + // Write imports after top comment. + when (~imports-done? & ~starts-with?(line, "#")) + write(stream, imports); imports-done? := #t; - write(stream, - "\nimport os, sys\n" - "sys.path.insert(0, os.path.abspath('../../_packages/sphinx-extensions/current/src/sphinxcontrib'))\n" - "import dylan.domain\n"); end; - if (starts-with?(line, "html_theme =")) - write(stream, "html_theme = 'furo'"); - else + unless (starts-with?(line, "html_theme ")) write(stream, line); end; new-line(stream);