
    7jI!              
       (   d Z ddlZddlZddlZddlZ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 ddlmZ d Z e	ej$                  j'                  d	 e                   Zej+                         r5 eed
z        ej.                  z   ej$                  d   z   ej$                  d<   dej$                  v r9ej$                  d   ej.                  z   ej$                  d   z   ej$                  d<   ddddddZg dZg dZd Zd Zd Zd Zd Zd Z ejB                  d   dk7  sejB                  d   dk  r e d        e"d        ejF                  d       Z$ e%e$d         d!k  r= e%e$d         dk  r/ e	d"      jM                         Z' e d# ee'               e"d       ejP                  jS                  ejT                        Z+e+ej$                  d   jG                  ej.                        vr7ej.                  jY                  e+ej$                  d   f      ej$                  d<   d$ejT                   d%Z-ej\                  dd Z/e/re/d   d   d&k(  re/d= e/re/d   d   d&k(  re/xr e/d   ev Z0e0s ed"      r? ed'      r	 ed"       n. e e- e e	d"      jM                               fz          e"d       ejb                  jd                  jf                  ro ed(      rg ed)      r	 ed(       nV ed*      r eej\                  d   d+d,       n6 e e- e e	d(      jM                               fz          e d-        e"d       eD ]  Z4	  e5e4        y# e6e7f$ r3Z8e0r& e d.e4 d/e8jr                  jt                   d0e8        n Y dZ8[8DdZ8[8ww xY w)1zQMK CLI Subcommands

We list each subcommand here explicitly because all the reliable ways of searching for modules are slow and delay startup.
    N)	find_spec)Path)run)cli__VERSION__)yesnoc                     dt        j                          j                         v rB	 t        j                  g d      } | j                  dk(  r| j
                  j                         S 	 t        j                  d      S # t        $ r Y  w xY w)Nwindows)cygpathz-wz/opt/qmkr   qmk)
platformlowerr   r   
returncodestdoutstrip	Exceptionplatformdirsuser_data_dir)results    I/home/hanthebot/chat/keyboard/qmk_firmware/lib/python/qmk/cli/__init__.py_get_default_distrib_pathr      s}    H%%'--//	WW:;F  A%}}**,, &
 %%e,,  		s   ?A< <	BBQMK_DISTRIB_DIRbinPATHQMK_PATH_PREFIXpep8ext_namingserialzusb.core
dotty_dictPIL)zpep8-namingpyserialpyusbzqmk-dotty-dictpillow)cloneconfigdoctorenvsetup)<zqmk.cli.ci.validate_aliaseszqmk.cli.buxzqmk.cli.c2jsonz
qmk.cli.cdzqmk.cli.chibios.confmigratezqmk.cli.cleanzqmk.cli.compilezqmk.cli.docszqmk.cli.doctorzqmk.cli.findzqmk.cli.flashzqmk.cli.format.czqmk.cli.format.jsonzqmk.cli.format.pythonzqmk.cli.format.textzqmk.cli.generate.apiz!qmk.cli.generate.autocorrect_dataz%qmk.cli.generate.compilation_databasez"qmk.cli.generate.community_moduleszqmk.cli.generate.config_hz qmk.cli.generate.develop_pr_listzqmk.cli.generate.dfu_headerzqmk.cli.generate.docszqmk.cli.generate.info_jsonzqmk.cli.generate.keyboard_czqmk.cli.generate.keyboard_hzqmk.cli.generate.keycodeszqmk.cli.generate.keymap_hz"qmk.cli.generate.make_dependenciesz"qmk.cli.generate.rgb_breathe_tablezqmk.cli.generate.rules_mkzqmk.cli.generate.version_hzqmk.cli.git.submodulezqmk.cli.hellozqmk.cli.import.kbfirmwarezqmk.cli.import.keyboardzqmk.cli.import.keymapzqmk.cli.infozqmk.cli.json2czqmk.cli.license_checkzqmk.cli.lintzqmk.cli.kle2jsonzqmk.cli.list.keyboardszqmk.cli.list.keymapszqmk.cli.list.layoutszqmk.cli.mass_compilezqmk.cli.migratezqmk.cli.new.keyboardzqmk.cli.new.keymapzqmk.cli.painterzqmk.cli.pytestzqmk.cli.resolve_aliaszqmk.cli.test.czqmk.cli.userspace.addzqmk.cli.userspace.compilezqmk.cli.userspace.doctorzqmk.cli.userspace.listzqmk.cli.userspace.pathzqmk.cli.userspace.removezqmk.cli.via2jsonc                    t         j                  dddg}t         j                  t         j                  k7  r_t	        j
                  t         j                  t        j                        spt        dt         j                         |j                  dd       nCt	        j
                  t         j                  t        j                        s|j                  d       t        g |d|  S )	zPerform the installation of missing requirements.

    If we detect that we are running in a virtualenv we can't write into we'll use sudo to perform the pip install.
    z-mpipinstallz@Notice: Using sudo to install modules to location owned by root:r   sudoz--user-r)sys
