+
    )j6\                       ^ RI Ht ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHu H	t
 ^ RIHt ^ RIHtHt ^ RIHt ^ RIHtHt ^ RIHtHtHtHtHtHtHtHt ^ RIHt  ^ RI t ^ RI#t#]! ]$4      t%R	t&]]R
,          ]R,          3,          t'R R lt(]]R,          ]R,          3,          t)R4R R llt*]*! R
4      t+]*! R4      t,R R lt-R R lt.R R lt/R5R lt0R6R R llt1 ! R R4      t2 ! R R4      t3R7R R  llt4R! R" lt5R# R$ lt6R% R& lt7]! ^R'7      R( R) l4       t8R* R+ lt9R6R, R- llt:R. R/ lt;R8R0 R1 llt<R9R2 R3 llt=R#   ]! d    ^ RI"t  Li ; i):    )annotationsN)suppress)	lru_cachewraps)	getLogger)PathPurePath)AnyCallableIterableLiteralMappingOptionalSequenceUnion)	normalize1-0-0targetbasec                    V ^8  d   QhRRRR/# )   versionstrreturnztuple[int, int, int] )formats   ".lib/python3.14/site-packages/menuinst/utils.py__annotate__r      s     7 7S 7%9 7    c                    V P                  R4      p\        V4      ^8w  d   \        RV  24      h\        V^ ,          4      \        V^,          4      \        V^,          4      3# )zDParse SchemaVer string 'MODEL-REVISION-ADDITION' into tuple of ints.-zInvalid SchemaVer format: )splitlen
ValueErrorint)r   partss   & r   parse_schemaverr'      sS    MM#E
5zQ5gY?@@uQx=#eAh-U1X66r   usersystemc                    V ^8  d   QhRRRR/# )r   which_TargetOrBaser   r   r   )r   s   "r   r   r   '   s     -6 -6= -6 -6r   c                h   V R8H  pRpR\         P                  9   d'   \        \        4      ;_uu_ 4        ^ RIHp RRR4       V'       dl   \        P                  P                  R4      pV'       d   V# V'       d   VP                  # \        P                  P                  R\         P                  4      # \        P                  P                  R4      pV'       d   V# V'       d   VP                  # \        P                  P                  R\         P                  4      #   + '       g   i     L; i)	a  
The prefixes in menuinst need to be handled with care.

Conda installations that require superuser permissions need elevation for
the creation of shortcuts. Constructor will leave a sentinel file to signal
this. If a file `.nonadmin` is present in the 'base' environment (or root of
the installation directory if conda is not present), superuser access is not
needed.

