nodes: 0, module; 1, function_definition; 2, function_name:sort_loading_order; 3, parameters; 4, block; 5, identifier:step_files; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, return_statement; 12, comment:"""Sort step files into correct loading order.
  
      The correct loading order is first tools, then workflows without
      subworkflows, and then workflows with subworkflows. This order is
      required to avoid error messages when a working directory is used.
      """; 13, assignment; 14, assignment; 15, assignment; 16, identifier:f; 17, identifier:step_files; 18, comment:# assume that urls are tools; 19, block; 20, binary_operator:tools + workflows + workflows_with_subworkflows; 21, identifier:tools; 22, list; 23, identifier:workflows; 24, list; 25, identifier:workflows_with_subworkflows; 26, list; 27, if_statement; 28, binary_operator:tools + workflows; 29, identifier:workflows_with_subworkflows; 30, boolean_operator; 31, block; 32, else_clause; 33, identifier:tools; 34, identifier:workflows; 35, call; 36, call; 37, expression_statement; 38, block; 39, attribute; 40, argument_list; 41, attribute; 42, argument_list; 43, call; 44, expression_statement; 45, if_statement; 46, identifier:f; 47, identifier:startswith; 48, string; 49, identifier:f; 50, identifier:startswith; 51, string; 52, attribute; 53, argument_list; 54, assignment; 55, comparison_operator:obj.get('class', '') == 'Workflow'; 56, block; 57, else_clause; 58, string_content:http://; 59, string_content:https://; 60, identifier:tools; 61, identifier:append; 62, identifier:f; 63, identifier:obj; 64, call; 65, call; 66, string; 67, if_statement; 68, block; 69, identifier:load_yaml; 70, argument_list; 71, attribute; 72, argument_list; 73, string_content:Workflow; 74, comparison_operator:'requirements' in obj.keys(); 75, block; 76, else_clause; 77, expression_statement; 78, identifier:f; 79, identifier:obj; 80, identifier:get; 81, string; 82, string; 83, string; 84, call; 85, expression_statement; 86, if_statement; 87, block; 88, call; 89, string_content:class; 90, string_content:requirements; 91, attribute; 92, argument_list; 93, assignment; 94, comparison_operator:subw in obj['requirements']; 95, block; 96, else_clause; 97, expression_statement; 98, attribute; 99, argument_list; 100, identifier:obj; 101, identifier:keys; 102, identifier:subw; 103, dictionary; 104, identifier:subw; 105, subscript; 106, expression_statement; 107, block; 108, call; 109, identifier:tools; 110, identifier:append; 111, identifier:f; 112, pair; 113, identifier:obj; 114, string; 115, call; 116, expression_statement; 117, attribute; 118, argument_list; 119, string; 120, string; 121, string_content:requirements; 122, attribute; 123, argument_list; 124, call; 125, identifier:workflows; 126, identifier:append; 127, identifier:f; 128, string_content:class; 129, string_content:SubworkflowFeatureRequirement; 130, identifier:workflows_with_subworkflows; 131, identifier:append; 132, identifier:f; 133, attribute; 134, argument_list; 135, identifier:workflows; 136, identifier:append; 137, identifier:f
code: def sort_loading_order(step_files):
      """Sort step files into correct loading order.
  
      The correct loading order is first tools, then workflows without
      subworkflows, and then workflows with subworkflows. This order is
      required to avoid error messages when a working directory is used.
      """
      tools = []
      workflows = []
      workflows_with_subworkflows = []
  
      for f in step_files:
          # assume that urls are tools
          if f.startswith('http://') or f.startswith('https://'):
              tools.append(f)
          else:
              obj = load_yaml(f)
              if obj.get('class', '') == 'Workflow':
                  if 'requirements' in obj.keys():
                      subw = {'class': 'SubworkflowFeatureRequirement'}
                      if subw in obj['requirements']:
                          workflows_with_subworkflows.append(f)
                      else:
                          workflows.append(f)
                  else:
                      workflows.append(f)
              else:
                  tools.append(f)
      return tools + workflows + workflows_with_subworkflows