original_docstring: Assign widths to auto-width columns.
  
          Parameters
          ----------
          columns : dict
              A dictionary where each key is an auto-width column.  The value
              should be a dictionary with the following information:
                - wants: how much width the column wants
                - min: the minimum that the width should set to, provided there
                  is enough room
               - weight: if present, a "weight" key indicates the number of
                 available characters the column should claim at a time.  This is
                 only in effect after each column has claimed one, and the
                 specific column has claimed its minimum.
          available : int or float('inf')
              Width available to be assigned.
  
          Returns
          -------
          Dictionary mapping each auto-width column to the assigned width.
          
docstring: Assign widths to auto-width columns.
  Parameters
  
  columns : dict
  A dictionary where each key is an auto-width column.  The value
  should be a dictionary with the following information:
  wants: how much width the column wants
  min: the minimum that the width should set to, provided there
  is enough room
  weight: if present, a "weight" key indicates the number of
  available characters the column should claim at a time.  This is
  only in effect after each column has claimed one, and the
  specific column has claimed its minimum.
  available : int or float('inf')
  Width available to be assigned.
  
  Returns
  
  Dictionary mapping each auto-width column to the assigned width.
docstring_tokens: Assign widths to auto - width columns . Parameters columns : dict A dictionary where each key is an auto - width column . The value should be a dictionary with the following information : wants : how much width the column wants min : the minimum that the width should set to provided there is enough room weight : if present a " weight " key indicates the number of available characters the column should claim at a time . This is only in effect after each column has claimed one and the specific column has claimed its minimum . available : int or float ( ' inf ' ) Width available to be assigned . Returns Dictionary mapping each auto - width column to the assigned width .
code: def _assign_widths(columns, available):
          """Assign widths to auto-width columns.
  
          Parameters
          ----------
          columns : dict
              A dictionary where each key is an auto-width column.  The value
              should be a dictionary with the following information:
                - wants: how much width the column wants
                - min: the minimum that the width should set to, provided there
                  is enough room
               - weight: if present, a "weight" key indicates the number of
                 available characters the column should claim at a time.  This is
                 only in effect after each column has claimed one, and the
                 specific column has claimed its minimum.
          available : int or float('inf')
              Width available to be assigned.
  
          Returns
          -------
          Dictionary mapping each auto-width column to the assigned width.
          """
          # NOTE: The method below is not very clever and does unnecessary
          # iteration.  It may end up being too slow, but at least it should
          # serve to establish the baseline (along with tests) that show the
          # desired behavior.
  
          assigned = {}
  
          # Make sure every column gets at least one.
          for column in columns:
              col_wants = columns[column]["wants"]
              if col_wants > 0:
                  available -= 1
                  assigned[column] = 1
          assert available >= 0, "bug: upstream checks should make impossible"
  
          weights = {c: columns[c].get("weight", 1) for c in columns}
          # ATTN: The sorting here needs to be stable across calls with the same
          # row so that the same assignments come out.
          colnames = sorted(assigned.keys(), reverse=True,
                            key=lambda c: (columns[c]["min"], weights[c], c))
          columns_in_need = set(assigned.keys())
          while available > 0 and columns_in_need:
              for column in colnames:
                  if column not in columns_in_need:
                      continue
  
                  col_wants = columns[column]["wants"] - assigned[column]
                  if col_wants < 1:
                      columns_in_need.remove(column)
                      continue
  
                  wmin = columns[column]["min"]
                  has = assigned[column]
                  claim = min(weights[column] if has >= wmin else wmin - has,
                              col_wants,
                              available)
                  available -= claim
                  assigned[column] += claim
                  lgr.log(9, "Claiming %d characters (of %d available) for %s",
                          claim, available, column)
                  if available == 0:
                      break
          lgr.debug("Available width after assigned: %s", available)
          lgr.debug("Assigned widths: %r", assigned)
          return assigned
code_tokens: def _assign_widths ( columns , available ) : assigned = { } for column in columns : col_wants = columns [ column ] [ "wants" ] if col_wants > 0 : available -= 1 assigned [ column ] = 1 assert available >= 0 , "bug: upstream checks should make impossible" weights = { c : columns [ c ] . get ( "weight" , 1 ) for c in columns } colnames = sorted ( assigned . keys ( ) , reverse = True , key = lambda c : ( columns [ c ] [ "min" ] , weights [ c ] , c ) ) columns_in_need = set ( assigned . keys ( ) ) while available > 0 and columns_in_need : for column in colnames : if column not in columns_in_need : continue col_wants = columns [ column ] [ "wants" ] - assigned [ column ] if col_wants < 1 : columns_in_need . remove ( column ) continue wmin = columns [ column ] [ "min" ] has = assigned [ column ] claim = min ( weights [ column ] if has >= wmin else wmin - has , col_wants , available ) available -= claim assigned [ column ] += claim lgr . log ( 9 , "Claiming %d characters (of %d available) for %s" , claim , available , column ) if available == 0 : break lgr . debug ( "Available width after assigned: %s" , available ) lgr . debug ( "Assigned widths: %r" , assigned ) return assigned
short_docstring: Assign widths to auto-width columns.
short_docstring_tokens: Assign widths to auto - width columns .
comment: """Assign widths to auto-width columns.
  
          Parameters
          ----------
          columns : dict
              A dictionary where each key is an auto-width column.  The value
              should be a dictionary with the following information:
                - wants: how much width the column wants
                - min: the minimum that the width should set to, provided there
                  is enough room
               - weight: if present, a "weight" key indicates the number of
                 available characters the column should claim at a time.  This is
                 only in effect after each column has claimed one, and the
                 specific column has claimed its minimum.
          available : int or float('inf')
              Width available to be assigned.
  
          Returns
          -------
          Dictionary mapping each auto-width column to the assigned width.
          """$SEP$# NOTE: The method below is not very clever and does unnecessary$SEP$# iteration.  It may end up being too slow, but at least it should$SEP$# serve to establish the baseline (along with tests) that show the$SEP$# desired behavior.$SEP$# Make sure every column gets at least one.$SEP$# ATTN: The sorting here needs to be stable across calls with the same$SEP$# row so that the same assignments come out.