-
Notifications
You must be signed in to change notification settings - Fork 769
/
update_api_docs.py
executable file
·58 lines (43 loc) · 1.63 KB
/
update_api_docs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
import os
import platform
import sys
import subprocess
DIR_OF_THIS_SCRIPT = os.path.dirname( os.path.abspath( __file__ ) )
DIR_OF_DOCS = os.path.join( DIR_OF_THIS_SCRIPT, 'docs' )
def OnWindows():
return platform.system() == 'Windows'
# On Windows, distutils.spawn.find_executable only works for .exe files
# but .bat and .cmd files are also executables, so we use our own
# implementation.
def FindExecutable( executable ):
# Executable extensions used on Windows
WIN_EXECUTABLE_EXTS = [ '.exe', '.bat', '.cmd' ]
paths = os.environ[ 'PATH' ].split( os.pathsep )
base, extension = os.path.splitext( executable )
if OnWindows() and extension.lower() not in WIN_EXECUTABLE_EXTS:
extensions = WIN_EXECUTABLE_EXTS
else:
extensions = [ '' ]
for extension in extensions:
executable_name = executable + extension
if not os.path.isfile( executable_name ):
for path in paths:
executable_path = os.path.join( path, executable_name )
if os.path.isfile( executable_path ):
return executable_path
else:
return executable_name
return None
def GenerateApiDocs():
npm = FindExecutable( 'npm' )
if not npm:
sys.exit( 'ERROR: NPM is required to generate API docs.' )
os.chdir( os.path.join( DIR_OF_DOCS ) )
subprocess.call( [ npm, 'install', '--production' ] )
bootprint = FindExecutable( os.path.join( DIR_OF_DOCS, 'node_modules',
'.bin', 'bootprint' ) )
api = os.path.join( DIR_OF_DOCS, 'openapi.yml' )
subprocess.call( [ bootprint, 'openapi', api, DIR_OF_DOCS ] )
if __name__ == '__main__':
GenerateApiDocs()