12
12
13
13
from readthedocs .builds import utils as version_utils
14
14
from readthedocs .doc_builder .base import BaseBuilder , restoring_chdir
15
- from readthedocs .projects .utils import run , safe_write
15
+ from readthedocs .projects .utils import safe_write
16
16
from readthedocs .projects .exceptions import ProjectImportError
17
17
from readthedocs .restapi .client import api
18
18
@@ -123,18 +123,20 @@ def append_conf(self, **kwargs):
123
123
def build (self , ** kwargs ):
124
124
self .clean ()
125
125
project = self .version .project
126
- os .chdir (project .conf_dir (self .version .slug ))
127
- force_str = " -E " if self ._force else ""
128
- build_command = "%s -T %s -b %s -d _build/doctrees -D language=%s . %s " % (
129
- project .venv_bin (version = self .version .slug ,
130
- bin = 'sphinx-build' ),
131
- force_str ,
132
- self .sphinx_builder ,
133
- project .language ,
134
- self .sphinx_build_dir ,
135
- )
136
- results = run (build_command , shell = True )
137
- return results
126
+ build_command = [
127
+ project .venv_bin (version = self .version .slug , bin = 'sphinx-build' ),
128
+ '-T'
129
+ ]
130
+ if self ._force :
131
+ build_command .append ('-E' )
132
+ build_command .extend ([
133
+ '-b' , self .sphinx_builder ,
134
+ '-d' , '_build/doctrees' ,
135
+ '-D' , 'language={lang}' .format (lang = project .language ),
136
+ '.' ,
137
+ self .sphinx_build_dir
138
+ ])
139
+ self .run (* build_command , cwd = project .conf_dir (self .version .slug ))
138
140
139
141
140
142
class HtmlBuilder (BaseSphinx ):
@@ -212,7 +214,7 @@ def move(self, **kwargs):
212
214
if from_globs :
213
215
from_file = from_globs [0 ]
214
216
to_file = os .path .join (self .target , "%s.epub" % self .version .project .slug )
215
- run ('mv -f %s %s' % ( from_file , to_file ) )
217
+ self . run ('mv' , '-f' , from_file , to_file )
216
218
217
219
218
220
class PdfBuilder (BaseSphinx ):
@@ -223,42 +225,49 @@ class PdfBuilder(BaseSphinx):
223
225
@restoring_chdir
224
226
def build (self , ** kwargs ):
225
227
self .clean ()
226
- project = self .version .project
227
- os .chdir (project .conf_dir (self .version .slug ))
228
+ cwd = self .project .conf_dir (self .version .slug )
228
229
# Default to this so we can return it always.
229
- results = {}
230
- latex_results = run ('%s -b latex -D language=%s -d _build/doctrees . _build/latex'
231
- % (project .venv_bin (version = self .version .slug ,
232
- bin = 'sphinx-build' ), project .language ))
233
-
234
- if latex_results [0 ] == 0 :
235
- os .chdir ('_build/latex' )
236
- tex_files = glob ('*.tex' )
237
-
238
- if tex_files :
239
- # Run LaTeX -> PDF conversions
240
- pdflatex_cmds = [('pdflatex -interaction=nonstopmode %s'
241
- % tex_file ) for tex_file in tex_files ]
242
- makeindex_cmds = [('makeindex -s python.ist %s.idx'
243
- % os .path .splitext (tex_file )[0 ]) for tex_file in tex_files ]
244
- pdf_results = run (* pdflatex_cmds )
245
- ind_results = run (* makeindex_cmds )
246
- pdf_results = run (* pdflatex_cmds )
247
- else :
248
- pdf_results = (0 , "No tex files found" , "No tex files found" )
249
- ind_results = (0 , "No tex files found" , "No tex files found" )
250
-
251
- results = [
252
- latex_results [0 ] + ind_results [0 ] + pdf_results [0 ],
253
- latex_results [1 ] + ind_results [1 ] + pdf_results [1 ],
254
- latex_results [2 ] + ind_results [2 ] + pdf_results [2 ],
255
- ]
256
- pdf_match = PDF_RE .search (results [1 ])
257
- if pdf_match :
258
- self .pdf_file_name = pdf_match .group (1 ).strip ()
259
- else :
260
- results = latex_results
261
- return results
230
+ self .run (
231
+ self .project .venv_bin (version = self .version .slug , bin = 'sphinx-build' ),
232
+ '-b' , 'latex' ,
233
+ '-D' , 'language={lang}' .format (lang = self .project .language ),
234
+ '-d' ,'_build/doctrees' ,
235
+ '.' ,
236
+ '_build/latex' ,
237
+ cwd = cwd
238
+ )
239
+ latex_cwd = os .path .join (cwd , '_build' , 'latex' )
240
+ tex_files = glob (os .path .join (latex_cwd , '*.tex' ))
241
+
242
+ if not tex_files :
243
+ # TODO status code here
244
+ raise BuildEnvironmentError ('No TeX files were found' )
245
+
246
+ # Run LaTeX -> PDF conversions
247
+ pdflatex_cmds = [
248
+ ['pdflatex' ,
249
+ '-interaction=nonstopmode' ,
250
+ tex_file ]
251
+ for tex_file in tex_files ]
252
+ makeindex_cmds = [
253
+ ['makeindex' ,
254
+ '-s' ,
255
+ 'python.ist' ,
256
+ '{0}.idx' .format (os .path .splitext (tex_file )[0 ])]
257
+ for tex_file in tex_files ]
258
+ for cmd in pdflatex_cmds :
259
+ self .run (* cmd , cwd = latex_cwd )
260
+ for cmd in makeindex_cmds :
261
+ self .run (* cmd , cwd = latex_cwd )
262
+ for cmd in pdflatex_cmds :
263
+ self .run (* cmd , cwd = latex_cwd )
264
+
265
+ # TODO this ain't going to work without having access to the command
266
+ # returned here. We should probably return the command from run
267
+ # TODO pdf_match = PDF_RE.search(results[1])
268
+ pdf_match = PDF_RE .search ('' )
269
+ if pdf_match :
270
+ self .pdf_file_name = pdf_match .group (1 ).strip ()
262
271
263
272
def move (self , ** kwargs ):
264
273
if not os .path .exists (self .target ):
@@ -283,4 +292,4 @@ def move(self, **kwargs):
283
292
from_file = None
284
293
if from_file :
285
294
to_file = os .path .join (self .target , "%s.pdf" % self .version .project .slug )
286
- run ('mv -f %s %s' % ( from_file , to_file ) )
295
+ self . run ('mv' , '-f' , from_file , to_file )
0 commit comments