
    KuiU                    ^   d Z ddlmZ ddl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mZ ddlm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 ddlm Z m!Z! ddl"m#Z#m$Z$m%Z%m&Z& ddl'm(Z(m)Z)m*Z* ddl+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8m9Z9 er+ddl:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZA ddlBmCZC  G d ded      ZD ej                  eF      ZGd.dZH G d  d!      ZId/d"ZJd0d#ZK G d$ d%e      ZL G d& d'      ZM G d( d)      ZN G d* d+      ZO G d, d-eO      ZPy)1z:Build Environment used for isolation during sdist building    )annotationsN)OrderedDict)IterableSequence)AbstractContextManager)nullcontext)StringIO)TracebackType)TYPE_CHECKINGProtocol	TypedDict)Version)__file__)open_rich_spinneropen_spinner)BuildDependencyInstallErrorDiagnosticPipErrorInstallWheelBuildErrorPipError)get_platlibget_purelib
get_scheme)get_default_environmentget_environment)
deprecated)VERBOSEcapture_logging)get_requirement)call_subprocess)TempDirectorytempdir_kinds)
WheelCache)PackageFinder)BuildTracker)InstallRequirement)BaseResolverc                      e Zd ZU ded<   y)ExtraEnvironzdict[str, str]extra_environN)__name__
__module____qualname____annotations__     a/root/.openclaw/workspace/chatterbox_venv/lib/python3.12/site-packages/pip/_internal/build_env.pyr(   r(   ,   s    %%r/   r(   F)totalc                    | |k7  r| |fS | fS Nr.   )abs     r0   _dedupr6   3   s    !VAq6%!%r/   c                      e Zd ZddZy)_Prefixc                    || _         d| _        t        d|      }|j                  | _        t        |j                  |j                        | _        y )NF )prefix)	pathsetupr   scriptsbin_dirr6   purelibplatliblib_dirs)selfr<   schemes      r0   __init__z_Prefix.__init__8   s=    	
Bt,~~v~~v~~>r/   N)r<   strreturnNone)r*   r+   r,   rE   r.   r/   r0   r8   r8   7   s    ?r/   r8   c                     t        j                  t              j                         j                  } | j                         st        |       S t        j                  | dz        S )zGet a file to pass to a Python executable, to run the currently-running pip.

    This is used to run a pip subprocess, for installing requirements into the build
    environment.
    z__pip-runner__.py)	pathlibPathpip_locationresolveparentis_dirrF   osfsdecode)sources    r0   get_runnable_piprS   @   sK     \\,'//188F==? 6{;;v 3344r/   c                     t        t        d      rt        j                         } nt               t	               g} | D ch c]!  }t
        j                  j                  |      # c}S c c}w )zGet system site packages

    Usually from site.getsitepackages,
    but fallback on `get_purelib()/get_platlib()` if unavailable
    (e.g. in a virtualenv created by virtualenv<20)

    Returns normalized set of strings.
    getsitepackages)hasattrsiterU   r   r   rP   r<   normcase)system_sitesr<   s     r0   _get_system_sitepackagesrZ   P   sP     t&'++- ${}5/;<tBGGT"<<<s   &A'c                  ,    e Zd ZdZ	 	 	 	 	 	 	 	 	 	 ddZy)BuildEnvironmentInstallerz]
    Interface for installing build dependencies into an isolated build
    environment.
    c                    y r3   r.   )rC   requirementsr;   kindfor_reqs        r0   installz!BuildEnvironmentInstaller.installj   s     r/   N
