docstr: This method is very similar to importlib's `_gcd_import`.
docstr_tok: ["This","method","is","very","similar","to","importlib","'s","`","_gcd_import","`","."]
code: def _do_import(self, import_path, sys_path):
      """
      This method is very similar to importlib's `_gcd_import`.
      """
      import_parts = [
          force_unicode(i.value if isinstance(i, tree.Name) else i)
          for i in import_path
      ]
  
      # Handle "magic" Flask extension imports:
      # ``flask.ext.foo`` is really ``flask_foo`` or ``flaskext.foo``.
      if len(import_path) > 2 and import_parts[:2] == ["flask", "ext"]:
          # New style.
          ipath = ("flask_" + str(import_parts[2]),) + import_path[3:]
          modules = self._do_import(ipath, sys_path)
          if modules:
              return modules
          else:
              # Old style
              return self._do_import(
                  ("flaskext",) + import_path[2:], sys_path
              )
  
      if import_parts[0] in settings.auto_import_modules:
          module = _load_module(
              self._evaluator,
              import_names=import_parts,
              sys_path=sys_path,
          )
          return ContextSet(module)
  
      module_name = ".".join(import_parts)
      try:
          return ContextSet(
              self._evaluator.module_cache.get(module_name)
          )
      except KeyError:
          pass
  
      if len(import_path) > 1:
          # This is a recursive way of importing that works great with
          # the module cache.
          bases = self._do_import(import_path[:-1], sys_path)
          if not bases:
              return NO_CONTEXTS
          # We can take the first element, because only the os special
          # case yields multiple modules, which is not important for
          # further imports.
          parent_module = list(bases)[0]
  
          # This is a huge exception, we follow a nested import
          # ``os.path``, because it's a very important one in Python
          # that is being achieved by messing with ``sys.modules`` in
          # ``os``.
          if import_parts == ["os", "path"]:
              return parent_module.py__getattribute__("path")
  
          try:
              method = parent_module.py__path__
          except AttributeError:
              # The module is not a package.
              _add_error(self.module_context, import_path[-1])
              return NO_CONTEXTS
          else:
              paths = method()
              debug.dbg(
                  "search_module %s in paths %s", module_name, paths
              )
              for path in paths:
                  # At the moment we are only using one path. So this is
                  # not important to be correct.
                  if not isinstance(path, list):
                      path = [path]
                  (
                      code,
                      module_path,
                      is_pkg,
                  ) = self._evaluator.compiled_subprocess.get_module_info(
                      string=import_parts[-1],
                      path=path,
                      full_name=module_name,
                      is_global_search=False,
                  )
                  if module_path is not None:
                      break
              else:
                  _add_error(self.module_context, import_path[-1])
                  return NO_CONTEXTS
      else:
          debug.dbg(
              "global search_module %s in %s",
              import_parts[-1],
              self.file_path,
          )
          # Override the sys.path. It works only good that way.
          # Injecting the path directly into `find_module` did not work.
          (
              code,
              module_path,
              is_pkg,
          ) = self._evaluator.compiled_subprocess.get_module_info(
              string=import_parts[-1],
              full_name=module_name,
              sys_path=sys_path,
              is_global_search=True,
          )
          if module_path is None:
              # The module is not a package.
              _add_error(self.module_context, import_path[-1])
              return NO_CONTEXTS
  
      module = _load_module(
          self._evaluator,
          module_path,
          code,
          sys_path,
          import_names=import_parts,
          safe_module_name=True,
      )
  
      if module is None:
          # The file might raise an ImportError e.g. and therefore not be
          # importable.
          return NO_CONTEXTS
  
      return ContextSet(module)
  
imports: import os
  from parso.python import tree
  from parso.tree import search_ancestor
  from parso import python_bytes_to_unicode
  from jedi._compatibility import FileNotFoundError, ImplicitNSInfo, force_unicode, unicode
  from jedi import debug
  from jedi import settings
  from jedi.parser_utils import get_cached_code_lines
  from jedi.evaluate import sys_path
  from jedi.evaluate import helpers
  from jedi.evaluate import compiled
  from jedi.evaluate import analysis
  from jedi.evaluate.utils import unite
  from jedi.evaluate.cache import evaluator_method_cache
  from jedi.evaluate.filters import AbstractNameDefinition
  from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS
label_desc: Use image node_id 5 for calling the Importer obj's underlying member method code with example usage: obj._do_import(import_path, sys_path) and returns: ContextSet, ContextSet, ContextSet, NO_CONTEXTS, modules, self, NO_CONTEXTS, parent_module, NO_CONTEXTS, NO_CONTEXTS, NO_CONTEXTS