In order to check for this file, menuinst needs to track 'base_prefix'. For
a regular 'conda' process, this should be `conda.base.context.context.root_prefix'.
However, constructor also relies on a pyinstaller-frozen conda installation,
'conda-standalone'. In these cases, 'sys.prefix' is set to temporary location
of the extracted contents of the executable -- that's NOT the base installation!

For those reasons, we handle the default prefix with 'sys.prefix' (or 'sys.base_prefix')
as a last resort. The logic is:

- If 'MENUINST_PREFIX' (or 'MENUINST_BASE_PREFIX') is an env var with a set value, use that.
- If are already using conda, we get the context object and use those values.
- If CONDA_PREFIX (or 'CONDA_ROOT_PREFIX') are available, use those
- Last resort: use sys.prefix and sys.base_prefix

This helps us pass a lot of CLI arguments back and forth.
r   Nconda)contextMENUINST_BASE_PREFIXCONDA_ROOT_PREFIXMENUINST_PREFIXCONDA_PREFIX)sysmodulesr   ImportErrorconda.base.contextr/   osenvirongetroot_prefixbase_prefixtarget_prefixprefix)r+   r   r/   r>   s   &   r   _default_prefixr?   '   s    4 F?DG#++k""2 #  67M&&&zz~~13??CCZZ^^-.F$$$::>>.#**55! #"s   D!!D1	c                    V ^8  d   QhRRRR/# )r   r>   r   r   dictr   )r   s   "r   r   r   [   s        t    r   c                   V R,          R,          pVP                  4       '       g   / #  \        VR4      ;_uu_ 4       p\        P                  ! V4      pRRR4       XP                  RR4      p \        T4      p\        \        4      pYg8  d   \        P                  R	TT\        4       T#   + '       g   i     La; i  \         d   p\        RT 24      ThRp?ii ; i  \
         d    \        P                  RTT4       Tu # i ; i)
zyRead menuinst.toml from prefix, returning empty dict if missing.

Raises an exception if the file exists but is invalid.
Menumenuinst.tomlrbNzFailed to read schema_versionr   z1menuinst.toml at %s has invalid schema_version %rzXmenuinst.toml at %s has schema_version %s, but this menuinst only understands version %s)existsopentomllibload	Exceptionr$   r:   r'   MENUINST_TOML_SCHEMA_VERSIONloggerwarning)r>   	toml_pathfdataexcr   file_vercurrent_vers   &       r   read_menuinst_tomlrU   [   s    
 /1I	A)T""a<<?D # hh'1G	"7+%&BC <(	
 K/ #" A?9+67S@A  ?	

 sF   C B.C 0C# .B>	9C >C C CC #$D
	D
c               $    V ^8  d   QhRRRRRR/# )r   r>   r   rQ   rA   r   Noner   )r   s   "r   r   r   ~   s!     	  	  	 D 	 T 	 r   c                <   VP                  R\        4       V R,          pVP                  RRR7       VR,          pVR,          p\        VR4      ;_uu_ 4       p\        P
                  ! W4       RRR4       VP                  V4       R#   + '       g   i     L#; i)	zWrite menuinst.toml atomically.rF   rC   T)parentsexist_okrD   zmenuinst.toml.tmpwbN)
setdefaultrL   mkdirrH   tomli_wdumpreplace)r>   rQ   menu_dirrO   tmp_pathrP   s   &&    r   write_menuinst_tomlrc   ~   sw    OO$&BCHNN4$N/?*I--H	h		T 
Y 
	s   BB	c                   V ^8  d   QhRR/# )r   textr   r   )r   s   "r   r   r      s     * *# *r   c                    \        RV 4      P                  RR4      P                  R4      p \        P                  ! RRV 4      P                  4       P                  4       p \        P                  ! RRV 4      # )z
Convert to ASCII, and spaces and underscores to hyphens.
Remove characters that aren't alphanumerics, or hyphens.
Convert to lowercase. Also strip leading and trailing whitespace.
NFKDasciiignorez[^\w\s-] z[_\-\s]+r!   )r   encodedecoderesubstriplower)re   s   &r   slugifyrq      s_    : VT"))'8<CCGLD66+r4(..0668D66+sD))r   c                   RpRW,          ,           p\        V 4      '       d   V P                  '       d!   V P                  P                  4       '       g   W2,           V n        V  FV  p\        WA^,           4       VP                  '       d#   VP                  P                  4       '       d   KI  W2,           Vn        KX  	  XP                  '       d!   VP                  P                  4       '       g	   W4n        R# R# V'       d=   V P                  '       d!   V P                  P                  4       '       g	   W0n        R# R# R# )zJ
adds whitespace to the tree, so that it results in a pretty printed tree
z    
N)r#   re   ro   indent_xml_treetail)elemlevelindentationbase_indentationes   &&   r   rt   rt      s     Ke11
4yyyyy		 1 1(6DIAAqy)666)7  vvvQVV\\^^%F , $)))499??+<+<(I ,=5r   c               $    V ^8  d   QhRRRRRR/# )r   parentzXMLTree.Elementtagr   re   zOptional[str]r   )r   s   "r   r   r      s!      /  = r   c                F    \         P                  ! W4      pVe   W#n        V# )zY
Add a child element of specified tag type to parent.
The new child element is returned.
)XMLTree
SubElementre   )r|   r}   re   rv   s   &&& r   add_xml_childr      s$    
 f*D	Kr   c                      ] tR t^tRt]R R l4       t]R R l4       t]R R l4       t]R R l4       t	]R	 R
 l4       t
]RR R ll4       tRtR# )WinLexc                   V ^8  d   QhRR/# )r   argsSequence[str]r   )r   s   "r   r   WinLex.__annotate__   s     ' 'm 'r   c                	,   \        V4      ^8  EdZ   V P                  V^ ,          4      '       Ed;   Rp\        ^\        V4      4       F+  pW,          P                  4       pVR8X  g
   VR8X  g   K)  Tp M	  Ve   W^,           R pV'       d   \        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   V P                  V^ ,          4      '       d   V P                  V^ ,          R4      MV^ ,          pV^V pV Uu. uF.  pV P                  V4      '       d   V P                  VR4      MTNK0  	  ppRP                  V4      p	V.VOW,          NRV	 R2N# V U
u. uF  qP                  V
4      NK  	  pp
V# u upi u up
i )	r   Nz/Cz/Kc              3  ,   "   T F
  pR V9   x  K  	  R# 5i) Nr   ).0entrys   & r   	<genexpr>$WinLex.quote_args.<locals>.<genexpr>   s     ?$u$s   TF"r   )	r#   _is_cmd_exerangeupperany_needs_quotes_for_cmd
ensure_padjoinquote_string)clsr   switch_indexindexaru   cmd0	pre_flags
tail_partstail_strargs   &&         r   
quote_argsWinLex.quote_args   s    t9q=S__T!W55Lq#d),K%%'9T	#(L	 - '1,./CC?$?CCC?$??? 44T!W== tAw4!!W  !%Q| 4I "&"!%A 473L3LQ3O3O3/UVV!%  "  #xx
3H R9Rd.@RAhZq/RR 266#  %6" 7s   F-F/Fc                    V ^8  d   QhRRRR/# r   sr   r   boolr   )r   s   "r   r   r      s     2 2C 2D 2r   c                    VP                  R4      pVP                  4       R8X  d   R# \        V4      P                  P                  4       pVR8H  ;'       g    VR8H  # )z
Return True if input refers to cmd.exe or %COMSPEC%. Here, 'refers' implies variants of
cmd, cmd.exe, <some path>/cmd and accounting for quoted input.
r   z	%COMSPEC%TCMDzCMD.EXE)ro   r   r	   name)r   r   tr   s   &&  r   r   WinLex._is_cmd_exe   sS     GGCL779# {%%'u}11	 11r   c                   V ^8  d   QhRR/# )r   r   r   r   )r   s   "r   r   r     s     & &S &r   c                   VR8X  d   R# \        V4      ^8  d"   V^ ,          VR	,          u;8X  d
   R8X  d    V#  V^ ,          R
9   d   V# V P                  V4      '       d   V# \        V4      ^8  d2   V^ ,          R8X  d$   VR,          P                  4       '       d   RV R2# RV9   d   RV9   g   RV9   d   RV R2# RV9   d   RV R2# V# )a  
Quote given input if necessary.
This is based on the following rules:
* Preserve already-quoted input..
* Quote args with spaces
* Quote path-like input with variables, for example %FOO%\foo.exe.
* Quote positional args such as %1, %2, ..., %n where n is a positive integer.
* Don't auto-quote shell metacharacters (>, <, |, &).
* Don't auto-quote just because of '%' (it changes observable output).
rj   z""r   r   %:   NN/\)r!   r   )r#   _has_shell_metaisdigitr   r   s   &&r   r   WinLex.quote_string
  s     7 q6Q;1Q41R5/C/H 0 Q4:H q!!H q6Q;1Q43;1R5==??qc8O !8TQYqc8O!8qc8Or   c                    V ^8  d   QhRRRR/# )r   r   r   r   r   r   )r   s   "r   r   r   4  s     6 6 6 6r   c                   a \         ;QJ d)    V3R lV P                   4       F  '       g   K   R# 	  R# ! V3R lV P                   4       4      # )zL
Detect shell metacharacters that must remain unquoted to preserve meaning.
c              3  ,   <"   T F	  qS9   x  K  	  R # 5iNr   )r   chr   s   & r   r   )WinLex._has_shell_meta.<locals>.<genexpr>8  s     5_r7_s   TF)r   _META_CHARS)r   r   s   &fr   r   WinLex._has_shell_meta3  s6    
 s5S__5ss5s5s5S__555r   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   r   ;  s      c d r   c                    RV9   # )z&
Return True if input contains space.
r   r   r   s   &&r   r   WinLex._needs_quotes_for_cmd:  s    
 axr   c               $    V ^8  d   QhRRRRRR/# )r   r   r   padr   r   )r   s   "r   r   r   B  s!     / /c / /c /r   c                n    V'       g   V# V^ ,          VR,          u;8X  d
   V8X  d    V#  V: V: V: 2# )z
Pad the input set via 'name' with the string set via keyword-argument 'pad'.
If pad='"', then padding is only added if the input contains a space or
a percentage sign.

Examples:
    >>> ensure_pad('conda')
    '_conda_'

r   r   )r   r   r   s   &&&r   r   WinLex.ensure_padA  s:     K7d2h%#%K &  #D#..r   r   N)><|&)_)__name__
__module____qualname____firstlineno__r   classmethodr   r   r   r   r   r   __static_attributes__r   r   r   r   r      s     'K' 'R 2 2 & &P 6 6   / /r   r   c                  B    ] tR tRt]R R l4       t]R R l4       tRtR# )UnixLexiU  c                    V ^8  d   QhRRRR/# )r   r   r   r   r   )r   s   "r   r   UnixLex.__annotate__W  s     3 3m 3 3r   c                	L    V Uu. uF  q P                  V4      NK  	  up# u upi r   )r   )r   r   r   s   && r   r   UnixLex.quote_argsV  s#    -12T  #T222s   !c                    V ^8  d   QhRRRR/# )r   r   r   r   r   )r   s   "r   r   r   [  s      S S r   c                	    \         P                  ! V4      pVP                  R 4      '       d   RV9  d
   RV^R  R2pV# )'r   r   )shlexquote
startswith)r   r   quoteds   && r   r   UnixLex.quote_stringZ  s@    QS!!c&7"a(Fr   r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   U  s(    3 3  r   r   c                    V ^8  d   QhRRRR/# )r   pathstr | os.PathLike
missing_okr   r   )r   s   "r   r   r   b  s      "  r   c                z     \         P                  ! V 4       R #   \         d   pT'       g   Th R p?R # R p?ii ; ir   )r8   unlinkFileNotFoundError)r   r   rR   s   && r   r   r   b  s/    
		$ I s    :
5:c                    V ^8  d   QhRRRR/# )r   r   r   r   r   r   )r   s   "r   r   r   j  s        %  $  r   c                T    \        \        4      P                  pVR ,          V ,          # )rQ   )r   __file__r|   )r   heres   & r   	data_pathr   j  s     >  D&=4r   c               $    V ^8  d   QhRRRRRR/# )r   mappingzMapping[str, Any]updating_mappingszIterable[Mapping]r   r   )r   s   "r   r   r   o  s$     # ##4E##r   c                   V P                  4       pV Fn  pVP                  4        FW  w  rEWB9   dI   \        W$,          \        4      '       d-   \        V\        4      '       d   \	        W$,          V4      W$&   KS  WRV&   KY  	  Kp  	  V# r   )copyitems
isinstancerA   deep_update)r   r   updated_mappingupdating_mappingkvs   &*    r   r   r   o  st    0 llnO-$**,DA$1488q$''%01CQ%G"%&" - . r   c               $    V ^8  d   QhRRRRRR/# )r   r=   zos.PathLiker<   r   r   r   )r   s   "r   r   r     s&     +G +G{ +G +G +Gr   c                   \        4       '       d   R# \        V R4      P                  4       '       d   R#  \        V R4      P                  4        R#   \         d"   p\
        P                  RYR7        Rp?MRp?ii ; iY8X  d   R# \        TR4      P                  4       '       d   R# \        P                  R8X  d   R# \        P                  R8X  dN    \        TR4      P                  4        R#   \         d#   p\
        P                  RYR7        Rp?R# Rp?ii ; i\        R	\        P                   24      h)
z=
Checks if the current installation needs admin permissions.
F	.nonadminz%Attempt to write %s/.nonadmin failed.exc_infoNTntposixUnsupported operating system: )
user_is_adminr   rG   touchrK   rM   debugr8   r   RuntimeError)r=   r<   rR   s   && r   needs_adminr    s    M;'..00 []K(..0 [<mZZ[ #
 K%,,..	ww$	G		k*002
 	  	LL@-L^	 ;BGG9EFFs/   A A>A99A>C4 4D!?DD!)maxsizec                   V ^8  d   QhRR/# )r   r   r   r   )r   s   "r   r   r     s     	G 	Gt 	Gr   c                     \         P                  R 8X  d   ^RIHp  \	        V ! 4       4      # \         P                  R8X  d   \         P
                  ! 4       ^ 8H  # \        R\         P                   24      h)r   isUserAdminr   r   )r8   r   platforms.win_utils.win_elevater  r   getuidr  r  s    r   r   r     sQ    	ww$@KM""	G	yy{a;BGG9EFFr   c                    V ^8  d   QhRRRR/# )r   argvr   r   r%   r   )r   s   "r   r   r     s     G G} G Gr   c                    \         P                  R8X  d   ^RIHp V! V 4      # \         P                  R8X  d   \        P
                  ! R.V O4      # \        R\         P                   24      h)z=
Rerun this command in a new process with admin permissions.
r   )
runAsAdminr   sudor   )r8   r   r	  r  
subprocesscallr  )r  r  s   & r   run_as_adminr    sU     
ww$?$	G	//;BGG9EFFr   c                    V ^8  d   QhRRRR/# )r   r<   Optional[os.PathLike]r   r   r   )r   s   "r   r   r     s      #8 M r   c                J   \        T ;'       g    \        4      p \        \        R R4      '       dd   \        P
                  R8X  d   V R,          pMV R,          R,          pVP                  4       '       d   \        V4      3# \        P                  R3# \        P                  3# )frozenFr   z
python.exebinpython)	r   DEFAULT_BASE_PREFIXgetattrr4   r8   r   is_filer   
executable)r<   base_prefix_pythons   & r   python_executabler    s    {99&9:K sHe$$77d?!,|!;!,u!4x!? %%''*+-- ))NNr   c                    V ^8  d   QhRRRR/# )r   funcr   r   r   )r   s   "r   r   r     s     _ _H _ _r   c                B   a  \        S 4      RRRR/R V 3R lll4       pV# )a  
Multiplatform decorator to run a function as a superuser, if needed.

This depends on the presence of a `.nonadmin` file in the installation root.
This is usually planted by the `constructor` installer if the installation
process didn't need superuser permissions.

In the absence of this file, we assume that we will need superuser
permissions, so we try to run the decorated function as a superuser.
If that fails (the user rejects the request or doesn't have permissions
to accept it), we'll try to run it as a normal user.

NOTE: Only functions that return None should be decorated. The function
will run in a separate process, so we won't be able to capture the return
value anyway.
r=   Nr<   c                    V ^8  d   QhRRRR/# )r   r=   zos.PathLike | Noner<   r   )r   s   "r   r   'elevate_as_needed.<locals>.__annotate__  s"     J
 J
)J
 (J
r   c                  < VP                  R R4       T ;'       g    \        p T;'       g    \        p\        W4      '       EdY   \        P                  P                  R4      R8w  Ed4    SP                  R8X  d&   RSP                   R\         RSP                   R2pMR	SP                   R
SP                   R2pRP                  \        P                  P                  4        UUu. uF'  w  rVVP                  R4      '       g   K  RV RV R2NK)  	  upp4      p. \        4       ORNRV RV SP                   RV: RV : RV: RV: R2Np\        P                  RV4       \        V4      p	\        P                  P                  RR4       V	^ 8X  d   R# My\%        4       '       dj   \'        V R4      P)                  4       ;'       g    \'        VR4      P)                  4       pS! TRT RTR V'       d   \        P*                  R8X  d   RMR/VB # S! VRV RVR R/VB # u uppi   \          d"   p
\        P#                  RT
R7        Rp
?
L;Rp
?
ii ; i) _modeN_MENUINST_RECURSING1__main__zimport runpy;z = runpy.run_path('z')['z'];zfrom z import ;zos.environ.setdefault('z', 'z')z-cz<import os;os.environ.setdefault('_MENUINST_RECURSING', '1');z(*z,target_prefix=z,base_prefix=z,_mode='system',**)zElevating command: %sz,Elevation failed! Falling back to user mode.r   r   r=   r<   r   r(   r)   )CONDA_CONSTRUCTOR_	MENUINST_)popr  r  r8   r9   r:   r   r   r   r   r   r   r  rM   r  r  rK   rN   r   r   r  r   )r=   r<   r   kwargsimport_funcr   r   env_varscmdreturn_coderR   nonadmin_existsr   s   $$*,        r   wrapper_elevate*elevate_as_needed.<locals>.wrapper_elevate  s    	

7D!%<<)<!88%833

45<&??j0'==/)<XJ G!]]O30   %*$//):(4==/QR"SK88 ')jj&6&6&8&8FQ<<(OP ?1!D2>&8&(Ij"m}}o &x  %%2$5 6##./ 2

 4c:*3/ 

4d;!# $__ ]K088: < <[199;   	+' !0BGGtOf
    	
'
#
 

 
 	
W.  ]MX[\\]s2   ,A?H+ +H%
H%
AH+ %H+ +I6II)r   )r   r5  s   f r   elevate_as_neededr7    s@    $ 4[J
,0J
 +/J
 J
 J
X r   c               $    V ^8  d   QhRRRRRR/# )r   r=   r  r<   r%  _UserOrSystemr   )r   s   "r   r   r   W  s&      (& r   c           
     ~   \         P                  R 8X  d9   V'       d"   \         P                  P                  VR4      pMRp\	        VR4      pM\
        P                  p\        R\        4       R\         P                  P                  RR4      RVVR7       \         P                  R 8X  d   VP                  4        R	# R	# )
r   z_test_output.txtr   zuser_is_admin():zenv_var:MENUINST_TESTzN/Az_mode:)fileN)r8   r   r   r   rH   r4   stdoutprintr   r9   r:   close)r=   r<   r%  outputouts   &&&  r   _test_elevationrB  W  s    
 
ww$WW\\+/ABF'F63jj	


. 
ww$		 r   c                   V ^8  d   QhRR/# )r   r   zsubprocess.CompletedProcessr   )r   s   "r   r   r   q  s      9T r   c                R   \         P                  ! V 3R RRR/VB pV'       dl   \        P                  RVP                  VP
                  4       \        P                  RVP                  4       \        P                  RVP                  4       V'       d   VP                  4        V# )capture_outputTre   z%s returned %dz
stdout:
%sz
stderr:
%s)	r  runrM   r  r   
returncoder=  stderrcheck_returncode)r   checklogr/  processs   &&&, r   
logged_runrM  q  su    nnTL$LTLVLG
%w||W5G5GH]GNN3]GNN3  "Nr   )r   )r   r   )F)NNr(   )FT)>
__future__r   r8   rm   r   r  r4   xml.etree.ElementTreeetreeElementTreer   
contextlibr   	functoolsr   r   loggingr   pathlibr   r	   typingr
   r   r   r   r   r   r   r   unicodedatar   rI   r6   tomlir^   r   rM   rL   r,   r'   r9  r?   DEFAULT_PREFIXr  rU   rc   rq   rt   r   r   r   r   r   r   r  r   r  r  r7  rB  rM  r   r   r   <module>rZ     s@   " 	 	   
 ' '  &  " W W W ! 	8	& gh'897 gfowx'889-6` !*%f-  F	 *D)(G/ G/T
 
 
#L+G\ 1	G 	GG._D4   s   E EE