Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding MkDocs docs to template #319

Merged
merged 25 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a5f0d52
Adding MkDocs docs to template
matt-graham Mar 20, 2024
36a4fbd
Add new line in docstring to satisfy Ruff
matt-graham Mar 20, 2024
d33e871
Avoid repetition of docs dependencies
matt-graham Mar 21, 2024
d605092
Fix typo and make title case consistent
matt-graham Mar 21, 2024
ec12b11
Format frameworks as a list
matt-graham Mar 21, 2024
788c9f7
Add edit URI for GitHub links
matt-graham Mar 21, 2024
ebebf85
Use MkDocs recommended stricter validation
matt-graham Mar 21, 2024
0de39ae
Add GitHub social link
matt-graham Mar 21, 2024
81fa625
Include README and license content in docs
matt-graham Mar 21, 2024
248f1f3
Tweak copyright line
matt-graham Mar 21, 2024
0648c3a
Correct reference to docs dependencies
matt-graham Mar 21, 2024
04884a5
Rename license file in docs to make relative link from README work
matt-graham Mar 21, 2024
f16841b
Add edit buttons to docs
matt-graham Mar 21, 2024
414fd18
Merge branch 'main' into mmg/mkdocs-docs
paddyroddy Mar 22, 2024
442992e
Apply suggestions from code review
matt-graham Mar 22, 2024
2e67533
Reorder tox testenv sections
matt-graham Mar 22, 2024
f48174e
Add quotation marks around URL for consistency
matt-graham Mar 22, 2024
483a19e
Add vertical spacing between docs workflow job steps for consistency
matt-graham Mar 22, 2024
2f6bace
Adjust commented section indentation
matt-graham Mar 22, 2024
c36eb4f
Remove spaces on empty lines
matt-graham Mar 22, 2024
dfa918a
Add option to enable automatically docs to GitHub Pages to cookiecutter
matt-graham Mar 22, 2024
5c874cf
Adjust newlines and whitespace control in template to satisfy prettier
matt-graham Mar 22, 2024
c23d7e6
Switch from pymdownx.snippets extension to mkdocs-include-markdown-pl…
matt-graham Mar 22, 2024
832b262
Remove indentation in include-markdown directive to satisfy prettier
matt-graham Mar 22, 2024
fbb1d62
Update {{cookiecutter.project_slug}}/README.md
matt-graham Mar 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
"package_name": "{{cookiecutter.project_slug.replace('-', '_')}}",
"project_short_description": "A cookiecutter template with ARC recommendations.",
"initialise_git_repository": true,
"deploy_docs_to_github_pages": false,
"github_username": "{{cookiecutter.author_given_names.lower().replace(' ', '-')}}-{{cookiecutter.author_family_names.lower().replace(' ', '-')}}",
"min_python_version": ["3.9", "3.10", "3.11", "3.12"],
"max_python_version": ["3.12", "3.11", "3.10", "3.9"],
"license": ["MIT", "BSD-3", "GPL-3.0"],
"funder": "JBFC: The Joe Bloggs Funding Council"
"funder": "JBFC: The Joe Bloggs Funding Council",
"__prompts__": {
matt-graham marked this conversation as resolved.
Show resolved Hide resolved
"deploy_docs_to_github_pages": "Enable automatically deploying HTML documentation to GitHub Pages website on pushes to main"
}
}
3 changes: 3 additions & 0 deletions tests/test_package_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def test_package_generation(
"tests",
pathlib.Path(".github"),
pathlib.Path(".github") / "workflows",
"mkdocs.yml",
pathlib.Path("docs") / "index.md",
pathlib.Path("docs") / "api.md",
]
for f in expected_files:
full_path = test_project_dir / f
Expand Down
48 changes: 48 additions & 0 deletions {{cookiecutter.project_slug}}/.github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Documentation

on:
push:
branches:
- main
pull_request:

jobs:
docs:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4

- name: Cache tox
uses: actions/cache@v4
with:
path: .tox
key: tox-${{ '{{' }} hashFiles('pyproject.toml') {{ '}}' }}

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
cache: "pip"
cache-dependency-path: "pyproject.toml"

- name: Install tox
run: python -m pip install tox
- name: Build HTML documentation with tox
run: tox -e docs
{%- if cookiecutter.deploy_docs_to_github_pages %}
matt-graham marked this conversation as resolved.
Show resolved Hide resolved

