duty 1.2.0__py3-none-any.whl → 1.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
duty/tools/_mkdocs.py ADDED
@@ -0,0 +1,271 @@
1
+ """Callable for [MkDocs](https://github.com/mkdocs/mkdocs)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from duty.tools._base import Tool
6
+
7
+
8
+ class mkdocs(Tool): # noqa: N801
9
+ """Call [MkDocs](https://github.com/mkdocs/mkdocs)."""
10
+
11
+ cli_name = "mkdocs"
12
+
13
+ @classmethod
14
+ def build(
15
+ cls,
16
+ *,
17
+ config_file: str | None = None,
18
+ clean: bool | None = None,
19
+ strict: bool | None = None,
20
+ theme: str | None = None,
21
+ directory_urls: bool | None = None,
22
+ site_dir: str | None = None,
23
+ quiet: bool = False,
24
+ verbose: bool = False,
25
+ ) -> mkdocs:
26
+ """Build the MkDocs documentation.
27
+
28
+ Parameters:
29
+ config_file: Provide a specific MkDocs config.
30
+ clean: Remove old files from the site_dir before building (the default).
31
+ strict: Enable strict mode. This will cause MkDocs to abort the build on any warnings.
32
+ theme: The theme to use when building your documentation.
33
+ directory_urls: Use directory URLs when building pages (the default).
34
+ site_dir: The directory to output the result of the documentation build.
35
+ quiet: Silence warnings.
36
+ verbose: Enable verbose output.
37
+ """
38
+ cli_args = ["build"]
39
+
40
+ if clean is True:
41
+ cli_args.append("--clean")
42
+ elif clean is False:
43
+ cli_args.append("--dirty")
44
+
45
+ if config_file:
46
+ cli_args.append("--config-file")
47
+ cli_args.append(config_file)
48
+
49
+ if strict is True:
50
+ cli_args.append("--strict")
51
+
52
+ if theme:
53
+ cli_args.append("--theme")
54
+ cli_args.append(theme)
55
+
56
+ if directory_urls is True:
57
+ cli_args.append("--use-directory-urls")
58
+ elif directory_urls is False:
59
+ cli_args.append("--no-directory-urls")
60
+
61
+ if site_dir:
62
+ cli_args.append("--site_dir")
63
+ cli_args.append(site_dir)
64
+
65
+ if quiet and "-q" not in cli_args:
66
+ cli_args.append("--quiet")
67
+
68
+ if verbose and "-v" not in cli_args:
69
+ cli_args.append("--verbose")
70
+
71
+ return cls(cli_args)
72
+
73
+ @classmethod
74
+ def gh_deploy(
75
+ cls,
76
+ *,
77
+ config_file: str | None = None,
78
+ clean: bool | None = None,
79
+ message: str | None = None,
80
+ remote_branch: str | None = None,
81
+ remote_name: str | None = None,
82
+ force: bool | None = None,
83
+ no_history: bool | None = None,
84
+ ignore_version: bool | None = None,
85
+ shell: bool | None = None,
86
+ strict: bool | None = None,
87
+ theme: str | None = None,
88
+ directory_urls: bool | None = None,
89
+ site_dir: str | None = None,
90
+ quiet: bool = False,
91
+ verbose: bool = False,
92
+ ) -> mkdocs:
93
+ """Deploy your documentation to GitHub Pages.
94
+
95
+ Parameters:
96
+ config_file: Provide a specific MkDocs config.
97
+ clean: Remove old files from the site_dir before building (the default).
98
+ message: A commit message to use when committing to the GitHub Pages remote branch.
99
+ Commit {sha} and MkDocs {version} are available as expansions.
100
+ remote_branch: The remote branch to commit to for GitHub Pages. This overrides the value specified in config.
101
+ remote_name: The remote name to commit to for GitHub Pages. This overrides the value specified in config
102
+ force: Force the push to the repository.
103
+ no_history: Replace the whole Git history with one new commit.
104
+ ignore_version: Ignore check that build is not being deployed with an older version of MkDocs.
105
+ shell: Use the shell when invoking Git.
106
+ strict: Enable strict mode. This will cause MkDocs to abort the build on any warnings.
107
+ theme: The theme to use when building your documentation.
108
+ directory_urls: Use directory URLs when building pages (the default).
109
+ site_dir: The directory to output the result of the documentation build.
110
+ quiet: Silence warnings.
111
+ verbose: Enable verbose output.
112
+ """
113
+ cli_args = ["gh-deploy"]
114
+
115
+ if clean is True:
116
+ cli_args.append("--clean")
117
+ elif clean is False:
118
+ cli_args.append("--dirty")
119
+
120
+ if message:
121
+ cli_args.append("--message")
122
+ cli_args.append(message)
123
+
124
+ if remote_branch:
125
+ cli_args.append("--remote-branch")
126
+ cli_args.append(remote_branch)
127
+
128
+ if remote_name:
129
+ cli_args.append("--remote-name")
130
+ cli_args.append(remote_name)
131
+
132
+ if force:
133
+ cli_args.append("--force")
134
+
135
+ if no_history:
136
+ cli_args.append("--no-history")
137
+
138
+ if ignore_version:
139
+ cli_args.append("--ignore-version")
140
+
141
+ if shell:
142
+ cli_args.append("--shell")
143
+
144
+ if config_file:
145
+ cli_args.append("--config-file")
146
+ cli_args.append(config_file)
147
+
148
+ if strict is True:
149
+ cli_args.append("--strict")
150
+
151
+ if theme:
152
+ cli_args.append("--theme")
153
+ cli_args.append(theme)
154
+
155
+ if directory_urls is True:
156
+ cli_args.append("--use-directory-urls")
157
+ elif directory_urls is False:
158
+ cli_args.append("--no-directory-urls")
159
+
160
+ if site_dir:
161
+ cli_args.append("--site_dir")
162
+ cli_args.append(site_dir)
163
+
164
+ if quiet and "-q" not in cli_args:
165
+ cli_args.append("--quiet")
166
+
167
+ if verbose and "-v" not in cli_args:
168
+ cli_args.append("--verbose")
169
+
170
+ return cls(cli_args)
171
+
172
+ @classmethod
173
+ def new(cls, project_directory: str, *, quiet: bool = False, verbose: bool = False) -> mkdocs:
174
+ """Create a new MkDocs project.
175
+
176
+ Parameters:
177
+ project_directory: Where to create the project.
178
+ quiet: Silence warnings.
179
+ verbose: Enable verbose output.
180
+ """
181
+ cli_args = ["new", project_directory]
182
+
183
+ if quiet and "-q" not in cli_args:
184
+ cli_args.append("--quiet")
185
+
186
+ if verbose and "-v" not in cli_args:
187
+ cli_args.append("--verbose")
188
+
189
+ return cls(cli_args)
190
+
191
+ @classmethod
192
+ def serve(
193
+ cls,
194
+ *,
195
+ config_file: str | None = None,
196
+ dev_addr: str | None = None,
197
+ livereload: bool | None = None,
198
+ dirtyreload: bool | None = None,
199
+ watch_theme: bool | None = None,
200
+ watch: list[str] | None = None,
201
+ strict: bool | None = None,
202
+ theme: str | None = None,
203
+ directory_urls: bool | None = None,
204
+ quiet: bool = False,
205
+ verbose: bool = False,
206
+ ) -> mkdocs:
207
+ """Run the builtin development server.
208
+
209
+ Parameters:
210
+ config_file: Provide a specific MkDocs config.
211
+ dev_addr: IP address and port to serve documentation locally (default: localhost:8000).
212
+ livereload: Enable/disable the live reloading in the development server.
213
+ dirtyreload: nable the live reloading in the development server, but only re-build files that have changed.
214
+ watch_theme: Include the theme in list of files to watch for live reloading. Ignored when live reload is not used.
215
+ watch: Directories or files to watch for live reloading.
216
+ strict: Enable strict mode. This will cause MkDocs to abort the build on any warnings.
217
+ theme: The theme to use when building your documentation.
218
+ directory_urls: Use directory URLs when building pages (the default).
219
+ quiet: Silence warnings.
220
+ verbose: Enable verbose output.
221
+ """
222
+ cli_args = ["serve"]
223
+
224
+ if dev_addr:
225
+ cli_args.append("--dev-addr")
226
+ cli_args.append(dev_addr)
227
+
228
+ if livereload is True:
229
+ cli_args.append("--livereload")
230
+ elif livereload is False:
231
+ cli_args.append("--no-livereload")
232
+
233
+ if dirtyreload:
234
+ cli_args.append("--dirtyreload")
235
+
236
+ if watch_theme:
237
+ cli_args.append("--watch-theme")
238
+
239
+ if watch:
240
+ for path in watch:
241
+ cli_args.append("--watch")
242
+ cli_args.append(path)
243
+
244
+ if config_file:
245
+ cli_args.append("--config-file")
246
+ cli_args.append(config_file)
247
+
248
+ if strict is True:
249
+ cli_args.append("--strict")
250
+
251
+ if theme:
252
+ cli_args.append("--theme")
253
+ cli_args.append(theme)
254
+
255
+ if directory_urls is True:
256
+ cli_args.append("--use-directory-urls")
257
+ elif directory_urls is False:
258
+ cli_args.append("--no-directory-urls")
259
+
260
+ if quiet and "-q" not in cli_args:
261
+ cli_args.append("--quiet")
262
+
263
+ if verbose and "-v" not in cli_args:
264
+ cli_args.append("--verbose")
265
+
266
+ return cls(cli_args)
267
+
268
+ def __call__(self) -> int:
269
+ from mkdocs.__main__ import cli as run_mkdocs
270
+
271
+ return run_mkdocs(self.cli_args)