code: def build_cmdstan_model(target_dir):
      """
      Rebuild cmdstan in the build environment, then use this installation to compile the stan model.
      The stan model is copied to {target_dir}/prophet_model.bin
      The cmdstan files required to run cmdstanpy commands are copied to {target_dir}/cmdstan-{version}.
  
      Parameters
      ----------
      target_dir: Directory to copy the compiled model executable and core cmdstan files to.
      """
      import cmdstanpy
  
      target_cmdstan_dir = (
          Path(target_dir) / f"cmdstan-{CMDSTAN_VERSION}"
      ).resolve()
      with tempfile.TemporaryDirectory() as tmp_dir:
          # long paths on windows can cause problems during build
          if IS_WINDOWS:
              cmdstan_dir = (
                  Path(tmp_dir) / f"cmdstan-{CMDSTAN_VERSION}"
              ).resolve()
          else:
              cmdstan_dir = target_cmdstan_dir
  
          install_cmdstan_deps(cmdstan_dir)
          model_name = "prophet.stan"
          # note: ensure copy target is a directory not a file.
          temp_stan_file = copy(
              os.path.join(MODEL_DIR, model_name),
              cmdstan_dir.parent.resolve(),
          )
          sm = cmdstanpy.CmdStanModel(stan_file=temp_stan_file)
          target_name = "prophet_model.bin"
          copy(sm.exe_file, os.path.join(target_dir, target_name))
  
          if IS_WINDOWS and repackage_cmdstan():
              copytree(cmdstan_dir, target_cmdstan_dir)
  
      # Clean up
      for f in Path(MODEL_DIR).iterdir():
          if f.is_file() and f.name != model_name:
              os.remove(f)
  
      if repackage_cmdstan():
          prune_cmdstan(target_cmdstan_dir)
  
imports: import os
  import platform
  from pathlib import Path
  from shutil import copy, copytree, rmtree
  from typing import List
  import tempfile
  from setuptools import find_packages, setup, Extension
  from setuptools.command.build_ext import build_ext
  from setuptools.command.build_py import build_py
  from setuptools.command.editable_wheel import editable_wheel
  from wheel.bdist_wheel import bdist_wheel
label_desc: Use image node_id 5 for calling a global function with example usage: build_cmdstan_model(target_dir) without return types