/ docs / scripts / build-api-docs.py
build-api-docs.py
 1  import os
 2  import shutil
 3  import subprocess
 4  
 5  import click
 6  
 7  
 8  @click.command()
 9  @click.option("--with-r", "with_r", is_flag=True, default=False, help="Build R documentation")
10  @click.option(
11      "--with-ts", "with_ts", is_flag=True, default=True, help="Build TypeScript documentation"
12  )
13  def main(with_r, with_ts):
14      try:
15          # Run "make rsthtml" in "api_reference" subfolder
16          print("Building API reference documentation...")
17          subprocess.run(["make", "clean"], check=True, cwd="api_reference")
18          subprocess.run(["make", "rsthtml"], check=True, cwd="api_reference")
19          subprocess.run(["make", "javadocs"], check=True, cwd="api_reference")
20          if with_r:
21              subprocess.run(["make", "rdocs"], check=True, cwd="api_reference")
22          if with_ts:
23              subprocess.run(["make", "tsdocs"], check=True, cwd="api_reference")
24          print("Build successful.")
25      except subprocess.CalledProcessError as e:
26          print(f"Build failed: {e}")
27          exit(1)
28  
29      destination_folder = "static/api_reference"
30      source_folder = "api_reference/build/html"
31  
32      # Remove the destination folder if it exists
33      if os.path.exists(destination_folder):
34          shutil.rmtree(destination_folder)
35          print(f"Removed existing static API docs at {destination_folder}.")
36  
37      # Copy the contents of "api_reference/build/html" to "static/api_reference"
38      shutil.copytree(source_folder, destination_folder)
39      print(f"Copied files from {source_folder} to {destination_folder}.")
40  
41  
42  if __name__ == "__main__":
43      main()