Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

docs: Sphinx: kerneldoc: only initialize kernel-doc classes once

Instead of re-creating the objects every time, initialize it
just once.

This allows caching previously parsed objects.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Message-ID: <b00788f26e161512858a6e01a673c34743c954df.1745564565.git.mchehab+huawei@kernel.org>

authored by

Mauro Carvalho Chehab and committed by
Jonathan Corbet
b437bf2d 292c39b4

+11 -12
+11 -12
Documentation/sphinx/kerneldoc.py
··· 48 48 from kdoc_output import RestFormat 49 49 50 50 __version__ = '1.0' 51 - use_kfiles = False 51 + kfiles = None 52 + logger = logging.getLogger('kerneldoc') 52 53 53 54 def cmd_str(cmd): 54 55 """ ··· 87 86 'functions': directives.unchanged, 88 87 } 89 88 has_content = False 90 - logger = logging.getLogger('kerneldoc') 91 89 verbose = 0 92 90 93 91 parse_args = {} ··· 204 204 node = nodes.section() 205 205 206 206 try: 207 - self.logger.verbose("calling kernel-doc '%s'" % (" ".join(cmd))) 207 + logger.verbose("calling kernel-doc '%s'" % (" ".join(cmd))) 208 208 209 209 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 210 210 out, err = p.communicate() ··· 214 214 if p.returncode != 0: 215 215 sys.stderr.write(err) 216 216 217 - self.logger.warning("kernel-doc '%s' failed with return code %d" 217 + logger.warning("kernel-doc '%s' failed with return code %d" 218 218 % (" ".join(cmd), p.returncode)) 219 219 return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))] 220 220 elif env.config.kerneldoc_verbosity > 0: 221 221 sys.stderr.write(err) 222 222 223 223 except Exception as e: # pylint: disable=W0703 224 - self.logger.warning("kernel-doc '%s' processing failed with: %s" % 224 + logger.warning("kernel-doc '%s' processing failed with: %s" % 225 225 (" ".join(cmd), str(e))) 226 226 return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))] 227 227 ··· 261 261 self.do_parse(result, node) 262 262 263 263 except Exception as e: # pylint: disable=W0703 264 - self.logger.warning("kernel-doc '%s' processing failed with: %s" % 264 + logger.warning("kernel-doc '%s' processing failed with: %s" % 265 265 (cmd_str(cmd), str(e))) 266 266 return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))] 267 267 ··· 292 292 return node.children 293 293 294 294 def run(self): 295 - global use_kfiles 295 + global kfiles 296 296 297 - if use_kfiles: 298 - out_style = RestFormat() 299 - kfiles = KernelFiles(out_style=out_style, logger=self.logger) 297 + if kfiles: 300 298 return self.run_kdoc(kfiles) 301 299 else: 302 300 return self.run_cmd() ··· 304 306 self.state.nested_parse(result, 0, node, match_titles=1) 305 307 306 308 def setup_kfiles(app): 307 - global use_kfiles 309 + global kfiles 308 310 309 311 kerneldoc_bin = app.env.config.kerneldoc_bin 310 312 311 313 if kerneldoc_bin and kerneldoc_bin.endswith("kernel-doc.py"): 312 314 print("Using Python kernel-doc") 313 - use_kfiles = True 315 + out_style = RestFormat() 316 + kfiles = KernelFiles(out_style=out_style, logger=logger) 314 317 else: 315 318 print(f"Using {kerneldoc_bin}") 316 319