r^   Iterable[str]r;   r8   r_   rF   r`   InstallRequirement | NonerG   rH   )r*   r+   r,   __doc__ra   r.   r/   r0   r\   r\   d   s<    
# 
  + 
r/   r\   c                  P    e Zd ZdZ	 	 d	 	 	 	 	 	 	 ddZddZ	 	 	 	 	 	 	 	 	 	 d	dZy)
#SubprocessBuildEnvironmentInstallerzD
    Install build dependencies by calling pip in a subprocess.
    Nc                6    || _         |xs g | _        || _        y r3   )finder_build_constraints!_build_constraint_feature_enabled)rC   ri   build_constraints build_constraint_feature_enableds       r0   rE   z,SubprocessBuildEnvironmentInstaller.__init__y   s      "3"9r1Q.r/   c                    | j                   s| j                  ryt        j                  j	                  d      }|r|j                         syt        dddd       y)z
        Check for deprecation warning: PIP_CONSTRAINT affecting build environments.

        This warns when build-constraint feature is NOT enabled and PIP_CONSTRAINT
        is not empty.
        NPIP_CONSTRAINTzGSetting PIP_CONSTRAINT will not affect build constraints in the future,zto specify build constraints using --build-constraint or PIP_BUILD_CONSTRAINT. To disable this warning without any build constraints set --use-feature=build-constraint or PIP_USE_FEATURE="build-constraint"z26.2)reasonreplacementgone_inissue)rk   rj   rP   environgetstripr   )rC   pip_constraints     r0   _deprecation_constraint_checkzASubprocessBuildEnvironmentInstaller._deprecation_constraint_check   sV     11T5L5L(89^%9%9%;35
 	
r/   c                  | j                          | j                  }t        j                  t	               dddd|j
                  ddddd	g}t        j                         t        j                  k  r|j                  d
       n,t        j                         t        k  r|j                  d       dD ][  }t        |j                  |      }|j                  d|j                  dd      z   dj!                  t#        |xs dh            f       ] |j$                  H|j$                  j'                         D ]+  \  }	}
|j                  d|	j                  dd      z   |
f       - |j(                  }|r4|j                  d|d   g       |dd  D ]  }|j                  d|g        n|j                  d       |j*                  D ]  }|j                  d|g        |j,                  r|j                  d|j,                  g       |j.                  D ]  }|j                  d|g        |j0                  r|j                  d|j0                  g       |j2                  r|j                  d|j2                  g       |j4                  r|j                  d       | j6                  r|j                  ddg       | j8                  r7| j8                  D ](  }|j                  d|g       |j                  d |g       * i }| j6                  r| j8                  sd!d"d#ii}|j:                  r+|j                  d$|j:                  j=                         g       |j                  d       |j                  |       |r|j>                  rd%|j>                   nd	}tA        d&|       5 }tC        |fd'| | |d(| d d d        y # 1 sw Y   y xY w))Nra   z--ignore-installedz	--no-userz--prefixz--no-warn-script-locationz--disable-pip-version-checkz--no-compilez--targetr:   z-vvz-v)	no_binaryonly_binaryz--_-,z:none:z-ir      z--extra-index-urlz
--no-indexz--find-linksz--proxyz--trusted-hostz--certz--client-certz--prefer-binaryz--use-featurezbuild-constraintz--constraintz--build-constraintr)    _PIP_IN_BUILD_IGNORE_CONSTRAINTS1z--uploaded-prior-toz for Installing zinstalling )command_descspinner)"rx   ri   sys
executablerS   r<   loggergetEffectiveLevelloggingDEBUGappendr   getattrformat_controlextendreplacejoinsortedrelease_controlget_ordered_args
index_urls
find_linksproxytrusted_hostscustom_certclient_certprefer_binaryrk   rj   uploaded_prior_to	isoformatnamer   r   )rC   r^   r;   r_   r`   ri   argsr   formats	attr_namevaluer   extra_indexlinkhostconstraint_filer)   identify_requirementr   s                      r0   ra   z+SubprocessBuildEnvironmentInstaller.install   s    	**,NN KK')  #
& ##%6KK%%'72KK: 	Nf33^DGKK>11#s;;HHVG$9z:;	 !!- %+$:$:$K$K$M I 	5TI$5$5c3$??GHI &&
KKz!}-.)!"~ @0+>?@ KK%%% 	0DKK./	0 <<KKFLL12(( 	2DKK)401	2KK6#5#567KK&*<*<=>KK)* 11KK*<=>"" $(#:#: E^_=>1?CDE ')11$:Q:Q -/QSV.WXM##KK.0H0H0R0R0TUVDL! '.',,eGLL>"B 	 Kv./ 	7*4&1E0FG  		 	 	s   N;;O)NF)ri   r#   rl   zlist[str] | Nonerm   boolrG   rH   rG   rH   rb   )r*   r+   r,   re   rE   rx   ra   r.   r/   r0   rg   rg   t   s     /316	RR ,R +/	R
 
R
:g#g g
 g +g 
