11import argparse
22import os
3+ import pathlib
34import shutil
4- import subprocess
55import sys
66
7- curr_dir_path : str = os .path .dirname (os .path .realpath (__file__ ))
7+ from helpers import run_command
8+
9+ curr_dir_path : str = pathlib .Path (os .path .realpath (__file__ )).parent
810
911
1012def build_docs_using_sphinx (version_number : str ):
1113 print (f"Building docs for version v{ version_number } " )
12- if version_number [0 ] == 'v' :
13- raise ValueError (
14- 'Please provide version number without "v" prefix' )
15-
1614 python_path : str = sys .executable
1715 output_path : str = f'{ curr_dir_path } /serve/v{ version_number } '
18- output = subprocess . check_output (
16+ run_command (
1917 f"{ python_path } -m sphinx.cmd.build -M html source { output_path } "
2018 )
21- print (output .decode ())
22-
2319 tmp_path : str = f'{ output_path } @'
2420 shutil .move (output_path , tmp_path )
25- shutil .move (os . path . join (tmp_path , 'html' ), output_path )
21+ shutil .move (pathlib . Path (tmp_path , 'html' ), output_path )
2622 shutil .rmtree (tmp_path )
2723
2824
2925def update_index_html (version_number : str ):
30- with open (os .path .join (curr_dir_path , 'serve' , 'index.html' ), 'r' , encoding = 'utf-8' ) as index_html :
26+ print ('Updating index.html...' )
27+ with open (pathlib .Path (curr_dir_path / 'serve' / 'index.html' ), 'r' , encoding = 'utf-8' ) as index_html :
3128 content : str = index_html .read ()
3229 content = content .replace ('(latest)' , '' )
3330 content = content .replace (
@@ -41,7 +38,7 @@ def update_index_html(version_number: str):
4138 <!-- LATEST VERSION PLACEHOLDER -->
4239 '''
4340 )
44- with open (os . path . join (curr_dir_path , 'serve' , 'index.html' ), 'w' , encoding = 'utf-8' ) as index_html :
41+ with open (pathlib . Path (curr_dir_path / 'serve' / 'index.html' ), 'w' , encoding = 'utf-8' ) as index_html :
4542 index_html .write (content )
4643
4744
@@ -52,8 +49,14 @@ def main():
5249 parser .add_argument ('version_number' )
5350 args = parser .parse_args ()
5451
55- build_docs_using_sphinx (args .version_number )
56- update_index_html (args .version_number )
52+ version_number : str = args .version_number
53+ # remove "v" prefix if present
54+ if version_number .startswith ('v' ):
55+ version_number = version_number .replace ('v' , '' )
56+
57+ build_docs_using_sphinx (version_number )
58+ update_index_html (version_number )
59+ print ('Documentation built successfully!' )
5760
5861
5962if __name__ == "__main__" :
0 commit comments