code: def _load_configfile(configpath_or_obj, filetype="Config"):
      "Tries to load a configfile first as JSON, then as YAML, into a dict."
      import yaml
  
      if isinstance(configpath_or_obj, str) or isinstance(
          configpath_or_obj, Path
      ):
          obj = open(configpath_or_obj, encoding="utf-8")
      else:
          obj = configpath_or_obj
  
      try:
          with obj as f:
              try:
                  return json.load(
                      f, object_pairs_hook=collections.OrderedDict
                  )
              except ValueError:
                  f.seek(0)  # try again
              try:
                  import yte
  
                  return yte.process_yaml(f, require_use_yte=True)
              except yaml.YAMLError:
                  raise WorkflowError(
                      f"{filetype} file is not valid JSON or YAML. "
                      "In case of YAML, make sure to not mix "
                      "whitespace and tab indentation."
                  )
      except FileNotFoundError:
          raise WorkflowError(
              f"{filetype} file {configpath_or_obj} not found."
          )
  
imports: import collections
  import json
  from pathlib import Path
  from snakemake_interface_common.exceptions import WorkflowError
label_desc: Use image node_id 1 for calling a global function with example usage: _load_configfile(configpath_or_obj, filetype) and returns: json, yte