Skip to content

mkdocs ¤

Callable for MkDocs.

Functions:

  • build

    Build the MkDocs documentation.

  • gh_deploy

    Deploy your documentation to GitHub Pages.

  • new

    Create a new MkDocs project.

  • run

    Run mkdocs.

  • serve

    Run the builtin development server.

build ¤

build(
    *,
    config_file: str | None = None,
    clean: bool | None = None,
    strict: bool | None = None,
    theme: str | None = None,
    directory_urls: bool | None = None,
    site_dir: str | None = None,
    quiet: bool = False,
    verbose: bool = False
) -> None

Build the MkDocs documentation.

Parameters:

  • config_file (str | None, default: None ) –

    Provide a specific MkDocs config.

  • clean (bool | None, default: None ) –

    Remove old files from the site_dir before building (the default).

  • strict (bool | None, default: None ) –

    Enable strict mode. This will cause MkDocs to abort the build on any warnings.

  • theme (str | None, default: None ) –

    The theme to use when building your documentation.

  • directory_urls (bool | None, default: None ) –

    Use directory URLs when building pages (the default).

  • site_dir (str | None, default: None ) –

    The directory to output the result of the documentation build.

  • quiet (bool, default: False ) –

    Silence warnings.

  • verbose (bool, default: False ) –

    Enable verbose output.

Source code in src/duty/callables/mkdocs.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
@lazy(name="mkdocs.build")
def build(
    *,
    config_file: str | None = None,
    clean: bool | None = None,
    strict: bool | None = None,
    theme: str | None = None,
    directory_urls: bool | None = None,
    site_dir: str | None = None,
    quiet: bool = False,
    verbose: bool = False,
) -> None:
    """Build the MkDocs documentation.

    Parameters:
        config_file: Provide a specific MkDocs config.
        clean: Remove old files from the site_dir before building (the default).
        strict: Enable strict mode. This will cause MkDocs to abort the build on any warnings.
        theme: The theme to use when building your documentation.
        directory_urls: Use directory URLs when building pages (the default).
        site_dir: The directory to output the result of the documentation build.
        quiet: Silence warnings.
        verbose: Enable verbose output.
    """
    cli_args = []

    if clean is True:
        cli_args.append("--clean")
    elif clean is False:
        cli_args.append("--dirty")

    if config_file:
        cli_args.append("--config-file")
        cli_args.append(config_file)

    if strict is True:
        cli_args.append("--strict")

    if theme:
        cli_args.append("--theme")
        cli_args.append(theme)

    if directory_urls is True:
        cli_args.append("--use-directory-urls")
    elif directory_urls is False:
        cli_args.append("--no-directory-urls")

    if site_dir:
        cli_args.append("--site_dir")
        cli_args.append(site_dir)

    run("build", *cli_args, quiet=quiet, verbose=verbose)

gh_deploy ¤

gh_deploy(
    *,
    config_file: str | None = None,
    clean: bool | None = None,
    message: str | None = None,
    remote_branch: str | None = None,
    remote_name: str | None = None,
    force: bool | None = None,
    no_history: bool | None = None,
    ignore_version: bool | None = None,
    shell: bool | None = None,
    strict: bool | None = None,
    theme: str | None = None,
    directory_urls: bool | None = None,
    site_dir: str | None = None,
    quiet: bool = False,
    verbose: bool = False
) -> None

Deploy your documentation to GitHub Pages.

Parameters:

  • config_file (str | None, default: None ) –

    Provide a specific MkDocs config.

  • clean (bool | None, default: None ) –

    Remove old files from the site_dir before building (the default).

  • message (str | None, default: None ) –

    A commit message to use when committing to the GitHub Pages remote branch. Commit {sha} and MkDocs {version} are available as expansions.

  • remote_branch (str | None, default: None ) –

    The remote branch to commit to for GitHub Pages. This overrides the value specified in config.

  • remote_name (str | None, default: None ) –

    The remote name to commit to for GitHub Pages. This overrides the value specified in config

  • force (bool | None, default: None ) –

    Force the push to the repository.

  • no_history (bool | None, default: None ) –

    Replace the whole Git history with one new commit.

  • ignore_version (bool | None, default: None ) –

    Ignore check that build is not being deployed with an older version of MkDocs.

  • shell (bool | None, default: None ) –

    Use the shell when invoking Git.

  • strict (bool | None, default: None ) –

    Enable strict mode. This will cause MkDocs to abort the build on any warnings.

  • theme (str | None, default: None ) –

    The theme to use when building your documentation.

  • directory_urls (bool | None, default: None ) –

    Use directory URLs when building pages (the default).

  • site_dir (str | None, default: None ) –

    The directory to output the result of the documentation build.

  • quiet (bool, default: False ) –

    Silence warnings.

  • verbose (bool, default: False ) –

    Enable verbose output.

