1import os.path 2 3from docutils.parsers.rst import directives 4from docutils.parsers.rst.directives.misc import Include as BaseInclude 5from sphinx.util.docutils import SphinxDirective 6 7 8class IncludeBuildFile(BaseInclude, SphinxDirective): 9 """ 10 Like the standard "Include" directive, but relative to the app 11 build directory 12 """ 13 def run(self): 14 abspath = os.path.join(self.env.config.build_dir, self.arguments[0]) 15 self.arguments[0] = abspath 16 self.env.note_included(abspath) 17 return super(IncludeBuildFile, self).run() 18 19 20def setup(app): 21 directives.register_directive('include-build-file', IncludeBuildFile) 22 23 return {'parallel_read_safe': True, 'parallel_write_safe': True, 'version': '0.1'} 24