
    7j                     ^    d Z ddlZddlmZ ddlmZ ddlmZmZ ddl	m
Z
 d Zd Zd	 Zdd
Zy)z-Helpful decorators that subcommands can use.
    N)	monotonic)cli)find_keyboard_from_dirkeyboard_folder)find_keymap_from_dirc                  v    	 t         j                  S # t        $ r t         j                  j                  cY S w xY w)zAHandle missing cli.subcommand_name on older versions of milc
    )r   subcommand_nameAttributeError_subcommand__name__     G/home/hanthebot/chat/keyboard/qmk_firmware/lib/python/qmk/decorators.py_get_subcommand_namer      s2    (""" ('''(s    #88c                 B     t        j                          fd       }|S )zSets `cli.config.<subcommand>.keyboard` based on environment.

    This will rewrite cli.config.<subcommand>.keyboard if the user did not pass `--keyboard` and the directory they are currently in is a keyboard or keymap directory.
    c                  b   t               }t        j                  |   d   dk(  r3t        t        j                  |   d         t        j                  |   d<   t        j                  |   d   dk7  r8t               }|r,|t        j                  |   d<   dt        j                  |   d<    | i |S )Nkeyboardconfig_fileargumentkeyboard_directory)r   r   config_sourcer   configr   )argskwargscmdr   funcs       r   wrapperz#automagic_keyboard.<locals>.wrapper   s    "$ S!*->*9#**S/*:U*VCJJsOJ' S!*-;-/H.6

3
+5I!!#&z2T$V$$r   	functoolswrapsr   r   s   ` r   automagic_keyboardr"      s'    
 __T% %$ Nr   c                 B     t        j                          fd       }|S )zSets `cli.config.<subcommand>.keymap` based on environment.

    This will rewrite cli.config.<subcommand>.keymap if the user did not pass `--keymap` and the directory they are currently in is a keymap, layout, or user directory.
    c                      t               }t        j                  |   d   dk7  r;t               \  }}|r,|t        j                  |   d<   |t        j                  |   d<    | i |S )Nkeymapr   )r   r   r   r   r   )r   r   r   keymap_namekeymap_typer   s        r   r   z!automagic_keymap.<locals>.wrapper5   sl    "$ S!(+z9';'=$K,7

3)3>!!#&x0T$V$$r   r   r!   s   ` r   automagic_keymapr(   0   s'    
 __T% % Nr   c                       fd}|S )ag  Least Recently Used Cache- cache the result of a function.

    Args:

        timeout
            How many seconds to cache results for.

        maxsize
            The maximum size of the cache in bytes

        typed
            When `True` argument types will be taken into consideration, for example `3` and `3.0` will be treated as different keys.
    c                       t        j                                t               z    _        t        j                          fd       } j
                  |_         j                  |_        |S )N)maxsizetypedc                      t               j                  k\  r"t               z   _        j                           | i |S )N)r   
expirationcache_clear)r   r   r   timeouts     r   wrapped_funcz6lru_cache.<locals>.wrapper_cache.<locals>.wrapped_funcX   s;    {doo-"++"7  "(((r   )r   	lru_cacher   r.   r    
cache_infor/   )r   r1   r+   r0   r,   s   ` r   wrapper_cachez lru_cache.<locals>.wrapper_cacheT   sg    @y""7%@F#+/			) 
	) #'//#'#3#3 r   r   )r0   r+   r,   r4   s   ``` r   r2   r2   F   s    $ r   )
      F)__doc__r   timer   milcr   qmk.keyboardr   r   
qmk.keymapr   r   r"   r(   r2   r   r   r   <module>r<      s-       @ +(6, r   