Skip to content
110 changes: 76 additions & 34 deletions docs/contribute/test-ulwazi-theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,64 @@ Ulwazi is a Sphinx theme built on Vanilla, with the base layout and functionalit

This guide outlines the steps required to use the Ulwazi theme in your Sphinx documentation project.

We recommend creating a new branch of your repository and testing Ulwazi in that branch.
You can build the Ulwazi-themed documentation locally from the branch or open a PR and view the changes in its RTD preview.

## Update the dependencies

In your project's Python requirements, replace the canonical-sphinx package with Ulwazi and its dependencies. The minimum set is:
In your project's Python requirements (`requirements.txt`), replace the Canonical Sphinx package with Ulwazi and its dependencies:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear to me what's meant here by "Ulwazi's dependencies". A lot of these extensions already exist in the default starter pack extensions.txt.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great point, that leads me to an idea of separating minimum dependencies from the ones we use in our Ulwazi demo. I'll add it as a feature request to our GitHub issues.


```{code-block} text
```{code-block} diff
:caption: requirements.txt

sphinx
build
sphinx-autobuild
canonical-sphinx-config @ git+https://github.com/Canonical/canonical-sphinx-config.git@main
myst-parser~=4.0
sphinx-basic-ng
sphinxcontrib-jquery
beautifulsoup4
packaging
sphinxcontrib-svg2pdfconverter[CairoSVG]
sphinx-last-updated-by-git
sphinx-sitemap
ulwazi
- canonical-sphinx
+ sphinx
+ build
+ sphinx-autobuild
+ canonical-sphinx-config @ git+https://github.com/Canonical/canonical-sphinx-config.git@main
+ myst-parser~=4.0
+ sphinx-basic-ng
+ sphinxcontrib-jquery
+ beautifulsoup4
+ packaging
+ sphinxcontrib-svg2pdfconverter[CairoSVG]
+ sphinx-last-updated-by-git
+ sphinx-sitemap
+ sphinx-terminal
+ ulwazi
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add sphinx-modern-pdf-style here as well. If someone follows the simpler approach described below, then sphinx_modern_pdf_style is included in the extensions list in default_conf.py, and the instruction to add sphinx-modern-pdf-style to requirements.txt only appears in the instructions for the harder approach. Might as well include it in the default requirements.txt even if not every docs set needs it (not every docs set needs myst-parser either but it's included).

```

## Update the configuration
Be ready to add any other missing extensions if you see errors about them.

## Main configuration

Updating the project configuration is the most critical step in this process.

There are two main ways to do that:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
There are two main ways to do that:
There are two main ways:


* Simple way -- Adapt the [Sample `conf.py` for Ulwazi](https://github.com/canonical/ulwazi/blob/main/docs/default-conf.py) by adjusting the values for your specific documentation.
* Hard way -- Adapt your existing configuration by adding all required values.

We strongly recommend trying the first option (the simple way) first as it proved to be faster and less troublesome, yet enough for testing the theme.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
We strongly recommend trying the first option (the simple way) first as it proved to be faster and less troublesome, yet enough for testing the theme.
We strongly recommend trying the simple way first as it proved to be faster and less troublesome, yet enough for testing the theme.

Choose the hard way if your project already has significant `conf.py` customisation that would be difficult to recreate from the Sample `conf.py` for Ulwazi.

### The simple way

Here is the simple way of trying Ulwazi:

1. Copy the [Sample `conf.py` for Ulwazi](https://github.com/canonical/ulwazi/blob/main/docs/default-conf.py) file inside your documentation folder.
2. Rename the old `conf.py` to some other name, like `old-conf.py`.
3. Rename the sample configuration file to `conf.py`.
4. Open the old and new files side by side and update relevant values in the new configuration file for your specific product and documentation.

This is the most important and tricky part -- updating the project configuration. A reference `conf.py` with all the required configuration and TODO markers is provided in the Ulwazi repository as [`default-conf.py`](https://github.com/canonical/ulwazi/blob/main/docs/default-conf.py). Copy it as the starting point for a new documentation set, or use it as a checklist when migrating an existing one.
### The hard way

### Set the theme
The following instructions describe the modifications needed to support Ulwazi in an existing `conf.py` file.
Use this approach if you want to preserve as much of your original `conf.py` as possible, for example in a heavily customised deployment or when troubleshooting a configuration issue.
Comment thread
izmalk marked this conversation as resolved.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Use this approach if you want to preserve as much of your original `conf.py` as possible, for example in a heavily customised deployment or when troubleshooting a configuration issue.
Use this approach if you want to preserve as much of your original `conf.py` as possible, for example in a heavily customized deployment or when troubleshooting a configuration issue.


For an example of all the changes, see the [Charmed Apache Kafka Ulwazi PR](https://github.com/canonical/kafka-operator/pull/444/files#diff-85933aa74a2d66c3e4dcdf7a9ad8397f5a7971080d34ef1108296a7c6b69e7e3).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: The PR includes many other changes (formatting, etc.) that need to be ignored to see the Ulwazi-specific ones.

If providing an example diff/PR like this, it should be against the vanilla SP and free of anything else than the Ulwazi changes.

I realize that's likely out of scope of this PR, so I'd rather leave this out.


#### Set the theme

Tell Sphinx to use Ulwazi as the theme:

Expand All @@ -49,26 +80,28 @@ Tell Sphinx to use Ulwazi as the theme:
html_theme = "ulwazi"
```

### Update the extensions
#### Update the extensions

In the list of extensions, replace canonical-sphinx with Ulwazi, and its dependencies:
In the list of extensions, replace Canonical Sphinx with Ulwazi and its dependencies:

```{code-block} diff
:caption: extensions in conf\.py

-"canonical-sphinx~=0.6"
+"ulwazi"
-"canonical-sphinx~=0.6",
+"ulwazi",
+"sphinx_terminal",
+"canonical_sphinx_config",
+"myst_parser",
+"sphinxcontrib.jquery",
```

If you need PDF output, add `sphinx_modern_pdf_style` to the list.
If you need **PDF output**, add `sphinx_modern_pdf_style` to the extensions list and `sphinx-modern-pdf-style` to `requirements.txt`.

This is only a partial list. Your project may require additional extensions beyond those listed here.
```{caution}
Your project may require additional extensions beyond those listed here.
```

### Add the required variables
#### Add the required variables

Add and fill the following variables immediately before `html_context = {`:

Expand All @@ -91,10 +124,9 @@ product_page = <link-to-product-website>

If your project is written in reST, set `default_source_extension` to `".rst"`.

### Update the HTML context
#### Update the HTML context

You need to make several updates to the `html_context` dictionary.
For an example of all the changes, see the [Charmed Apache Kafka Ulwazi PR](https://github.com/canonical/kafka-operator/pull/444/files#diff-85933aa74a2d66c3e4dcdf7a9ad8397f5a7971080d34ef1108296a7c6b69e7e3).

The code snippets in this section might not match the exact layout of `html_context` in your `conf.py`.

Expand All @@ -108,7 +140,7 @@ Add these new variables, including the top-level variables you declared earlier:
"license": {
"name": "Apache-2.0", # TODO: set your license
"url": github_repo + "/blob/main/LICENSE",
}
},
```

Add these entries so the theme can display the project name and author without duplicating them:
Expand Down Expand Up @@ -180,7 +212,7 @@ Add the following parameters for the footer.
}
```

### Add syntax highlighting
#### Add syntax highlighting

Add these syntax highlighting settings after the list of extensions:

Expand All @@ -191,7 +223,7 @@ highlight_language = "none" # default
pygments_style = "autumn" # see https://pygments.org/styles for more
```

### Configure the sitemap
#### Configure the sitemap

Add the lastmod setting to the sitemap section:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

        Add the lastmod setting to the sitemap section:
      
      
        
        Add the `lastmod` setting to the sitemap section:

Note this has been in the starter pack for a while; maybe add "if it doesn't already exist."


Expand All @@ -201,7 +233,7 @@ Add the lastmod setting to the sitemap section:
sitemap_show_lastmod = True
```

### Configure PDF output
#### Configure PDF output

If you need to render your docs to PDF, add the following at the end of the configuration:

Expand All @@ -211,7 +243,7 @@ If you need to render your docs to PDF, add the following at the end of the conf
set_modern_pdf_config = True
```

### Update the copyright
#### Update the copyright

The Ulwazi theme expects a plain year string rather than the older {spellexception}`CC-BY-SA` format.

Expand All @@ -225,14 +257,24 @@ The license information is now conveyed through the "license" key in "html_conte

## Test the documentation

Once configuration is complete, review everything again and build it from scratch (cleaning out the existing build files first):
Once configuration is complete, make sure the required extensions are listed in both the `extensions` list in `conf.py` and the `requirements.txt` file.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth mentioning that extensions bundled with Sphinx (that start with sphinx.ext., such as sphinx.ext.intersphinx) are exceptions; they only need to be listed in conf.py.


Build the documentation from scratch by first cleaning out any existing build files:

```shell
cd docs
make clean
make run
```

This will start a local server at http://127.0.0.1:8000. Open it in your browser to verify the pages render correctly.
If the build fails, check the build logs to identify the cause.
Common issues are:

1. Missing extensions
2. Missing required values in `conf.py`

Fix any issues and rebuild.

Once the build succeeds, a local server starts at http://127.0.0.1:8000. Open that URL in your browser to verify that the pages render correctly.

Report issues or feature requests in the [Ulwazi GitHub repository](https://github.com/canonical/ulwazi/issues/new).
Loading