code: def _prepare_and_upload_runtime_scripts(
      spark_config: SparkConfig,
      s3_base_uri: str,
      s3_kms_key: str,
      sagemaker_session: Session,
  ):
      """Copy runtime scripts to a folder and upload to S3.
  
      In case of remote function, s3_base_uri is s3_root_uri + function_name.
      In case of pipeline, s3_base_uri is s3_root_uri + pipeline_name. The runtime scripts are
      uploaded only once per pipeline.
  
      Args:
          spark_config (SparkConfig): remote Spark job configurations.
  
          s3_base_uri (str): S3 location that the runtime scripts will be uploaded to.
  
          s3_kms_key (str): kms key used to encrypt the files uploaded to S3.
  
          sagemaker_session (str): SageMaker boto client session.
      """
  
      from sagemaker.workflow.utilities import (
          load_step_compilation_context,
      )
  
      step_compilation_context = load_step_compilation_context()
  
      if (
          step_compilation_context
          and not step_compilation_context.upload_runtime_scripts
      ):
          return s3_path_join(s3_base_uri, RUNTIME_SCRIPTS_CHANNEL_NAME)
  
      with _tmpdir() as bootstrap_scripts:
          # write entrypoint script to tmpdir
          entrypoint_script_path = os.path.join(
              bootstrap_scripts, ENTRYPOINT_SCRIPT_NAME
          )
          entry_point_script = ENTRYPOINT_SCRIPT
          if spark_config:
              entry_point_script = SPARK_ENTRYPOINT_SCRIPT
              spark_script_path = os.path.join(
                  os.path.dirname(__file__),
                  "runtime_environment",
                  SPARK_APP_SCRIPT_NAME,
              )
              shutil.copy2(spark_script_path, bootstrap_scripts)
  
          with open(entrypoint_script_path, "w", newline="\n") as file:
              file.writelines(entry_point_script)
  
          bootstrap_script_path = os.path.join(
              os.path.dirname(__file__),
              "runtime_environment",
              BOOTSTRAP_SCRIPT_NAME,
          )
          runtime_manager_script_path = os.path.join(
              os.path.dirname(__file__),
              "runtime_environment",
              RUNTIME_MANAGER_SCRIPT_NAME,
          )
  
          # copy runtime scripts to tmpdir
          shutil.copy2(bootstrap_script_path, bootstrap_scripts)
          shutil.copy2(runtime_manager_script_path, bootstrap_scripts)
  
          upload_path = S3Uploader.upload(
              bootstrap_scripts,
              s3_path_join(s3_base_uri, RUNTIME_SCRIPTS_CHANNEL_NAME),
              s3_kms_key,
              sagemaker_session,
          )
  
          if step_compilation_context:
              step_compilation_context.upload_runtime_scripts = False
          return upload_path
  
imports: from __future__ import absolute_import
  import dataclasses
  import os
  import re
  import shutil
  import sys
  import json
  import secrets
  from typing import Callable, Dict, List, Optional, Tuple, Union, TYPE_CHECKING
  from urllib.parse import urlparse
  from io import BytesIO
  from sagemaker.config.config_schema import REMOTE_FUNCTION_ENVIRONMENT_VARIABLES, REMOTE_FUNCTION_IMAGE_URI, REMOTE_FUNCTION_DEPENDENCIES, REMOTE_FUNCTION_PRE_EXECUTION_COMMANDS, REMOTE_FUNCTION_PRE_EXECUTION_SCRIPT, REMOTE_FUNCTION_INCLUDE_LOCAL_WORKDIR, REMOTE_FUNCTION_INSTANCE_TYPE, REMOTE_FUNCTION_JOB_CONDA_ENV, REMOTE_FUNCTION_ROLE_ARN, REMOTE_FUNCTION_S3_ROOT_URI, REMOTE_FUNCTION_S3_KMS_KEY_ID, REMOTE_FUNCTION_VOLUME_KMS_KEY_ID, REMOTE_FUNCTION_TAGS, REMOTE_FUNCTION_VPC_CONFIG_SUBNETS, REMOTE_FUNCTION_VPC_CONFIG_SECURITY_GROUP_IDS, REMOTE_FUNCTION_ENABLE_INTER_CONTAINER_TRAFFIC_ENCRYPTION
  from sagemaker.experiments._run_context import _RunContext
  from sagemaker.experiments.run import Run
  from sagemaker.image_uris import get_base_python_image_uri
  from sagemaker import image_uris
  from sagemaker.remote_function.checkpoint_location import CheckpointLocation
  from sagemaker.session import get_execution_role, _logs_for_job, Session
  from sagemaker.utils import name_from_base, _tmpdir, resolve_value_from_config, format_tags, Tags
  from sagemaker.s3 import s3_path_join, S3Uploader
  from sagemaker import vpc_utils
  from sagemaker.remote_function.core.stored_function import StoredFunction, _SerializedData
  from sagemaker.remote_function.core.pipeline_variables import Context
  from sagemaker.remote_function.runtime_environment.runtime_environment_manager import RuntimeEnvironmentManager, _DependencySettings
  from sagemaker.remote_function import logging_config
  from sagemaker.remote_function.spark_config import SparkConfig
  from sagemaker.spark import defaults
  from sagemaker.remote_function.custom_file_filter import CustomFileFilter, copy_workdir, resolve_custom_file_filter_from_config_file
label_desc: Use image node_id 1 for calling a global function with example usage: _prepare_and_upload_runtime_scripts(spark_config, s3_base_uri, s3_kms_key, sagemaker_session) and returns: s3_path_join, upload_path