code: def _target_path_for_source(
      source_path,
      source_origin,
      source,
      target_dir,
      resolve_flag_refs,
  ):
      """Returns target path for source.
  
      If target path is defined for the source, it redefines any value
      defined for the resource parent.
      """
      target_path = _source_target_path(
          source, source_path, source_origin
      )
      if os.path.isabs(target_path):
          raise OpDependencyError(
              f"invalid path '{target_path}' in {source.resdef.name} resource "
              "(path must be relative)"
          )
      basename = os.path.basename(source_path)
      if source.rename:
          basename = _renamed_source_path(
              basename, source.rename, resolve_flag_refs
          )
      return os.path.join(target_dir, target_path, basename)
  
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 29 for calling a global function with example usage: _target_path_for_source(source_path, source_origin, source, target_dir, resolve_flag_refs) and returns: os