code: def _validate_py_version_and_set_if_needed(
      py_version, version_config, framework
  ):
      """Checks if the Python version is one of the supported versions."""
      if "repository" in version_config:
          available_versions = version_config.get("py_versions")
      else:
          available_versions = list(version_config.keys())
  
      if not available_versions:
          if py_version:
              logger.info(
                  "Ignoring unnecessary Python version: %s.", py_version
              )
          return None
  
      if py_version is None and defaults.SPARK_NAME == framework:
          return None
  
      if py_version is None and len(available_versions) == 1:
          logger.info(
              "Defaulting to only available Python version: %s",
              available_versions[0],
          )
          return available_versions[0]
  
      _validate_arg(py_version, available_versions, "Python version")
      return py_version
  
imports: from __future__ import absolute_import
  import json
  import logging
  import os
  import re
  from typing import Optional
  from packaging.version import Version
  from sagemaker import utils
  from sagemaker.jumpstart.constants import DEFAULT_JUMPSTART_SAGEMAKER_SESSION
  from sagemaker.jumpstart.utils import is_jumpstart_model_input
  from sagemaker.spark import defaults
  from sagemaker.jumpstart import artifacts
  from sagemaker.workflow import is_pipeline_variable
  from sagemaker.workflow.utilities import override_pipeline_parameter_var
  from sagemaker.fw_utils import GRAVITON_ALLOWED_TARGET_INSTANCE_FAMILY, GRAVITON_ALLOWED_FRAMEWORKS
label_desc: Use image node_id 16 for calling a global function with example usage: _validate_py_version_and_set_if_needed(py_version, version_config, framework) and returns: py_version, None, None, available_versions