def _runHtmlBuilder(self): # Build the commond line for Sphinx. if core.config()['Sphinx']['AdvancedMode']: htmlBuilderCommandLine = core.config()['Sphinx']['Cmdline'] if sys.platform.startswith('linux'): # If Linux is used, then subprocess cannot take the whole # commandline as the name of an executable file. Module shlex # has to be used to parse commandline. htmlBuilderCommandLine = shlex.split(htmlBuilderCommandLine) else: # For available builder options, refer to: http://sphinx-doc.org/builders.html htmlBuilderCommandLine = [ core.config()['Sphinx']['Executable'], # Place doctrees in the ``_build`` directory; by default, Sphinx # places this in _build/html/.doctrees. '-d', os.path.join('_build', 'doctrees'), # Source directory -- the current directory, since we'll chdir to # the project directory before executing this. '.', # Build directory core.config()['Sphinx']['OutputPath'] ] # Invoke it. try: # Clear the log at the beginning of a Sphinx build. self.logWindowClear.emit() cwd = core.config()['Sphinx']['ProjectPath'] # If the command line is already a string (advanced mode), just print it. # Otherwise, it's a list that should be transformed to a string. if isinstance(htmlBuilderCommandLine, str): htmlBuilderCommandLineStr = htmlBuilderCommandLine else: htmlBuilderCommandLineStr = ' '.join(htmlBuilderCommandLine) self.logWindowText.emit('{} : {}\n\n'.format( cwd, htmlBuilderCommandLineStr)) # Run Sphinx, reading stdout in a separate thread. self._qe = QEventLoop() # Sphinx will output just a carriage return (0x0D) to simulate a # single line being updated by build status and the build # progresses. Without universal newline support here, we'll wait # until the build is complete (with a \n\r) to report any build # progress! So, enable universal newlines, so that each \r will be # treated as a separate line, providing immediate feedback on build # progress. popen = open_console_output(htmlBuilderCommandLine, cwd=cwd, universal_newlines=True) # Perform reads in an event loop. The loop is exit when all reads # have completed. We can't simply start the _stderr_read thread # here, because calls to self._qe_exit() will be ignored until # we're inside the event loop. QTimer.singleShot(0, lambda: self._popen_read(popen)) self._qe.exec_() except OSError as ex: return ('Failed to execute HTML builder:\n' '{}\n'.format(str(ex)) + 'Go to Settings -> Settings -> CodeChat to set HTML' ' builder configurations.') return self._stderr
def _runHtmlBuilder(self): # Build the commond line for Sphinx. if core.config()['Sphinx']['AdvancedMode']: htmlBuilderCommandLine = core.config()['Sphinx']['Cmdline'] if sys.platform.startswith('linux'): # If Linux is used, then subprocess cannot take the whole # commandline as the name of an executable file. Module shlex # has to be used to parse commandline. htmlBuilderCommandLine = shlex.split(htmlBuilderCommandLine) else: # For available builder options, refer to: http://sphinx-doc.org/builders.html htmlBuilderCommandLine = [core.config()['Sphinx']['Executable'], # Place doctrees in the ``_build`` directory; by default, Sphinx # places this in _build/html/.doctrees. '-d', os.path.join('_build', 'doctrees'), # Source directory -- the current directory, since we'll chdir to # the project directory before executing this. '.', # Build directory core.config()['Sphinx']['OutputPath']] # Invoke it. try: # Clear the log at the beginning of a Sphinx build. self.logWindowClear.emit() cwd = core.config()['Sphinx']['ProjectPath'] # If the command line is already a string (advanced mode), just print it. # Otherwise, it's a list that should be transformed to a string. if isinstance(htmlBuilderCommandLine, str): htmlBuilderCommandLineStr = htmlBuilderCommandLine else: htmlBuilderCommandLineStr = ' '.join(htmlBuilderCommandLine) self.logWindowText.emit('{} : {}\n\n'.format(cwd, htmlBuilderCommandLineStr)) # Run Sphinx, reading stdout in a separate thread. self._qe = QEventLoop() # Sphinx will output just a carriage return (0x0D) to simulate a # single line being updated by build status and the build # progresses. Without universal newline support here, we'll wait # until the build is complete (with a \n\r) to report any build # progress! So, enable universal newlines, so that each \r will be # treated as a separate line, providing immediate feedback on build # progress. popen = open_console_output(htmlBuilderCommandLine, cwd=cwd, universal_newlines=True) # Perform reads in an event loop. The loop is exit when all reads # have completed. We can't simply start the _stderr_read thread # here, because calls to self._qe_exit() will be ignored until # we're inside the event loop. QTimer.singleShot(0, lambda: self._popen_read(popen)) self._qe.exec_() except OSError as ex: return ( 'Failed to execute HTML builder:\n' '{}\n'.format(str(ex)) + 'Go to Settings -> Settings -> CodeChat to set HTML' ' builder configurations.') return self._stderr