code: def _walk_to_root(path):
      
      if not os.path.exists(path):
          raise IOError('Starting path not found')
  
      if os.path.isfile(path):
          path = os.path.dirname(path)
  
      last_dir = None
      current_dir = os.path.abspath(path)
      while last_dir != current_dir:
          yield current_dir
          parent_dir = os.path.abspath(os.path.join(current_dir, os.path.pardir))
          last_dir, current_dir = current_dir, parent_dir
docs: Yield directories starting from the given directory up to the root