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: kernel_include.py: move range logic to a separate function

Cleanup run() function by moving the range logic to a separate
function.

Here, I ended checking the current Sphinx implementation, as it
has some extra logic for the range check.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/12fa2204a9e7e309ae4b8694a37ebad9327ca634.1755872208.git.mchehab+huawei@kernel.org

authored by

Mauro Carvalho Chehab and committed by
Jonathan Corbet
3f7f3d49 012e00dd

+33 -18
+33 -18
Documentation/sphinx/kernel_include.py
··· 131 131 132 132 return parser.gen_output() 133 133 134 + def apply_range(self, rawtext): 135 + # Get to-be-included content 136 + startline = self.options.get('start-line', None) 137 + endline = self.options.get('end-line', None) 138 + try: 139 + if startline or (endline is not None): 140 + lines = rawtext.splitlines() 141 + rawtext = '\n'.join(lines[startline:endline]) 142 + except UnicodeError as error: 143 + raise self.severe(f'Problem with "{self.name}" directive:\n' 144 + + io.error_string(error)) 145 + # start-after/end-before: no restrictions on newlines in match-text, 146 + # and no restrictions on matching inside lines vs. line boundaries 147 + after_text = self.options.get("start-after", None) 148 + if after_text: 149 + # skip content in rawtext before *and incl.* a matching text 150 + after_index = rawtext.find(after_text) 151 + if after_index < 0: 152 + raise self.severe('Problem with "start-after" option of "%s" ' 153 + "directive:\nText not found." % self.name) 154 + rawtext = rawtext[after_index + len(after_text) :] 155 + before_text = self.options.get("end-before", None) 156 + if before_text: 157 + # skip content in rawtext after *and incl.* a matching text 158 + before_index = rawtext.find(before_text) 159 + if before_index < 0: 160 + raise self.severe('Problem with "end-before" option of "%s" ' 161 + "directive:\nText not found." % self.name) 162 + rawtext = rawtext[:before_index] 163 + 164 + return rawtext 165 + 134 166 def run(self): 135 167 """Include a file as part of the content of this reST file.""" 136 168 env = self.state.document.settings.env ··· 217 185 else: 218 186 rawtext = self.read_rawtext(path, encoding) 219 187 220 - # start-after/end-before: no restrictions on newlines in match-text, 221 - # and no restrictions on matching inside lines vs. line boundaries 222 - after_text = self.options.get("start-after", None) 223 - if after_text: 224 - # skip content in rawtext before *and incl.* a matching text 225 - after_index = rawtext.find(after_text) 226 - if after_index < 0: 227 - raise self.severe('Problem with "start-after" option of "%s" ' 228 - "directive:\nText not found." % self.name) 229 - rawtext = rawtext[after_index + len(after_text) :] 230 - before_text = self.options.get("end-before", None) 231 - if before_text: 232 - # skip content in rawtext after *and incl.* a matching text 233 - before_index = rawtext.find(before_text) 234 - if before_index < 0: 235 - raise self.severe('Problem with "end-before" option of "%s" ' 236 - "directive:\nText not found." % self.name) 237 - rawtext = rawtext[:before_index] 188 + rawtext = self.apply_range(rawtext) 238 189 239 190 include_lines = statemachine.string2lines(rawtext, tab_width, 240 191 convert_whitespace=True)