1
1
import argparse
2
2
import os
3
+ import pathlib
3
4
import shutil
4
- import subprocess
5
5
import sys
6
6
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
8
10
9
11
10
12
def build_docs_using_sphinx (version_number : str ):
11
13
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
-
16
14
python_path : str = sys .executable
17
15
output_path : str = f'{ curr_dir_path } /serve/v{ version_number } '
18
- output = subprocess . check_output (
16
+ run_command (
19
17
f"{ python_path } -m sphinx.cmd.build -M html source { output_path } "
20
18
)
21
- print (output .decode ())
22
-
23
19
tmp_path : str = f'{ output_path } @'
24
20
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 )
26
22
shutil .rmtree (tmp_path )
27
23
28
24
29
25
def 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 :
31
28
content : str = index_html .read ()
32
29
content = content .replace ('(latest)' , '' )
33
30
content = content .replace (
@@ -41,7 +38,7 @@ def update_index_html(version_number: str):
41
38
<!-- LATEST VERSION PLACEHOLDER -->
42
39
'''
43
40
)
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 :
45
42
index_html .write (content )
46
43
47
44
@@ -52,8 +49,14 @@ def main():
52
49
parser .add_argument ('version_number' )
53
50
args = parser .parse_args ()
54
51
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!' )
57
60
58
61
59
62
if __name__ == "__main__" :
0 commit comments