hotdoc module: avoid monkeypatch crime by properly subclassing ExternalProgram

pull/12106/head
Eli Schwartz 1 year ago
parent 169cd7e619
commit bf0494fcc0
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 15
      mesonbuild/modules/hotdoc.py

@ -15,8 +15,8 @@ from __future__ import annotations
'''This module provides helper functions for generating documentation using hotdoc'''
import os
import subprocess
import os, subprocess
import typing as T
from mesonbuild import mesonlib
from mesonbuild import mlog, build
@ -44,6 +44,11 @@ MIN_HOTDOC_VERSION = '0.8.100'
file_types = (str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex)
class HotdocExternalProgram(ExternalProgram):
def run_hotdoc(self, cmd: T.List[str]) -> int:
return subprocess.run(self.get_command() + cmd, stdout=subprocess.DEVNULL).returncode
class HotdocTargetBuilder:
def __init__(self, name, state, hotdoc, interpreter, kwargs):
@ -400,17 +405,13 @@ class HotDocModule(ExtensionModule):
def __init__(self, interpreter):
super().__init__(interpreter)
self.hotdoc = ExternalProgram('hotdoc')
self.hotdoc = HotdocExternalProgram('hotdoc')
if not self.hotdoc.found():
raise MesonException('hotdoc executable not found')
version = self.hotdoc.get_version(interpreter)
if not mesonlib.version_compare(version, f'>={MIN_HOTDOC_VERSION}'):
raise MesonException(f'hotdoc {MIN_HOTDOC_VERSION} required but not found.)')
def run_hotdoc(cmd):
return subprocess.run(self.hotdoc.get_command() + cmd, stdout=subprocess.DEVNULL).returncode
self.hotdoc.run_hotdoc = run_hotdoc
self.methods.update({
'has_extensions': self.has_extensions,
'generate_doc': self.generate_doc,

Loading…
Cancel
Save