def _make_symlinks_from_a_folder_with_warning()

in src/sagemaker_xgboost_container/data_utils.py [0:0]


def _make_symlinks_from_a_folder_with_warning(dest_path: str, data_path: str):
    """
    :param dest_path: A dir
    :param data_path: Either dir or file
    :param depth: current folder depth, Integer
    """

    # If data_path is a single file A, create smylink A -> dest_path/A
    # If data_path is a dir, create symlinks for files located within depth of MAX_FOLDER_DEPTH
    # under this dir. Ignore the files in deeper sub dirs and log a warning if they exist.

    if (not os.path.exists(dest_path)) or (not os.path.exists(data_path)):
        raise exc.AlgorithmError(f"Unable to create symlinks as {data_path} or {dest_path} doesn't exist ")

    if (not os.path.isdir(dest_path)):
        raise exc.AlgorithmError(f"Unable to create symlinks as dest_path {dest_path} is not a dir")

    try:
        _make_symlinks_from_a_folder(dest_path, data_path, 1)
    except exc.UserError as e:
        if e.message == f"Folder depth exceed the limit: {MAX_FOLDER_DEPTH}.":
            logging.warning(
                f"The depth of folder {data_path} exceed the limit {MAX_FOLDER_DEPTH}."
                f" Files in deeper sub dirs won't be loaded."
                f" Please adjust the folder structure accordingly."
                )