gr/   rg   c                  b    e Zd ZdZddd	 	 	 	 	 	 	 	 	 	 	 d
dZ	 	 	 	 	 	 	 	 	 	 ddZddZddZy	)"InprocessBuildEnvironmentInstallera  
    Build dependency installer that runs in the same pip process.

    This contains a stripped down version of the install command with
    only the logic necessary for installing build dependencies. The
    finder, session, build tracker, and wheel cache are reused, but new
    instances of everything else are created as needed.

    Options are inherited from the parent install command unless
    they don't make sense for build dependencies (in which case, they
    are hard-coded, see comments below).
    r.   r   )rl   	verbosityc                   ddl m} || _        || _        || _        d| _        t        dd      } || ||j                  j                  |j                  ||dd ddddddd	      | _
        y )
Nr   )RequirementPreparerzbuild-env-installTr_   globally_managedr:   Foff)build_isolation_installerri   session	build_dirbuild_trackerr   src_dirdownload_dirbuild_isolationcheck_build_depsprogress_barrequire_hashesuse_user_site
lazy_wheellegacy_resolver) pip._internal.operations.preparer   _finderrj   _wheel_cache_levelr    _link_collectorr   r<   	_preparer)rC   ri   r   wheel_cacherl   r   r   r   s           r0   rE   z+InprocessBuildEnvironmentInstaller.__init__  s~     	I"3'!':TR	,&***22nn' " !!)
r/   c               "   t         j                  t               xr | j                  dk(  }|rt	               }t        d|       }n3t        t                     t               }}t         j                  d|       	 | xj                  dz  c_        |5  |5 }| j                  ||       ddd       ddd       | xj                  dz  c_        y# 1 sw Y   'xY w# 1 sw Y   +xY w# t        $ ry}	t         j                  t        j                  j                                      t         j                  d|	ddi	       t         j                  d
       t        |||	d      d}	~	wt         $ r}	t        j                  j                               j#                         }
|s>d}
t%        |	t&              rt         j                  d|	       nt         j)                  d       t        |||	|
      d}	~	ww xY w# | xj                  dz  c_        w xY w)z@Install entrypoint. Manages output capturing and error handling.r   r   zInstalling %s ...r   Nz%srichT)extrar:   )cause	log_lineszpip crashed unexpectedly)r   isEnabledForr   r   r   r   r   r	   info_install_implr   textwrapdedentgetvalueerrorr   	Exception
