code: def _resolve_source_for_path(
      source_path,
      source_origin,
      source,
      target_dir,
      resolve_flag_refs,
  ):
      target_type = _target_type_for_source(source)
      target_path = _target_path_for_source(
          source_path,
          source_origin,
          source,
          target_dir,
          resolve_flag_refs,
      )
      resolved_source = ResolvedSource(
          source,
          target_path,
          target_dir,
          source_path,
          source_origin,
      )
      if _source_resolved_to_target_dir(source_path, target_dir):
          if _rename_needed(source_path, target_path):
              _rename_source(
                  source_path, target_path, source.replace_existing
              )
      elif target_type == "link":
          _link_to_source(
              source_path, target_path, source.replace_existing
          )
      elif target_type == "copy":
          _copy_source(
              source_path, target_path, source.replace_existing
          )
      else:
          assert False, (target_type, source, source.resdef)
      return resolved_source
  
imports: import os
  import re
  import logging
  import typing
  from guild import cli
  from guild import resolver
  from guild import resourcedef
  from guild import util
label_desc: Use image node_id 25 for calling a global function with example usage: _resolve_source_for_path(source_path, source_origin, source, target_dir, resolve_flag_refs) and returns: resolved_source