nodes: 0, module; 1, function_definition; 2, function_name:sort_versions; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, if_statement; 8, for_statement; 9, comment:# default ordering is version descending; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, comment:"""Sort entries by version.
  
          The order is typically descending, but package order functions can
          change this.
          """; 14, attribute; 15, block; 16, identifier:orderer; 17, parenthesized_expression; 18, block; 19, assignment; 20, assignment; 21, attribute; 22, block; 23, identifier:self; 24, identifier:sorted; 25, return_statement; 26, boolean_operator; 27, expression_statement; 28, if_statement; 29, attribute; 30, call; 31, attribute; 32, True; 33, identifier:self; 34, identifier:pr; 35, expression_statement; 36, attribute; 37, list; 38, assignment; 39, comparison_operator:entries is not None; 40, block; 41, identifier:self; 42, identifier:entries; 43, identifier:sorted; 44, argument_list; 45, identifier:self; 46, identifier:sorted; 47, call; 48, attribute; 49, identifier:package_orderers; 50, identifier:entries; 51, call; 52, identifier:entries; 53, None; 54, expression_statement; 55, expression_statement; 56, if_statement; 57, return_statement; 58, attribute; 59, keyword_argument; 60, keyword_argument; 61, attribute; 62, argument_list; 63, identifier:self; 64, identifier:solver; 65, attribute; 66, argument_list; 67, assignment; 68, assignment; 69, attribute; 70, block; 71, identifier:self; 72, identifier:entries; 73, identifier:key; 74, lambda; 75, identifier:reverse; 76, True; 77, identifier:self; 78, identifier:pr; 79, string:"sorted: %s packages: version descending"; 80, attribute; 81, identifier:orderer; 82, identifier:reorder; 83, attribute; 84, keyword_argument; 85, attribute; 86, identifier:entries; 87, attribute; 88, True; 89, identifier:self; 90, identifier:pr; 91, expression_statement; 92, lambda_parameters; 93, attribute; 94, identifier:self; 95, identifier:package_name; 96, identifier:self; 97, identifier:entries; 98, identifier:key; 99, lambda; 100, identifier:self; 101, identifier:entries; 102, identifier:self; 103, identifier:sorted; 104, call; 105, identifier:x; 106, identifier:x; 107, identifier:version; 108, lambda_parameters; 109, attribute; 110, attribute; 111, argument_list; 112, identifier:x; 113, identifier:x; 114, identifier:package; 115, identifier:self; 116, identifier:pr; 117, string:"sorted: %s packages: %s"; 118, attribute; 119, call; 120, identifier:self; 121, identifier:package_name; 122, identifier:repr; 123, argument_list; 124, identifier:orderer
code: def sort_versions(self):
          """Sort entries by version.
  
          The order is typically descending, but package order functions can
          change this.
          """
          if self.sorted:
              return
  
          for orderer in (self.solver.package_orderers or []):
              entries = orderer.reorder(self.entries, key=lambda x: x.package)
              if entries is not None:
                  self.entries = entries
                  self.sorted = True
  
                  if self.pr:
                      self.pr("sorted: %s packages: %s", self.package_name, repr(orderer))
                  return
  
          # default ordering is version descending
          self.entries = sorted(self.entries, key=lambda x: x.version, reverse=True)
          self.sorted = True
  
          if self.pr:
              self.pr("sorted: %s packages: version descending", self.package_name)