
    7jl                         d Z ddlZddlZddlZddlZddlmZ  ej                  d      Zda	da
d Zdded	efd
ZddZej                  d        Zd ZdefdZy)zUtility functions.
    N)cliz^(\d+)\.(\d+)\.(\d+)TFc                 ~    t         rt        j                  |        t        rt        j                         d   }|r|y y )N   )maybe_exit_should_exitsysexitmaybe_exit_reraiseexc_info)rces     A/home/hanthebot/chat/keyboard/qmk_firmware/lib/python/qmk/util.py
maybe_exitr      s5    LLN1G      should_exitshould_reraisec                     | a |ay )N)r   r	   )r   r   s     r   maybe_exit_configr      s     )'r   c                     | dv rt        |       S t        |       j                         j                         }|dv ry|dv ry|S )zReturns True if the value is truthy, False otherwise.

    Deals with:
        True: 1, true, t, yes, y, on
        False: 0, false, f, no, n, off
    >   FT>   1tyonyestrueT>   0fnnoofffalseF)boolstrstriplower)valuevalue_if_unknown
test_values      r   truthyr(   !   sO     E{U!!#))+J99::r   c               #     K   t         j                  j                  j                  d} n$t         j                  j                  j                  } | s	t         yt        j                  t              5  ddlm	} ddl
m  |       5 fd}| ddd       	 ddd       y# 1 sw Y   xY w# 1 sw Y   nxY wt        j                         5 j                   ddd       y# 1 sw Y   yxY ww)zReturns a function that can be used in place of a map() call.

    Attempts to use `mpire`, falling back to `multiprocessing` if it's not
    available. If parallelization is not requested, returns the original map()
    function.
    NTr   )
WorkerPool)make_single_argumentsc              7   T   K   j                  |  |ddid      D ]  }|  y w)N	generatorFT)progress_bar)imap_unordered)funcargsrr+   pools      r   _workerzparallelize.<locals>._workerP   s:     ,,T3H$3`Z_3`os,t AGs   %()r   configuserparallel_searchmap
contextlibsuppressImportErrormpirer*   mpire.utilsr+   multiprocessingPoolr/   )r7   r*   r4   r+   r3   s      @@r   parallelizer@   6   s      zz&&.**//99 	 
		[	) $5\ 	T
 M	 	 	 	  
			 "4!!!" " "sN   A0C54B1B%	B1	C5%B.	*B11B:6C5C) 	C5)C2.C5c                  d    t               5 }t         || i |      cddd       S # 1 sw Y   yxY w)zGEffectively runs `map()` but executes it in parallel if necessary.
    N)r@   list)r1   kwargsmap_fns      r   parallel_maprE   ]   s4     
 -&
 FD+F+,- - -s   &/verc                     t         j                  |       }|sydt        |j                  d            dt        |j                  d            dt        |j                  d            dS )N
0x000000000xr   02d      04d)TRIPLET_PATTERNmatchintgroup)rF   ms     r   triplet_to_bcdrS   h   sZ    c"AAGGAJ$S_S$9#aggaj/#9NOOr   )TF)F)__doc__r9   r>   r   remilcr   compilerN   r   r	   r   r!   r   r(   contextmanagerr@   rE   r"   rS    r   r   <module>rZ      s      
 	 "**45  (4 ( (* #" #"L-P Pr   