22import os
33from pathlib import Path
44import sys
5- from typing import Optional
5+ from typing import Dict , Optional
66
77from . import utils , core , codechat
88
@@ -14,11 +14,11 @@ def html(
1414 ptxfile : Path ,
1515 pub_file : Path ,
1616 output : Path ,
17- stringparams ,
17+ stringparams : Dict [ str , str ] ,
1818 custom_xsl : Optional [Path ],
19- xmlid_root ,
20- zipped = False ,
21- ):
19+ xmlid_root : Optional [ str ] ,
20+ zipped : bool = False ,
21+ ) -> None :
2222 os .makedirs (output , exist_ok = True )
2323 log .info (f"\n Now building HTML into { output } \n " )
2424 if xmlid_root is not None :
@@ -40,9 +40,9 @@ def html(
4040 None ,
4141 output .as_posix (),
4242 )
43- codechat . map_path_to_xml_id (
44- ptxfile , utils . project_path ( ptxfile ), output . as_posix ()
45- )
43+ pp = utils . project_path ( ptxfile )
44+ assert pp is not None , f"Invalid project path to { ptxfile } ."
45+ codechat . map_path_to_xml_id ( ptxfile , pp , output . as_posix () )
4646 except Exception as e :
4747 log .critical (e )
4848 log .debug ("Exception info:\n ##################\n " , exc_info = True )
@@ -54,9 +54,9 @@ def latex(
5454 ptxfile : Path ,
5555 pub_file : Path ,
5656 output : Path ,
57- stringparams ,
57+ stringparams : Dict [ str , str ] ,
5858 custom_xsl : Optional [Path ],
59- ):
59+ ) -> None :
6060 os .makedirs (output , exist_ok = True )
6161 log .info (f"\n Now building LaTeX into { output } \n " )
6262 # ensure working directory is preserved
@@ -81,10 +81,10 @@ def pdf(
8181 ptxfile : Path ,
8282 pub_file : Path ,
8383 output : Path ,
84- stringparams ,
84+ stringparams : Dict [ str , str ] ,
8585 custom_xsl : Optional [Path ],
8686 pdf_method : str ,
87- ):
87+ ) -> None :
8888 os .makedirs (output , exist_ok = True )
8989 log .info (f"\n Now building LaTeX into { output } \n " )
9090 # ensure working directory is preserved
@@ -110,10 +110,10 @@ def custom(
110110 ptxfile : Path ,
111111 pub_file : Path ,
112112 output : Path ,
113- stringparams ,
113+ stringparams : Dict [ str , str ] ,
114114 custom_xsl : Path ,
115115 output_filename : Optional [str ] = None ,
116- ):
116+ ) -> None :
117117 os .makedirs (output , exist_ok = True )
118118 if output_filename is not None :
119119 output_filepath = output / output_filename
@@ -141,7 +141,9 @@ def custom(
141141
142142
143143# build (non Kindle) ePub:
144- def epub (ptxfile , pub_file : Path , output : Path , stringparams ):
144+ def epub (
145+ ptxfile : Path , pub_file : Path , output : Path , stringparams : Dict [str , str ]
146+ ) -> None :
145147 os .makedirs (output , exist_ok = True )
146148 try :
147149 utils .npm_install ()
@@ -151,7 +153,7 @@ def epub(ptxfile, pub_file: Path, output: Path, stringparams):
151153 "Unable to build epub because node packages are not installed. Exiting..."
152154 )
153155 log .info (f"\n Now building ePub into { output } \n " )
154- with utils .working_directory ("." ):
156+ with utils .working_directory (Path () ):
155157 try :
156158 core .epub (
157159 ptxfile ,
@@ -169,7 +171,9 @@ def epub(ptxfile, pub_file: Path, output: Path, stringparams):
169171
170172
171173# build Kindle ePub:
172- def kindle (ptxfile , pub_file : Path , output : Path , stringparams ):
174+ def kindle (
175+ ptxfile : Path , pub_file : Path , output : Path , stringparams : Dict [str , str ]
176+ ) -> None :
173177 os .makedirs (output , exist_ok = True )
174178 try :
175179 utils .npm_install ()
@@ -179,7 +183,7 @@ def kindle(ptxfile, pub_file: Path, output: Path, stringparams):
179183 "Unable to build Kindle ePub because node packages are not installed. Exiting..."
180184 )
181185 log .info (f"\n Now building Kindle ePub into { output } \n " )
182- with utils .working_directory ("." ):
186+ with utils .working_directory (Path () ):
183187 try :
184188 core .epub (
185189 ptxfile ,
@@ -197,7 +201,13 @@ def kindle(ptxfile, pub_file: Path, output: Path, stringparams):
197201
198202
199203# build Braille:
200- def braille (ptxfile , pub_file : Path , output : Path , stringparams , page_format = "emboss" ):
204+ def braille (
205+ ptxfile : Path ,
206+ pub_file : Path ,
207+ output : Path ,
208+ stringparams : Dict [str , str ],
209+ page_format : str = "emboss" ,
210+ ) -> None :
201211 os .makedirs (output , exist_ok = True )
202212 log .warning (
203213 "Braille output is still experimental, and requires additional libraries from liblouis (specifically the file2brl software)."
@@ -210,7 +220,7 @@ def braille(ptxfile, pub_file: Path, output: Path, stringparams, page_format="em
210220 "Unable to build braille because node packages could not be installed. Exiting..."
211221 )
212222 log .info (f"\n Now building braille into { output } \n " )
213- with utils .working_directory ("." ):
223+ with utils .working_directory (Path () ):
214224 try :
215225 core .braille (
216226 xml_source = ptxfile ,
@@ -232,9 +242,9 @@ def webwork_sets(
232242 ptxfile : Path ,
233243 pub_file : Path ,
234244 output : Path ,
235- stringparams ,
236- zipped = False ,
237- ):
245+ stringparams : Dict [ str , str ] ,
246+ zipped : bool = False ,
247+ ) -> None :
238248 os .makedirs (output , exist_ok = True )
239249 log .info (f"\n Now building WeBWorK Sets into { output } \n " )
240250 # ensure working directory is preserved
0 commit comments