|
1 | 1 | import asyncio |
2 | 2 | import sys |
3 | 3 | from pathlib import Path |
| 4 | +from shutil import which |
4 | 5 | from typing import Any |
5 | 6 |
|
6 | 7 | from invoke import Context, task |
|
11 | 12 | MAIN_DIRECTORY_PATH = Path(__file__).parent |
12 | 13 |
|
13 | 14 |
|
| 15 | +def is_tool_installed(name: str) -> bool: |
| 16 | + """Check whether `name` is on PATH and marked as executable.""" |
| 17 | + return which(name) is not None |
| 18 | + |
| 19 | + |
14 | 20 | def _generate(context: Context) -> None: |
15 | 21 | """Generate documentation output from code.""" |
16 | 22 | _generate_infrahubctl_documentation(context=context) |
@@ -165,12 +171,46 @@ def lint_ruff(context: Context) -> None: |
165 | 171 | context.run(exec_cmd) |
166 | 172 |
|
167 | 173 |
|
| 174 | +@task |
| 175 | +def lint_markdownlint(context: Context) -> None: |
| 176 | + """Run markdownlint to check all markdown files.""" |
| 177 | + if not is_tool_installed("markdownlint-cli2"): |
| 178 | + print(" - markdownlint-cli2 is not installed, skipping documentation linting") |
| 179 | + return |
| 180 | + |
| 181 | + print(" - Check documentation with markdownlint-cli2") |
| 182 | + exec_cmd = "markdownlint-cli2 **/*.{md,mdx} --config .markdownlint.yaml" |
| 183 | + with context.cd(MAIN_DIRECTORY_PATH): |
| 184 | + context.run(exec_cmd) |
| 185 | + |
| 186 | + |
| 187 | +@task |
| 188 | +def lint_vale(context: Context) -> None: |
| 189 | + """Run vale to check all documentation files.""" |
| 190 | + if not is_tool_installed("vale"): |
| 191 | + print(" - vale is not installed, skipping documentation style linting") |
| 192 | + return |
| 193 | + |
| 194 | + print(" - Check documentation style with vale") |
| 195 | + exec_cmd = r'vale $(find ./docs -type f \( -name "*.mdx" -o -name "*.md" \))' |
| 196 | + with context.cd(MAIN_DIRECTORY_PATH): |
| 197 | + context.run(exec_cmd) |
| 198 | + |
| 199 | + |
| 200 | +@task |
| 201 | +def lint_docs(context: Context) -> None: |
| 202 | + """Run all documentation linters.""" |
| 203 | + lint_markdownlint(context) |
| 204 | + lint_vale(context) |
| 205 | + |
| 206 | + |
168 | 207 | @task(name="lint") |
169 | 208 | def lint_all(context: Context) -> None: |
170 | 209 | """Run all linters.""" |
171 | 210 | lint_yaml(context) |
172 | 211 | lint_ruff(context) |
173 | 212 | lint_mypy(context) |
| 213 | + lint_docs(context) |
174 | 214 |
|
175 | 215 |
|
176 | 216 | @task(name="docs-validate") |
|
0 commit comments