original_docstring: Given a list of starting javascript files, figure out all the Module
    objects that need to be loaded to satisfiy their dependencies.
  
    The javascript files shoud specify their dependencies in a format that is
    textually equivalent to base.js' require syntax, namely:
  
       base.require(module1);
       base.require(module2);
       base.requireStylesheet(stylesheet);
  
    The output of this function is an array of Module objects ordered by
    dependency.
    
docstring: Given a list of starting javascript files, figure out all the Module
  objects that need to be loaded to satisfiy their dependencies.
  
  The javascript files shoud specify their dependencies in a format that is
  textually equivalent to base.js' require syntax, namely.
  
  
  
  The output of this function is an array of Module objects ordered by
  dependency.
docstring_tokens: Given a list of starting javascript files figure out all the Module objects that need to be loaded to satisfiy their dependencies . The javascript files shoud specify their dependencies in a format that is textually equivalent to base . js ' require syntax namely . The output of this function is an array of Module objects ordered by dependency .
code: def calc_load_sequence(filenames, toplevel_dir):
    """Given a list of starting javascript files, figure out all the Module
    objects that need to be loaded to satisfiy their dependencies.
  
    The javascript files shoud specify their dependencies in a format that is
    textually equivalent to base.js' require syntax, namely:
  
       base.require(module1);
       base.require(module2);
       base.requireStylesheet(stylesheet);
  
    The output of this function is an array of Module objects ordered by
    dependency.
    """
    all_resources = {}
    all_resources["scripts"] = {}
    toplevel_modules = []
    root_dir = ''
    if filenames:
      root_dir = os.path.abspath(os.path.dirname(filenames[0]))
    resource_finder = ResourceFinder(root_dir)
    for filename in filenames:
      if not os.path.exists(filename):
        raise Exception("Could not find %s" % filename)
  
      rel_filename = os.path.relpath(filename, toplevel_dir)
      dirname = os.path.dirname(rel_filename)
      modname  = os.path.splitext(os.path.basename(rel_filename))[0]
      if len(dirname):
        name = dirname.replace('/', '.') + '.' + modname
      else:
        name = modname
  
      if name in all_resources["scripts"]:
        continue
  
      module = Module(name)
      module.load_and_parse(filename, decl_required = False)
      all_resources["scripts"][module.name] = module
      module.resolve(all_resources, resource_finder)
  
    # Find the root modules: ones who have no dependencies.
    module_ref_counts = {}
    for module in all_resources["scripts"].values():
      module_ref_counts[module.name] = 0
  
    def inc_ref_count(name):
      module_ref_counts[name] = module_ref_counts[name] + 1
    for module in all_resources["scripts"].values():
      for dependent_module in module.dependent_modules:
        inc_ref_count(dependent_module.name)
  
    root_modules = [all_resources["scripts"][name]
                    for name, ref_count in module_ref_counts.items()
                    if ref_count == 0]
  
    root_modules.sort(lambda x, y: cmp(x.name, y.name))
  
    already_loaded_set = set()
    load_sequence = []
    for module in root_modules:
      module.compute_load_sequence_recursive(load_sequence, already_loaded_set)
    return load_sequence
code_tokens: def calc_load_sequence ( filenames , toplevel_dir ) : all_resources = { } all_resources [ "scripts" ] = { } toplevel_modules = [ ] root_dir = '' if filenames : root_dir = os . path . abspath ( os . path . dirname ( filenames [ 0 ] ) ) resource_finder = ResourceFinder ( root_dir ) for filename in filenames : if not os . path . exists ( filename ) : raise Exception ( "Could not find %s" % filename ) rel_filename = os . path . relpath ( filename , toplevel_dir ) dirname = os . path . dirname ( rel_filename ) modname = os . path . splitext ( os . path . basename ( rel_filename ) ) [ 0 ] if len ( dirname ) : name = dirname . replace ( '/' , '.' ) + '.' + modname else : name = modname if name in all_resources [ "scripts" ] : continue module = Module ( name ) module . load_and_parse ( filename , decl_required = False ) all_resources [ "scripts" ] [ module . name ] = module module . resolve ( all_resources , resource_finder ) module_ref_counts = { } for module in all_resources [ "scripts" ] . values ( ) : module_ref_counts [ module . name ] = 0 def inc_ref_count ( name ) : module_ref_counts [ name ] = module_ref_counts [ name ] + 1 for module in all_resources [ "scripts" ] . values ( ) : for dependent_module in module . dependent_modules : inc_ref_count ( dependent_module . name ) root_modules = [ all_resources [ "scripts" ] [ name ] for name , ref_count in module_ref_counts . items ( ) if ref_count == 0 ] root_modules . sort ( lambda x , y : cmp ( x . name , y . name ) ) already_loaded_set = set ( ) load_sequence = [ ] for module in root_modules : module . compute_load_sequence_recursive ( load_sequence , already_loaded_set ) return load_sequence
short_docstring: Given a list of starting javascript files, figure out all the Module
  objects that need to be loaded to satisfiy their dependencies.
short_docstring_tokens: Given a list of starting javascript files figure out all the Module objects that need to be loaded to satisfiy their dependencies .
comment: """Given a list of starting javascript files, figure out all the Module
    objects that need to be loaded to satisfiy their dependencies.
  
    The javascript files shoud specify their dependencies in a format that is
    textually equivalent to base.js' require syntax, namely:
  
       base.require(module1);
       base.require(module2);
       base.requireStylesheet(stylesheet);
  
    The output of this function is an array of Module objects ordered by
    dependency.
    """$SEP$# Find the root modules: ones who have no dependencies.