Skip to content

Commit e3ba5e5

Browse files
authored
Fix MkDocs build from template instances (#517)
Resolves #515 - Updates `mkdocs.yml` configuration in template to use structure required by current MkDocs. - Fixes TOML `tox` configuration for `docs` environment to use required array of arrays syntax. Leaving this as a draft for now as we probably want to add a test for building MkDocs site from a template instance to catch things like this in future, ideally by running `tox -e docs` as well as `mkdocs build` to also catch error in `tox` configuration. I am not sure whether we would want to add `tox` as a development dependency here, or create a temporary virtual environment as suggested also in #516, install `tox` there and test running `tox -e docs` (plus potentially default test environment)?
1 parent f104af2 commit e3ba5e5

File tree

5 files changed

+44
-11
lines changed

5 files changed

+44
-11
lines changed

tests/data/test_package_generation/mkdocs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ plugins:
4747
default_handler: python
4848
handlers:
4949
python:
50-
docstring_style: google
51-
import:
50+
inventories:
5251
- "https://docs.python.org/3/objects.inv"
5352
options:
53+
docstring_style: google
5454
show_submodules: true
5555
paths: [src]
5656
- include-markdown:

tests/data/test_package_generation/pyproject.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ env_run_base = {commands = [
127127
"test",
128128
]}
129129
env.docs = {commands = [
130-
"mkdocs",
131-
"build",
132-
"--strict",
130+
[
131+
"mkdocs",
132+
"build",
133+
"--strict",
134+
],
133135
], extras = [
134136
"docs",
135137
]}

tests/test_package_generation.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def test_pip_installable(
128128
def test_optional_funder(
129129
tmp_path: pathlib.Path, generate_package: typing.Callable, funder: str
130130
) -> None:
131-
"""Test package generation."""
131+
"""Test specifying funder or not in package generation."""
132132
config = {
133133
"github_owner": "test-user",
134134
"project_short_description": "description",
@@ -149,3 +149,32 @@ def test_optional_funder(
149149
f"## Acknowledgements\n\nThis work was funded by {config['funder']}."
150150
in readme_text
151151
), readme_text
152+
153+
154+
def test_docs_build(
155+
tmp_path: pathlib.Path,
156+
venv: pytest_venv.VirtualEnvironment,
157+
generate_package: typing.Callable,
158+
) -> None:
159+
"""Test documentation build from package created from template."""
160+
config = {
161+
"github_owner": "test-user",
162+
"project_short_description": "description",
163+
"project_name": "Cookiecutter Test",
164+
}
165+
generate_package(config, tmp_path)
166+
test_project_dir = tmp_path / "cookiecutter-test"
167+
venv.install("tox")
168+
tox_docs_process = subprocess.run( # noqa: S603
169+
[
170+
pathlib.Path(venv.bin) / "tox",
171+
"-e",
172+
"docs",
173+
],
174+
cwd=test_project_dir,
175+
capture_output=True,
176+
check=False,
177+
)
178+
assert tox_docs_process.returncode == 0, (
179+
f"Something went wrong with building docs: {tox_docs_process.stderr!r}"
180+
)

{{cookiecutter.project_slug}}/mkdocs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ plugins:
4747
default_handler: python
4848
handlers:
4949
python:
50-
docstring_style: google
51-
import:
50+
inventories:
5251
- "https://docs.python.org/3/objects.inv"
5352
options:
53+
docstring_style: google
5454
show_submodules: true
5555
paths: [src]
5656
- include-markdown:

{{cookiecutter.project_slug}}/pyproject.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,11 @@ env_run_base = {commands = [
133133
"test",
134134
]}
135135
env.docs = {commands = [
136-
"mkdocs",
137-
"build",
138-
"--strict",
136+
[
137+
"mkdocs",
138+
"build",
139+
"--strict",
140+
],
139141
], extras = [
140142
"docs",
141143
]}

0 commit comments

Comments
 (0)