# Automatically deploy documentation to a GitHub Pages website on pushing to main.
# Requires configuring the repository to deploy GitHub pages from a branch
# gh-pages (https://tinyurl.com/gh-pages-from-branch), which will be created the
# first time this workflow step is run.
- name: Publish documentation on GitHub pages
if: success() && github.event_name != 'pull_request'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ '{{' }} secrets.GITHUB_TOKEN {{ '}}' }}
publish_dir: site
publish_branch: gh-pages
user_name: "github-actions[bot]"
user_email: "github-actions[bot]@users.noreply.github.com"
{%- endif %}
27 changes: 24 additions & 3 deletions {{cookiecutter.project_slug}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
[![Tests status][tests-badge]][tests-link]
[![Linting status][linting-badge]][linting-link]
[![Documentation status][documentation-badge]][documentation-link]
[![License][license-badge]](./LICENSE.md)

<!--
Expand All @@ -16,6 +17,8 @@
[tests-link]: https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}/actions/workflows/tests.yml
[linting-badge]: https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}/actions/workflows/linting.yml/badge.svg
[linting-link]: https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}/actions/workflows/linting.yml
[documentation-badge]: https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}/actions/workflows/docs.yml/badge.svg
[documentation-link]: https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}/actions/workflows/docs.yml
[conda-badge]: https://img.shields.io/conda/vn/conda-forge/{{cookiecutter.project_slug}}
[conda-link]: https://github.com/conda-forge/{{cookiecutter.project_slug}}-feedstock
[pypi-link]: https://pypi.org/project/{{cookiecutter.project_slug}}/
Expand Down Expand Up @@ -51,9 +54,9 @@ Centre for Advanced Research Computing, University College London

<!-- TODO: can cookiecutter make a list of frameworks? -->

[Framework 1](https://something.com)
[Framework 2](https://something.com)
[Framework 3](https://something.com)
- [Framework 1](https://something.com)
- [Framework 2](https://something.com)
- [Framework 3](https://something.com)

## Getting Started

Expand Down Expand Up @@ -108,6 +111,24 @@ pytest tests

again from the root of the repository.

### Building Documentation

The MkDocs HTML documentation can be built locally by running

```sh
tox -e docs
```

from the root of the repository.
The built documentation will be written to `site`.

Alternatively to build and preview the documentation locally, in a Python environment
with the optional `docs` dependencies installed, run

```sh
mkdocs serve
```

## Roadmap

- [x] Initial Research
Expand Down
3 changes: 3 additions & 0 deletions {{cookiecutter.project_slug}}/docs/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{!
include-markdown "../LICENSE.md"
!}
3 changes: 3 additions & 0 deletions {{cookiecutter.project_slug}}/docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# API reference

::: {{cookiecutter.package_name}}
matt-graham marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions {{cookiecutter.project_slug}}/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{!
include-markdown "../README.md"
rewrite-relative-urls=false
!}
61 changes: 61 additions & 0 deletions {{cookiecutter.project_slug}}/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
site_name: "{{cookiecutter.project_name}}"
site_description: "Documentation website for {{cookiecutter.project_name}}"
site_author: "{{cookiecutter.author_given_names}} {{cookiecutter.author_family_names}}"
copyright: "Copyright © {% now 'utc', '%Y' %} {{cookiecutter.author_given_names}} {{cookiecutter.author_family_names}}"
repo_url: "https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}/"
repo_name: "{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}"
edit_uri: edit/main/docs/

validation:
omitted_files: warn
absolute_links: warn
unrecognized_links: warn

theme:
name: "material"
features:
- content.action.edit
palette:
- media: "(prefers-color-scheme)"
toggle:
icon: material/brightness-auto
name: Switch to light mode
- media: "(prefers-color-scheme: light)"
scheme: default
toggle:
icon: material/brightness-7
name: Switch to dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
toggle:
icon: material/brightness-4
name: Switch to system preference
icon:
repo: fontawesome/brands/github

nav:
- Overview: index.md
- API reference: api.md
- License: LICENSE.md

markdown_extensions:
- pymdownx.tasklist

plugins:
- search
- mkdocstrings:
default_handler: python
handlers:
python:
docstring_style: google
import:
- "https://docs.python.org/3/objects.inv"
matt-graham marked this conversation as resolved.
Show resolved Hide resolved
paths: [src]
- include-markdown:
opening_tag: "{!"
closing_tag: "!}"

extra:
social:
- icon: fontawesome/brands/github
link: "https://github.com/{{cookiecutter.github_username}}"
12 changes: 12 additions & 0 deletions {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ optional-dependencies = {dev = [
"ruff",
"tox",
"twine",
], docs = [
"mkdocs",
"mkdocs-include-markdown-plugin",
"mkdocs-material",
"mkdocstrings",
"mkdocstrings-python",
], test = [
"pytest",
"pytest-cov",
Expand Down Expand Up @@ -123,6 +129,12 @@ legacy_tox_ini = """
extras =
test

[testenv:docs]
commands =
mkdocs build --strict
extras =
docs

[tox]
env_list =
{%- for python_version in range(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
"""{{cookiecutter.package_name}} package."""
from ._version import __version__ # noqa: F401


def example_function(argument: str, keyword_argument: str = "default") -> str:
"""
Concatenate string arguments - an example function docstring.

Args:
argument: An argument.
keyword_argument: A keyword argument with a default value.

Returns:
The concatenation of `argument` and `keyword_argument`.

"""
return argument + keyword_argument