File: update_api_docs.py

package info (click to toggle)
ycmd 0%2B20240823%2Bgit8b61f19%2Bds-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,040 kB
  • sloc: python: 44,018; cpp: 6,138; java: 486; sh: 378; cs: 207; javascript: 150; ansic: 82; makefile: 45; xml: 18; objc: 10
file content (58 lines) | stat: -rwxr-xr-x 1,672 bytes parent folder | download | duplicates (2)
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()