code: def _get_target_span_version(
      uri: str,
      split: example_gen_pb2.Input.Split,
      range_config: Optional[range_config_pb2.RangeConfig] = None,
  ) -> Tuple[Optional[int], Optional[int]]:
      """Retrieves a  target span and version for a given split pattern.
  
      If both Span and Version spec occur in the split pattern, searches for and
      returns both the target Span and Version. If only Span exists in the split
      pattern, searches for the target Span, and Version is returned as None.
      If Version is present, but not Span, an error is raised. If neither Span
      nor Version is present, returns both as None.
  
      Additonally, supports parsing span number from date stamps using the Date.
      specs. Once the calendar date is parsed from the Date specs, it is converted
      into a span number by counting the number of days since 01/01/1970.
  
      Args:
        uri: The base path from which files will be searched.
        split: An example_gen_pb2.Input.Split object which contains a split pattern,
          to be searched on.
        range_config: An instance of range_config_pb2.RangeConfig, which specifies
          which spans to consider when finding the most recent span and version. If
          unset, search for latest span number with no restrictions.
  
      Returns:
        Tuple of two ints, Span (optional) and Version (optional). Note
          that this function will update the {SPAN} or Date tags as well as the
          {VERSION} tags in the split config to actual Span and Version numbers.
  
      Raises:
        ValueError: if any of the following occurs:
          - If either Span or Version spec is occurs in the split pattern
            more than once.
          - If Version spec is provided, but Span spec is not present.
          - If Span or Version found is not an integer.
          - If a matching cannot be found for split pattern provided.
      """
      (
          is_match_span,
          is_match_date,
          is_match_version,
      ) = verify_split_pattern_specs(split)
  
      if not is_match_span and not is_match_date:
          return (None, None)
  
      (
          split_glob_pattern,
          split_regex_pattern,
      ) = _create_matching_glob_and_regex(
          uri=uri,
          split=split,
          is_match_span=is_match_span,
          is_match_date=is_match_date,
          is_match_version=is_match_version,
          range_config=range_config,
      )
  
      logging.info(
          "Glob pattern for split %s: %s",
          split.name,
          split_glob_pattern,
      )
      logging.info(
          "Regex pattern for split %s: %s",
          split.name,
          split_regex_pattern,
      )
  
      latest_span_tokens = None
      latest_span_int = None
      latest_version = None
      latest_version_int = None
  
      files = fileio.glob(split_glob_pattern)
      for file_path in files:
          (
              match_span_tokens,
              match_span_int,
              match_version,
              match_version_int,
          ) = _find_matched_span_version_from_path(
              file_path,
              split_regex_pattern,
              is_match_span,
              is_match_date,
              is_match_version,
          )
  
          if (
              latest_span_int is None
              or match_span_int > latest_span_int
          ):
              # Uses str instead of int because of zero padding digits.
              latest_span_tokens = match_span_tokens
              latest_span_int = match_span_int
              latest_version = match_version
              latest_version_int = match_version_int
          elif latest_span_int == match_span_int and (
              latest_version is None
              or match_version_int >= latest_version_int
          ):
              latest_version = match_version
              latest_version_int = match_version_int
  
      if latest_span_int is None or (
          is_match_version and latest_version is None
      ):
          raise ValueError(
              "Cannot find matching for split %s based on %s"
              % (split.name, split.pattern)
          )
  
      # Update split pattern so executor can find the files to ingest.
      if is_match_span:
          split.pattern = re.sub(
              SPAN_FULL_REGEX, latest_span_tokens[0], split.pattern
          )
      elif is_match_date:
          for spec, value in zip(DATE_SPECS, latest_span_tokens):
              split.pattern = split.pattern.replace(spec, value)
  
      if is_match_version:
          split.pattern = re.sub(
              VERSION_FULL_REGEX, latest_version, split.pattern
          )
  
      return latest_span_int, latest_version_int
  
imports: import datetime
  import os
  import re
  from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
  from absl import logging
  import numpy
  from tfx.dsl.io import fileio
  from tfx.proto import example_gen_pb2
  from tfx.proto import range_config_pb2
  from tfx.utils import io_utils
  from google.protobuf import json_format
  from tensorflow.core.example import example_pb2
  from tensorflow.core.example import feature_pb2
label_desc: Use image node_id 17 for calling a global function with example usage: _get_target_span_version(uri, split, range_config) and returns: latest_span_int,  latest_version_int, None,  None