o 7]h` @sHddlZddlmZddlmZddlmZmZmZm Z ej dkr(ddlm Z nddl m Z Gddde Z d ed e e d eefd d Zd edeedeedeed eef ddZ dd edeedeeed eefddZedkrddlmZeGdddZededddedddedddgZeeedSdS)N)Fraction)ceil)castListOptionalSequence))Protocolc@s:eZdZUdZdZeeed<dZeed<dZ eed<dS)Edgez1Any object that defines an edge (such as Layout).Nsizeratio minimum_size) __name__ __module__ __qualname____doc__r rint__annotations__rrrr9/usr/lib/python3/dist-packages/pip/_vendor/rich/_ratio.pyr s  r totaledgesreturnc Csdd|D}t}d|vrtddtt||D}|tdd|D}|dkr2ddt||DS||td d|D}|D]\}}||j|jkrS|j||<nq@|d} |D]\}}t||j| d \} } | ||<qZnd|vs ttt |S) aDivide total space to satisfy size, ratio, and minimum_size, constraints. The returned list of integers should add up to total in most cases, unless it is impossible to satisfy all the constraints. For instance, if there are two edges with a minimum size of 20 each and `total` is 30 then the returned list will be greater than total. In practice, this would mean that a Layout object would clip the rows that would overflow the screen height. Args: total (int): Total number of characters. edges (List[Edge]): Edges within total space. Returns: List[int]: Number of characters for each edge. cSsg|]}|jpdqSN)r ).0edgerrr %sz!ratio_resolve..NcSs$g|]\}\}}|dur||fqSrr)rindexr rrrrr,s  css|]}|pdVqdS)rNr)rr rrr 2sz ratio_resolve..rcSs&g|]\}}|dur|jpdn|qS)Nr )r)rr rrrrr5s css|] \}}|jp dVqdS)r N)r)r_rrrrr ;sr ) r enumeratezipsumrrdivmodrrr) rrsizes _Fractionflexible_edges remainingportionrr remainderr rrr ratio_resolves4     $r,ratiosmaximumsvaluesc Csddt||D}t|}|s|ddS|}g}|j}t|||D])\}} } |rH|dkrHt| t|||} || | || 8}||8}q#|| q#|S)adDivide an integer total in to parts based on ratios. Args: total (int): The total to divide. ratios (List[int]): A list of integer ratios. maximums (List[int]): List of maximums values for each slot. values (List[int]): List of values Returns: List[int]: A list of integers guaranteed to sum to total. cSg|] \}}|r |ndqSrr)rr_maxrrrr_z ratio_reduce..Nr)r#r$appendminround) rr-r.r/ total_ratiototal_remainingresultr4rmaximumvalue distributedrrr ratio_reduceQs     r=minimumsc Cs|r ddt||D}t|}|dksJd|}g}|j}|dur+dgt|}n|}t||D]"\}} |dkrFt| t|||} n|} || ||8}|| 8}q2|S)a<Distribute an integer total in to parts based on ratios. Args: total (int): The total to divide. ratios (List[int]): A list of integer ratios. minimums (List[int]): List of minimum values for each slot. Returns: List[int]: A list of integers guaranteed to sum to total. cSr0r1r)rr_minrrrrr3z$ratio_distribute..rzSum of ratios must be > 0N)r#r$r4lenmaxr) rr-r>r7r8distributed_totalr4 _minimumsrminimumr<rrrratio_distributeqs$  rE__main__) dataclassc@s6eZdZUdZeeed<dZeed<dZeed<dS)ENr r rr) rrrr rrrrrrrrrrHs  rHnr r)sys fractionsrmathrtypingrrrr version_infor pip._vendor.typing_extensionsr rr,r=rEr dataclassesrGrHresolvedprintr$rrrrsJ    = !  $ (