executableprefixbase_prefixosaccessW_OKprintinsertappend_run_cmd)requirementscommands     r   _install_depsr:   y   s    
 ~~tUI6G
zzS__$yyRWW-TVYV`V`aNN1f%YYszz277+x 1W1d1L11    c                      dt         j                  j                         v rAt        t        j
                  |       }dj                  |      }t        j                  d   d|g} t        |       S )z!Run a command in a subshell.
    r
    SHELLz-c)
r   r   r   mapshlexquotejoinr1   environr   )r9   safecmds     r   r7   r7      sV     CLL&&((ekk7+((7#::g&g6w<r;   c                 &   t        |       j                         5 }g }|j                         D ]  }|j                         j	                  dd      j	                  dd      }t        |      dk(  s|d   dk(  s|j                  d      r[d|v r|j                  d      d   }d|v r|j                  d      d   n|}|j	                  dd      }|t        v r	t        |   }t        |      r|j                  |        |cd	d	d	       S # 1 sw Y   y	xY w)
z Check if the modules in the given requirements.txt are available.

    Args:

        requirements
            The path to a requirements.txt file

    Returns a list of modules that couldn't be imported
    <=>r   #r,   -_N)r   open	readlinesr   replacelen
startswithsplitimport_namesr   r6   )r8   fdbroken_moduleslinemodule_namemodule_imports         r   _find_broken_requirementsrX      s    
l		 	 	" bLLN 	3D::<''S199#sCD4yA~aC4??43Hd{zz#q)03t$**S/!,K'//S9M l* ,[ 9]+%%k2#	3& -  s   CD)DDc                 J    t        |       }|D ]  }t        d|z          |ryy)z4Make sure we can import all the python modules.
    zCould not find module %s!TF)rX   r4   )r8   rT   modules      r   _broken_module_importsr[      s6     /|<N  4)F234 r;   c                  R    t         j                  j                         xr t        |  S )z*Wrapper to only prompt if interactive
    )r-   r   isattyr   )argss    r   _yesnor_      s      ::/5$</r;   c                 :    t        | t        j                         y)zWrapper to print to stderr
    )fileN)r4   r-   stderr)errmsgs    r   _eprintrd      s     
&szz"r;         	   zEError: Your Python is too old! Please upgrade to Python 3.9 or later.   .   zrequirements.txtzKYour MILC library is too old! Please upgrade: python3 -m pip install -U -r z
Please run `z? -m pip install -r %s` to install required python dependencies.rJ   z6Would you like to install the required Python modules?zrequirements-dev.txtz@Would you like to install the required developer Python modules?z)Would you like to disable developer mode?r$   zuser.developer=NonezDYou can also turn off developer mode: qmk config user.developer=NonezWarning: Could not import z: z, );__doc__r1   r   r   r@   r-   importlib.utilr   pathlibr   
subprocessr   milcr   r   milc.questionsr   r   rC   getr   existsstrpathseprR   safe_commandssubcommandsr:   r7   rX   r[   r_   rd   version_infoexitrQ   milc_versionintresolver8   pathdirnamer.   
python_dirrB   msg_installargvr^   safe_commandr$   user	developer
subcommand
__import__ImportErrorModuleNotFoundErrore	__class____name__ r;   r   <module>r      s   
    
 $   !  	- rzz~~&79R9TUV_u45

BRZZPVEWWBJJv 

"$56CbjjQWFXXBJJv $"=@2( F0#8 A!s//2Q6STI {  %|A!LO 4q 8*+335LYZ]^jZkYlmnI WW__S^^,
RZZ'--bjj99*bjj6H)IJBJJv s~~..mn
xx|
tAwqzS Q tAwqzS  0Q=001JK,-K3t,>'?'G'G'I#J"LLMG
zz  %;<R%STU01?@SXXa[(,ABK3t,B'C'K'K'M#N"PPQZ[G  J: ,- 0Bq{{?S?S>TTVWXVYZ[ \s   MN)NN