code: def _add_imports_to_env(self, raw_api):
          
          for namespace, desc in raw_api:
              for item in desc:
                  if isinstance(item, AstImport):
                      if namespace.name == item.target:
                          raise InvalidSpec('Cannot import current namespace.',
                                            item.lineno, item.path)
                      if item.target not in self.api.namespaces:
                          raise InvalidSpec(
                              'Namespace %s is not defined in any spec.' %
                              quote(item.target),
                              item.lineno, item.path)
                      env = self._get_or_create_env(namespace.name)
                      imported_env = self._get_or_create_env(item.target)
                      if namespace.name in imported_env:
                          # Block circular imports. The Python backend can't
                          # easily generate code for circular references.
                          raise InvalidSpec(
                              'Circular import of namespaces %s and %s '
                              'detected.' %
                              (quote(namespace.name), quote(item.target)),
                              item.lineno, item.path)
                      env[item.target] = imported_env
docs: Scans raw parser output for import declarations. Checks if the imports
          are valid, and then creates a reference to the namespace in the
          environment.
  
          Args:
              raw_api (Tuple[Namespace, List[stone.stone.parser._Element]]):
                  Namespace paired with raw parser output.