Source code in src/duty/callables/mkdocs.py
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
@lazy(name="mkdocs.gh_deploy")
def gh_deploy(
    *,
    config_file: str | None = None,
    clean: bool | None = None,
    message: str | None = None,
    remote_branch: str | None = None,
    remote_name: str | None = None,
    force: bool | None = None,
    no_history: bool | None = None,
    ignore_version: bool | None = None,
    shell: bool | None = None,
    strict: bool | None = None,
    theme: str | None = None,
    directory_urls: bool | None = None,
    site_dir: str | None = None,
    quiet: bool = False,
    verbose: bool = False,
) -> None:
    """Deploy your documentation to GitHub Pages.

    Parameters:
        config_file: Provide a specific MkDocs config.
        clean: Remove old files from the site_dir before building (the default).
        message: A commit message to use when committing to the GitHub Pages remote branch.
            Commit {sha} and MkDocs {version} are available as expansions.
        remote_branch: The remote branch to commit to for GitHub Pages. This overrides the value specified in config.
        remote_name: The remote name to commit to for GitHub Pages. This overrides the value specified in config
        force: Force the push to the repository.
        no_history: Replace the whole Git history with one new commit.
        ignore_version: Ignore check that build is not being deployed with an older version of MkDocs.
        shell: Use the shell when invoking Git.
        strict: Enable strict mode. This will cause MkDocs to abort the build on any warnings.
        theme: The theme to use when building your documentation.
        directory_urls: Use directory URLs when building pages (the default).
        site_dir: The directory to output the result of the documentation build.
        quiet: Silence warnings.
        verbose: Enable verbose output.
    """
    cli_args = []

    if clean is True:
        cli_args.append("--clean")
    elif clean is False:
        cli_args.append("--dirty")

    if message:
        cli_args.append("--message")
        cli_args.append(message)

    if remote_branch:
        cli_args.append("--remote-branch")
        cli_args.append(remote_branch)

    if remote_name:
        cli_args.append("--remote-name")
        cli_args.append(remote_name)

    if force:
        cli_args.append("--force")

    if no_history:
        cli_args.append("--no-history")

    if ignore_version:
        cli_args.append("--ignore-version")

    if shell:
        cli_args.append("--shell")

    if config_file:
        cli_args.append("--config-file")
        cli_args.append(config_file)

    if strict is True:
        cli_args.append("--strict")

    if theme:
        cli_args.append("--theme")
        cli_args.append(theme)

    if directory_urls is True:
        cli_args.append("--use-directory-urls")
    elif directory_urls is False:
        cli_args.append("--no-directory-urls")

    if site_dir:
        cli_args.append("--site_dir")
        cli_args.append(site_dir)

    run("gh-deploy", *cli_args, quiet=quiet, verbose=verbose)

new ¤

new(
    project_directory: str,
    *,
    quiet: bool = False,
    verbose: bool = False
) -> None

Create a new MkDocs project.

Parameters:

  • project_directory (str) –

    Where to create the project.

  • quiet (bool, default: False ) –

    Silence warnings.

  • verbose (bool, default: False ) –

    Enable verbose output.

Source code in src/duty/callables/mkdocs.py
176
177
178
179
180
181
182
183
184
185
@lazy(name="mkdocs.new")
def new(project_directory: str, *, quiet: bool = False, verbose: bool = False) -> None:
    """Create a new MkDocs project.

    Parameters:
        project_directory: Where to create the project.
        quiet: Silence warnings.
        verbose: Enable verbose output.
    """
    run("new", project_directory, quiet=quiet, verbose=verbose)

run ¤

run(
    *args: str, quiet: bool = False, verbose: bool = False
) -> None

Run mkdocs.

