docstr: Returns a :class:`KernelSpec` instance for a given kernel_name
  and resource_dir.
docstr_tok: ["Returns","a",":","class",":","`","KernelSpec","`","instance","for","a","given","kernel_name","and","resource_dir","."]
code: def _get_kernel_spec_by_name(self, kernel_name, resource_dir):
      """Returns a :class:`KernelSpec` instance for a given kernel_name
      and resource_dir.
      """
      if kernel_name == NATIVE_KERNEL_NAME:
          try:
              from ipykernel.kernelspec import (
                  RESOURCES,
                  get_kernel_dict,
              )
          except ImportError:
              # It should be impossible to reach this, but let's play it safe
              pass
          else:
              if resource_dir == RESOURCES:
                  return self.kernel_spec_class(
                      resource_dir=resource_dir, **get_kernel_dict()
                  )
  
      return self.kernel_spec_class.from_resource_dir(resource_dir)
  
imports: import errno
  import io
  import json
  import os
  import re
  import shutil
  import warnings
  from ipython_genutils.py3compat import PY3
  from traitlets import HasTraits, List, Unicode, Dict, Set, Bool, Type, CaselessStrEnum
  from traitlets.config import LoggingConfigurable
  from jupyter_core.paths import jupyter_data_dir, jupyter_path, SYSTEM_JUPYTER_PATH
label_desc: Use image node_id 5 for calling the KernelSpecManager obj's underlying member method code with example usage: obj._get_kernel_spec_by_name(kernel_name, resource_dir) and returns: self, self