code: def build_sdist(
      sdist_directory: str,
      config_settings: Optional[Dict[str, Any]] = None,
  ) -> str:
      """Build a source distribution"""
      logger = logging.getLogger("xgboost.packager.build_sdist")
  
      if config_settings:
          raise NotImplementedError(
              "XGBoost's custom build backend doesn't support config_settings option "
              f"when building sdist. {config_settings=}"
          )
  
      cpp_src_dir = TOPLEVEL_DIR.parent
      if not cpp_src_dir.joinpath("CMakeLists.txt").exists():
          raise RuntimeError(
              f"Did not find CMakeLists.txt from {cpp_src_dir}"
          )
  
      # Create tempdir with Python package + C++ sources
      with tempfile.TemporaryDirectory() as td:
          td_path = pathlib.Path(td)
  
          workspace = td_path / "sdist_workspace"
          workspace.mkdir()
          logger.info(
              "Copying project files to temporary directory %s",
              str(workspace),
          )
  
          copy_with_logging(
              TOPLEVEL_DIR / "pyproject.toml", workspace, logger=logger
          )
          copy_with_logging(
              TOPLEVEL_DIR / "hatch_build.py", workspace, logger=logger
          )
          copy_with_logging(
              TOPLEVEL_DIR / "README.rst", workspace, logger=logger
          )
  
          copytree_with_logging(
              TOPLEVEL_DIR / "xgboost",
              workspace / "xgboost",
              logger=logger,
          )
          copytree_with_logging(
              TOPLEVEL_DIR / "packager",
              workspace / "packager",
              logger=logger,
          )
  
          temp_cpp_src_dir = workspace / "cpp_src"
          copy_cpp_src_tree(
              cpp_src_dir, target_dir=temp_cpp_src_dir, logger=logger
          )
  
          with cd(workspace):
              sdist_name = hatchling.build.build_sdist(
                  sdist_directory, config_settings
              )
      return sdist_name
  
file_path: xgboost/python-package/packager/pep517.py
imports: import dataclasses
  import logging
  import os
  import pathlib
  import tempfile
  from contextlib import contextmanager
  from typing import Any, Dict, Iterator, Optional, Union
  import hatchling.build
  from .build_config import BuildConfiguration
  from .nativelib import locate_local_libxgboost, locate_or_build_libxgboost
  from .sdist import copy_cpp_src_tree
  from .util import copy_with_logging, copytree_with_logging
label_desc: Use image node_id 3 for calling a global function with example usage: build_sdist(sdist_directory, config_settings) and returns: sdist_name