def enumerate_global_imports(tokens):
imported_modules = []<EOL>import_line = False<EOL>from_import = False<EOL>parent_module = "<STR_LIT>"<EOL>function_count = <NUM_LIT:0><EOL>indentation = <NUM_LIT:0><EOL>for index, tok in enumerate(tokens):<EOL><INDENT>token_type = tok[<NUM_LIT:0>]<EOL>token_string = tok[<NUM_LIT:1>]<EOL>if token_type == tokenize.INDENT:<EOL><INDENT>indentation += <NUM_LIT:1><EOL><DEDENT>elif token_type == tokenize.DEDENT:<EOL><INDENT>indentation -= <NUM_LIT:1><EOL><DEDENT>elif token_type == tokenize.NEWLINE:<EOL><INDENT>import_line = False<EOL>from_import = False<EOL><DEDENT>elif token_type == tokenize.NAME:<EOL><INDENT>if token_string in ["<STR_LIT>", "<STR_LIT:class>"]:<EOL><INDENT>function_count += <NUM_LIT:1><EOL><DEDENT>if indentation == function_count - <NUM_LIT:1>:<EOL><INDENT>function_count -= <NUM_LIT:1><EOL><DEDENT>elif function_count >= indentation:<EOL><INDENT>if token_string == "<STR_LIT>":<EOL><INDENT>import_line = True<EOL><DEDENT>elif token_string == "<STR_LIT>":<EOL><INDENT>from_import = True<EOL><DEDENT>elif import_line:<EOL><INDENT>if token_type == tokenize.NAMEand tokens[index+<NUM_LIT:1>][<NUM_LIT:1>] != '<STR_LIT>':<EOL><INDENT>if not from_importand token_string not in reserved_words:<EOL><INDENT>if token_string not in imported_modules:<EOL><INDENT>if tokens[index+<NUM_LIT:1>][<NUM_LIT:1>] == '<STR_LIT:.>': <EOL><INDENT>parent_module = token_string + '<STR_LIT:.>'<EOL><DEDENT>else:<EOL><INDENT>if parent_module:<EOL><INDENT>module_string = (<EOL>parent_module + token_string)<EOL>imported_modules.append(module_string)<EOL>parent_module = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>imported_modules.append(token_string)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>return imported_modules<EOL>
Returns a list of all globally imported modules (skips modules imported
inside of classes, methods, or functions).  Example::

    >>> enumerate_global_modules(tokens)
    ['sys', 'os', 'tokenize', 're']

.. note::

    Does not enumerate imports using the 'from' or 'as' keywords.