docstr: Remove a kernel spec directory by name.
  
  Returns the path that was deleted.
docstr_tok: ["Remove","a","kernel","spec","directory","by","name",".","Returns","the","path","that","was","deleted","."]
code: def remove_kernel_spec(self, name):
      """Remove a kernel spec directory by name.
  
      Returns the path that was deleted.
      """
      save_native = self.ensure_native_kernel
      try:
          self.ensure_native_kernel = False
          specs = self.find_kernel_specs()
      finally:
          self.ensure_native_kernel = save_native
      spec_dir = specs[name]
      self.log.debug("Removing %s", spec_dir)
      if os.path.islink(spec_dir):
          os.remove(spec_dir)
      else:
          shutil.rmtree(spec_dir)
      return spec_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 9 for calling the KernelSpecManager obj's underlying member method code with example usage: obj.remove_kernel_spec(name) and returns: spec_dir