def run(self):
        """Return rel path to a downloaded file as `include` node argument."""
        document = self.state.document
        env = document.settings.env
        buildpath = env.app.outdir
        link = self.arguments[0]

        try:
            r = requests.get(link)
            r.raise_for_status()
            downloadpath = os.path.join(buildpath, '_downloads')
            if not os.path.isdir(downloadpath):
                os.makedirs(downloadpath)
            rstfile = os.path.join(downloadpath, os.path.basename(link))
            with open(rstfile, 'w') as f:
                f.write(r.text)
            rstfile = os.path.relpath(rstfile, os.path.dirname(env.doc2path
                                                               (env.docname)))
            self.arguments = [rstfile]
            return super(RemoteInclude, self).run()
        except Exception:
            err = 'Unable to resolve ' + link
            return [document.reporter.warning(str(err), line=self.lineno)]
def run ( self ) : document = self . state . document env = document . settings . env buildpath = env . app . outdir link = self . arguments [ 0 ] try : r = requests . get ( link ) r . raise_for_status ( ) downloadpath = os . path . join ( buildpath , '_downloads' ) if not os . path . isdir ( downloadpath ) : os . makedirs ( downloadpath ) rstfile = os . path . join ( downloadpath , os . path . basename ( link ) ) with open ( rstfile , 'w' ) as f : f . write ( r . text ) rstfile = os . path . relpath ( rstfile , os . path . dirname ( env . doc2path ( env . docname ) ) ) self . arguments = [ rstfile ] return super ( RemoteInclude , self ) . run ( ) except Exception : err = 'Unable to resolve ' + link return [ document . reporter . warning ( str ( err ) , line = self . lineno ) ]
Return rel path to a downloaded file as `include` node argument.