splitlines
isinstancer   	exception)rC   r^   r;   r_   r`   capture_logscapture_ctxr   streamexclogss              r0   ra   z*InprocessBuildEnvironmentInstaller.install@  s    "..w77LDKK1<L 5D4EK,=D6>R,SG $/xz#:KMKKK+T2	KK1K 9+ 9""<89 98 KK1K99 9 9 9 " 	 KK(9:;LLs64.L9KKO-SD   	%-__V__5F%G%R%R%TD c8,LLs+$$%?@-SD 	 KK1Ksb   ;C& CC(C0C& C	CC#C& &	G4/A4E##G4/B G//G44G7 7Hc           
        ddl m} ddlm} ddlm} ddlm} |D cg c]  } ||d       }}|j                  | j                         | j                         }	|	j                  |d      }
| j                  j                  |
j                  j                                |
j                   D cg c]  }|j"                  r| }} ||| j$                  d	      \  }}|rt'        |       ||	j)                  |
      |j*                  d
d
dddd      }t-        t/        |j0                              } |||      x}rt2        j5                  |       y
y
c c}w c c}w )z$Core build dependency install logic.r   )installed_packages_summary)install_given_reqs)install_req_from_line)buildT)user_supplied)check_supported_wheels)verifyNFr   )r;   roothomewarn_script_locationr   	pycompiler   )pip._internal.commands.installr   pip._internal.reqr   pip._internal.req.constructorsr   pip._internal.wheel_builderr   r   rj   _make_resolverrM   r    prepare_linked_requirements_morer^   valuesrequirements_to_installis_wheelr   r   get_installation_orderr<   r   listrB   r   r   )rC   r^   r;   r   r   r   r   reqireqsresolverresolved_setrreqs_to_buildr|   build_failures	installedenvsummarys                     r0   r   z0InprocessBuildEnvironmentInstaller._install_implt  sJ   M8H5KWXC&s$?XXT,,-&&(''d'K77%%,,.	

 $;;
1::A
 
 "-1B1B4P>(88&++L9;;!& 
	 d6??340C@@7@KK  A? Y
s   E/EEc                |    ddl m} ddlm}  ||| j                  | j
                  | j                  ddddddd      S )	z'Create a new resolver for one time use.r   )install_req_from_req_string)ResolverFTzto-satisfy-onlyN)make_install_reqpreparerri   r   ignore_requires_pythonr   ignore_dependenciesignore_installedforce_reinstallupgrade_strategypy_version_info)r   r   ,pip._internal.resolution.resolvelib.resolverr   r   r   r   )rC   r   r   s      r0   r   z1InprocessBuildEnvironmentInstaller._make_resolver  sG     	OI8^^<<))#( %!!. 
 	
r/   N)ri   r#   r   r$   r   r"   rl   zSequence[InstallRequirement]r   intrG   rH   rb   )r^   rc   r;   r8   rG   rH   )rG   r&   )r*   r+   r,   re   rE   ra   r   r   r.   r/   r0   r   r   
  s    & ;=&
 &
 $	&

  &
 8&
 &
 
&
P2#2 2
 2 +2 
2h'!R
r/   r   c                  h    e Zd ZdZd	dZd
dZ	 	 	 	 	 	 	 	 ddZ	 	 	 	 ddZdd	 	 	 	 	 	 	 	 	 ddZy)BuildEnvironmentzACreates and manages an isolated environment to install build depsc                   || _         t        t        j                  d      t	        fddD              | _        g | _        g | _        t        t        | j
                  j                                     D ]L  }| j                  j                  |j                         | j                  j                  |j                         N t               }t         j"                  j%                  j"                  d      | _        t         j"                  j)                  | j&                        st!        j*                  | j&                         t-        t         j"                  j%                  | j&                  d      dd	      5 }|j/                  t1        j2                  d
      j5                  || j                               d d d        y # 1 sw Y   y xY w)NTr   c              3     K   | ]9  }|t        t        j                  j                  j                  |            f ; y wr3   )r8   rP   r<   r   ).0r   temp_dirs     r0   	<genexpr>z,BuildEnvironment.__init__.<locals>.<genexpr>  s6      %
 7277<<t<=>%
s   ?A)normaloverlayrW   zsitecustomize.pywzutf-8)encodinga  
                import os, site, sys

                # First, drop system-sites related paths.
                original_sys_path = sys.path[:]
                known_paths = set()
                for path in {system_sites!r}:
                    site.addsitedir(path, known_paths=known_paths)
                system_paths = set(
                    os.path.normcase(path)
                    for path in sys.path[len(original_sys_path):]
                )
                original_sys_path = [
                    path for path in original_sys_path
                    if os.path.normcase(path) not in system_paths
                ]
                sys.path = original_sys_path

                # Second, add lib directories.
                # ensuring .pth file are processed.
                for path in {lib_dirs!r}:
                    assert not path in sys.path
                    site.addsitedir(path)
                )rY   rB   )	installerr    r!   	BUILD_ENVr   	_prefixes	_bin_dirs	_lib_dirsreversedr   r   r   r?   r   rB   rZ   rP   r<   r   	_site_direxistsmkdiropenwriter   r   format)rC   r  r;   rY   fpr  s        @r0   rE   zBuildEnvironment.__init__  sL   " m&=&=PTU$ %
-%
 

 %'$&tDNN$9$9$;<= 	3FNN!!&..1NN!!&//2	3 01hmmV<ww~~dnn-HHT^^$GGLL);<cG
 	HH2 &lT^^&L5	 	 	s   =A GGc                   dD ci c]#  }|t         j                  j                  |d       % c}| _        | j                  d d  }| j                  d   }|r.|j                  |j                  t         j                               | j                  g}t         j                  j                  t         j                  j                  |      dt         j                  j                  |      d       y c c}w )N)PATHPYTHONNOUSERSITE
PYTHONPATHr!  r   )rP   rt   ru   	_save_envr  r   splitpathsepr  updater   )rC   r   r<   old_path
pythonpaths        r0   	__enter__zBuildEnvironment.__enter__  s     C
 "**..t,,

 ~~a >>&)KKrzz23nn%





-$' jjooj9	

s   (C.c                    | j                   j                         D ];  \  }}|!t        j                  j	                  |d        )|t        j                  |<   = y r3   )r$  itemsrP   rt   pop)rC   exc_typeexc_valexc_tbvarname	old_values         r0   __exit__zBuildEnvironment.__exit__  sK     #'.."6"6"8 	0GY 

w-&/

7#		0r/   c                |   t               }t               }|r"t        | d      rt        | j                        n	t	               }|D ]  }t        |      }|j                  |j                  j                  ddi      s8|j                  |j                        }|s|j                  |       gt        |j                  t              r|j                   d|j                   }n|j                   d|j                   }|j                  j                  |j                  d      r|j                  ||f        ||fS )zReturn 2 sets:
        - conflicting requirements: set of (installed, wanted) reqs tuples
        - missing requirements: set of reqs
        r  r   r:   z==z===T)prereleases)setrV   r   r  r   r   markerevaluateget_distributionr   addr   versionr   	specifiercontains)	rC   reqsmissingconflictingr   req_strr   distinstalled_req_strs	            r0   check_requirementsz#BuildEnvironment.check_requirements  s    %e 4-  /,. 
   B%g. ::)#**2E2EwPRm2T++CHH5KK(dllG4+.88*Bt||n(E%+.88*C~(F%}}--dll-MOO%6$@AB" G##r/   Nr`   c                   | j                   |   }|j                  rJ d|_        |sy | j                  j                  ||||       y )NT)r_   r`   )r  r=   r  ra   )rC   r^   prefix_as_stringr_   r`   r;   s         r0   install_requirementsz%BuildEnvironment.install_requirements2  sH      01<<|V$Pr/   )r  r\   rG   rH   r   r.  ztype[BaseException] | Noner/  zBaseException | Noner0  zTracebackType | NonerG   rH   )r>  rc   rG   z%tuple[set[tuple[str, str]], set[str]]
