* Validates that the correct version of `mkdocs` is installed
()
| 239 | * Validates that the correct version of `mkdocs` is installed |
| 240 | */ |
| 241 | protected async validateMkDocs() { |
| 242 | log.debug(`Validating MkDocs version`); |
| 243 | |
| 244 | const pythonPath = this.pythonPath ?? (await findPython()); |
| 245 | if (!pythonPath) { |
| 246 | return this.fail(MESSAGE_PYTHON_MISSING); |
| 247 | } |
| 248 | |
| 249 | const mkdocsInstalled = await isMkDocsInstalled(); |
| 250 | if (!mkdocsInstalled) { |
| 251 | return this.fail(`Could not find MkDocs executable; please run "${NAME_BIN} init"`); |
| 252 | } |
| 253 | |
| 254 | let rawMkDocsVersion: string | undefined; |
| 255 | try { |
| 256 | ({stdout: rawMkDocsVersion} = await exec(pythonPath, ['-m', NAME_MKDOCS, '--version'])); |
| 257 | } catch (err) { |
| 258 | return this.fail(`Failed to get MkDocs version: ${err instanceof Error ? err.message : String(err)}`); |
| 259 | } |
| 260 | const match = rawMkDocsVersion.match(MKDOCS_VERSION_REGEX); |
| 261 | if (!match) { |
| 262 | return this.fail(`Could not parse MkDocs version. Output was ${rawMkDocsVersion}`); |
| 263 | } |
| 264 | const version = match[1]; |
| 265 | const reqs = await this.parseRequirementsTxt(); |
| 266 | const mkDocsPipPkg = reqs.find((pkg) => pkg.name === NAME_MKDOCS); |
| 267 | if (!mkDocsPipPkg) { |
| 268 | throw new DocutilsError(`No ${NAME_MKDOCS} package in ${REQUIREMENTS_TXT_PATH}. This is a bug`); |
| 269 | } |
| 270 | const {version: mkDocsReqdVersion} = mkDocsPipPkg; |
| 271 | if (version !== mkDocsReqdVersion) { |
| 272 | return this.fail(`MkDocs v${version} is installed, but v${mkDocsReqdVersion} is required`); |
| 273 | } |
| 274 | |
| 275 | this.ok('MkDocs install OK'); |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * Validates (sort of) an `mkdocs.yml` config file. |