class_docstr: A manager for kernel specs.
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: str, resource_dir: str
  ) -> KernelSpec:
      """Returns a :class:`KernelSpec` instance for a given kernel_name
      and resource_dir.
      """
      kspec = None
      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:
                  kdict = get_kernel_dict()
                  kspec = self.kernel_spec_class(
                      resource_dir=resource_dir, **kdict
                  )
      if not kspec:
          kspec = self.kernel_spec_class.from_resource_dir(resource_dir)
  
      if not KPF.instance(parent=self.parent).is_provisioner_available(
          kspec
      ):
          raise NoSuchKernel(kernel_name)
  
      return kspec
  
imports: from __future__ import annotations
  import json
  import os
  import re
  import shutil
  import typing
  import warnings
  from jupyter_core.paths import SYSTEM_JUPYTER_PATH, jupyter_data_dir, jupyter_path
  from traitlets import Bool, CaselessStrEnum, Dict, HasTraits, List, Set, Type, Unicode, observe
  from traitlets.config import LoggingConfigurable
  from .provisioning import KernelProvisionerFactory
label_desc: Use image node_id 6 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: kspec