0xtao

Finished
376376 rel_filename, filename = self.env.relfn2path(self.arguments[0])
377377 self.arguments[0] = filename
378378 self.env.note_included(filename)
379 return super().run()
379
380 # Read the file content and apply source-read event processing
381 try:
382 with open(filename, 'r', encoding=self.env.config.source_encoding) as f:
383 content = f.read()
384 except (OSError, UnicodeError) as err:
385 raise self.severe(f'Problems with "{self.arguments[0]}" path:\n{err}') from err
386
387 # Apply source-read event to the included file content
388 # Use the relative filename as the docname for the event
389 included_docname = self.env.path2doc(rel_filename)
390 arg = [content]
391 self.env.events.emit('source-read', included_docname, arg)
392 processed_content = arg[0]
393
394 # Create a temporary file with the processed content
395 # and update the arguments to use this temporary file
396 import tempfile
397 import os
398
399 # Create a temporary file with the processed content
400 with tempfile.NamedTemporaryFile(mode='w', encoding=self.env.config.source_encoding,
401 delete=False, suffix='.rst') as temp_file:
402 temp_file.write(processed_content)
403 temp_filename = temp_file.name
404
405 try:
406 # Store the original filename and temporarily use the processed one
407 original_filename = self.arguments[0]
408 self.arguments[0] = temp_filename
409
410 # Call the parent implementation with the processed content
411 result = super().run()
412
413 # Restore the original filename
414 self.arguments[0] = original_filename
415
416 return result
417 finally:
418 # Clean up the temporary file
419 try:
420 os.unlink(temp_filename)
421 except OSError:
422 pass
380423
381424
382425def setup(app: Sphinx) -> dict[str, Any]:
Test NameStatus
tests/test_directive_other.py::test_include_source_read_event
Fail
tests/test_directive_other.py::test_include_source_read_event_nested_includes
Fail
tests/test_directive_other.py::test_toctree
Pass
tests/test_directive_other.py::test_relative_toctree
Pass
tests/test_directive_other.py::test_toctree_urls_and_titles
Pass
tests/test_directive_other.py::test_toctree_glob
Pass
tests/test_directive_other.py::test_toctree_glob_and_url
Pass
tests/test_directive_other.py::test_reversed_toctree
Pass
tests/test_directive_other.py::test_toctree_twice
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.