Parameters:

  • *args (str, default: () ) –

    CLI arguments.

  • quiet (bool, default: False ) –

    Silence warnings.

  • verbose (bool, default: False ) –

    Enable verbose output.

Source code in src/duty/callables/mkdocs.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def run(*args: str, quiet: bool = False, verbose: bool = False) -> None:
    """Run `mkdocs`.

    Parameters:
        *args: CLI arguments.
        quiet: Silence warnings.
        verbose: Enable verbose output.
    """
    from mkdocs.__main__ import cli as mkdocs

    cli_args = list(args)

    if quiet and "-q" not in cli_args:
        cli_args.append("--quiet")

    if verbose and "-v" not in cli_args:
        cli_args.append("--verbose")

    mkdocs(cli_args)

serve ¤

serve(
    *,
    config_file: str | None = None,
    dev_addr: str | None = None,
    livereload: bool | None = None,
    dirtyreload: bool | None = None,
    watch_theme: bool | None = None,
    watch: list[str] | None = None,
    strict: bool | None = None,
    theme: str | None = None,
    directory_urls: bool | None = None,
    quiet: bool = False,
    verbose: bool = False
) -> None

Run the builtin development server.

Parameters:

  • config_file (str | None, default: None ) –

    Provide a specific MkDocs config.

  • dev_addr (str | None, default: None ) –

    IP address and port to serve documentation locally (default: localhost:8000).

  • livereload (bool | None, default: None ) –

    Enable/disable the live reloading in the development server.

  • dirtyreload (bool | None, default: None ) –

    nable the live reloading in the development server, but only re-build files that have changed.

  • watch_theme (bool | None, default: None ) –

    Include the theme in list of files to watch for live reloading. Ignored when live reload is not used.

  • watch (list[str] | None, default: None ) –

    Directories or files to watch for live reloading.

  • strict (bool | None, default: None ) –

    Enable strict mode. This will cause MkDocs to abort the build on any warnings.

  • theme (str | None, default: None ) –

    The theme to use when building your documentation.

  • directory_urls (bool | None, default: None ) –

    Use directory URLs when building pages (the default).

  • quiet (bool, default: False ) –

    Silence warnings.

  • verbose (bool, default: False ) –

    Enable verbose output.

Source code in src/duty/callables/mkdocs.py
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
@lazy(name="mkdocs.serve")
def serve(
    *,
    config_file: str | None = None,
    dev_addr: str | None = None,
    livereload: bool | None = None,
    dirtyreload: bool | None = None,
    watch_theme: bool | None = None,
    watch: list[str] | None = None,
    strict: bool | None = None,
    theme: str | None = None,
    directory_urls: bool | None = None,
    quiet: bool = False,
    verbose: bool = False,
) -> None:
    """Run the builtin development server.

    Parameters:
        config_file: Provide a specific MkDocs config.
        dev_addr: IP address and port to serve documentation locally (default: localhost:8000).
        livereload: Enable/disable the live reloading in the development server.
        dirtyreload: nable the live reloading in the development server, but only re-build files that have changed.
        watch_theme: Include the theme in list of files to watch for live reloading. Ignored when live reload is not used.
        watch: Directories or files to watch for live reloading.
        strict: Enable strict mode. This will cause MkDocs to abort the build on any warnings.
        theme: The theme to use when building your documentation.
        directory_urls: Use directory URLs when building pages (the default).
        quiet: Silence warnings.
        verbose: Enable verbose output.
    """
    cli_args = []

    if dev_addr:
        cli_args.append("--dev-addr")
        cli_args.append(dev_addr)

    if livereload is True:
        cli_args.append("--livereload")
    elif livereload is False:
        cli_args.append("--no-livereload")

    if dirtyreload:
        cli_args.append("--dirtyreload")

    if watch_theme:
        cli_args.append("--watch-theme")

    if watch:
        for path in watch:
            cli_args.append("--watch")
            cli_args.append(path)

    if config_file:
        cli_args.append("--config-file")
        cli_args.append(config_file)

    if strict is True:
        cli_args.append("--strict")

    if theme:
        cli_args.append("--theme")
        cli_args.append(theme)

    if directory_urls is True:
        cli_args.append("--use-directory-urls")
    elif directory_urls is False:
        cli_args.append("--no-directory-urls")

    run("serve", *cli_args, quiet=quiet, verbose=verbose)