r^   rc   rG  rF   r_   rF   r`   rd   rG   rH   )	r*   r+   r,   re   rE   r*  r3  rD  rH  r.   r/   r0   r	  r	    s    K5n
*
0,
0 &
0 %	
0
 

0 $! $	. $P .2Q#Q Q
 Q +Q 
Qr/   r	  c                  `    e Zd ZdZd	dZd	dZ	 	 	 	 	 	 	 	 d
dZd	dZdd	 	 	 	 	 	 	 	 	 ddZy)NoOpBuildEnvironmentz0A no-op drop-in replacement for BuildEnvironmentc                     y r3   r.   rC   s    r0   rE   zNoOpBuildEnvironment.__init__E      r/   c                     y r3   r.   rN  s    r0   r*  zNoOpBuildEnvironment.__enter__H  rO  r/   c                     y r3   r.   )rC   r.  r/  r0  s       r0   r3  zNoOpBuildEnvironment.__exit__K  s     	r/   c                     y r3   r.   rN  s    r0   cleanupzNoOpBuildEnvironment.cleanupS  rO  r/   NrE  c                   t               r3   )NotImplementedError)rC   r^   rG  r_   r`   s        r0   rH  z)NoOpBuildEnvironment.install_requirementsV  s     "##r/   r   rI  rJ  )	r*   r+   r,   re   rE   r*  r3  rS  rH  r.   r/   r0   rL  rL  B  sy    :, & %	
 
 .2$#$ $
 $ +$ 
$r/   rL  )r4   rF   r5   rF   rG   ztuple[str] | tuple[str, str])rG   rF   )rG   zset[str])Qre   
__future__r   r   rP   rJ   rW   r   r   collectionsr   collections.abcr   r   
contextlibr   ContextManagerr   ior	   typesr
   typingr   r   r   pip._vendor.packaging.versionr   pipr   rL   pip._internal.cli.spinnersr   r   pip._internal.exceptionsr   r   r   r   pip._internal.locationsr   r   r   pip._internal.metadatar   r   pip._internal.utils.deprecationr   pip._internal.utils.loggingr   r   pip._internal.utils.packagingr   pip._internal.utils.subprocessr   pip._internal.utils.temp_dirr    r!   pip._internal.cacher"   "pip._internal.index.package_finderr#   ,pip._internal.operations.build.build_trackerr$   pip._internal.req.req_installr%   pip._internal.resolution.baser&   r(   	getLoggerr*   r   r6   r8   rS   rZ   r\   rg   r   r	  rL  r.   r/   r0   <module>ro     s    @ "  	   
  # . ? "   5 5 1 ( F  I H K 6 @ 9 : E.@I@:&y & 
		8	$&? ?5 =(  S Slh
 h
VJQ JQZ$+ $r/   