Advanced usage
Using Sphinx’s Makefile
Sphinx by default generates a Makefile
,
so you can build your documentation with one command:
$ make html
But when building multiple projects, they will share the same output directory.
Change the Makefile
as follows to set a different build
directory for each project.
# Put your default project here.
PROJECT ?= user
BUILDDIR = _build/$(PROJECT)
Then you can build your documentation with:
# Will build the user project at _build/user/html/
$ make html
# Will build the dev project at _build/dev/html/
$ PROJECT=dev make html
Manually changing settings based on the current project
If the config
or use_config_file
options aren’t enough,
you can change the settings for each project manually.
Using one conf.py file
# File: docs/conf.py
from multiproject.utils import get_project
extensions = [
"multiproject",
]
multiproject_projects = {
"user": {},
"dev": {},
}
current_project = get_project(multiproject_projects)
locale_dirs = [f"{current_project}/locale/"]
if current_project == "user":
language = "en"
extensions += ["custom.extension"]
project = "User Documentation"
elif current_project == "dev":
language = "es"
project = "Development documentation"
Using multiple conf.py files
# File: docs/conf.py
extensions = [
"multiproject",
]
multiproject_projects = {
# Set `use_config_file` to false
# to avoid including the files twice.
"user": {
"use_config_file": False,
},
"dev": {
"use_config_file": False,
},
}
current_project = get_project(multiproject_projects)
# Set all values directly
# -----------------------
if current_project == 'user':
# File: docs/user/conf.py
from user.conf import *
elif current_project == 'dev':
# File: docs/dev/conf.py
from dev.conf import *
# Set value by value
# ------------------
if current_project == 'user':
# File: docs/user/conf.py
import user.conf as config
elif current_project == 'dev':
# File: docs/dev/conf.py
import dev.conf as config
# Replace the original values.
project = config.project
version = config.version
language = config.language
# Extending the original value.
extensions += config.extensions