
    7jM                         d dl Z d dlmZ d dlmZ d dlmZ d dlmZm	Z	m
Z
 d dlmZ d dlmZmZmZ d dlmZmZ d	Z G d
 de      Z ed      d        Zd Zd Zd Zd Zy)    N)Path)	lru_cache)AttrDict)	json_loadvalidatemerge_ordered_dicts)truthy)QMK_FIRMWAREQMK_USERSPACEHAS_QMK_USERSPACE)under_qmk_firmwareunder_qmk_userspacezqmk_module.jsonc                        e Zd Z fdZ xZS )	ModuleAPIc                 \    t         |           |j                         D ]
  \  }}|| |<    y )N)super__init__items)selfkwargskeyvalue	__class__s       N/home/hanthebot/chat/keyboard/qmk_firmware/lib/python/qmk/community_modules.pyr   zModuleAPI.__init__   s0     ,,. 	JCDI	    )__name__
__module____qualname__r   __classcell__)r   s   @r   r   r      s     r   r      )maxsizec                     t        t        t        j                  d                  } | D cg c]  }t	        |       }}t        |      }| d   j                  }|j                  d      }g }|j                         D ][  \  }}|j                  t        |d   ||d   |j                  dd      |j                  dd       |j                  d	d       
             ] |||d   |d   |d   fS c c}w )Nz#data/constants/module_hooks/*.hjson.ret_typeargscall_params guardheader)r%   namer&   r'   r)   r*   r   r       )sortedsetr
   globr   r   stemsplitr   appendr   get)	module_definition_filesfmodule_definition_jsonsmodule_definitionslatest_module_versionlatest_module_version_partsapi_listr+   mods	            r   module_api_listr<      s   $S):):;`)a%bc5LMy|MM,-DE3B7<<"7"="=c"BH'--/ 	c	_Vr2'''4(778T*
 	 *,G,JLghiLj  mH  IJ  mK  K  K! Ns   C+c                      g } t         r| j                  t        dz         | j                  t        dz         g }| D ]7  }|j	                  t
              D ]  }|j                  |j                          9 |S )z Find all available modules.
    modules)r   r2   r   r
   rglobCOMMUNITY_MODULE_JSON_FILENAMEparent)search_dirsr>   
search_dirmodule_json_paths       r   find_available_module_pathsrE   -   s|     K=945|i/0G! 4
 * 0 01O P 	4NN+223	44 Nr   c                     t               D ]p  }t        |      }|st        |      }|st        |j	                               t        d      d }t        t        |       j	                               }|sh||k(  sn|c S  y)zFind a module by name.
    zmodules/N)rE   r   r   stras_posixlenr   )modulemodule_pathrelative_pathlhsrhss        r   find_module_pathrO   <   s}     34 *;7/<M-((*+C
O,<=$v,'')*SCZ r   c                     t        |       }|st        d|        t        |t        z        }t	        t
        j                  j                  d      d      st        |d       | |d<   ||d<   |S )zLoad a module JSON file.
    zModule not found: SKIP_SCHEMA_VALIDATIONFzqmk.community_module.v1rJ   rK   )	rO   FileNotFoundErrorr   r@   r	   osenvironr3   r   )rJ   rK   module_jsons      r   load_module_jsonrV   O   sq     #6*K"4VH =>>K*HHIK"**..!9:EB78"K!,Kr   c                 4    t        t        t        |             S )z>Load the module JSON files, matching the specified order.
    )listmaprV   )r>   s    r   load_module_jsonsrZ   a   s     $g.//r   )rS   pathlibr   	functoolsr   milc.attrdictr   qmk.json_schemar   r   r   qmk.utilr	   qmk.constantsr
   r   r   qmk.pathr   r   r@   r   r<   rE   rO   rV   rZ    r   r   <module>rc      sd    	   " D D  H H <!2   1K K*&$0r   