
    wBfI)                        d 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
 e
rddlmZmZmZ dd	lmZ dd
ZddZddZy)zhCLI implementation for `conda search`.

Query channels for packages matching the provided package spec.
    )annotations)SUPPRESS)defaultdict)datetimetimezone)TYPE_CHECKING)ArgumentParser	Namespace_SubParsersAction   PackageRecordc                   ddl m} ddlm} ddlm}m}m}m} d} |d| d      }	 |d	      }
 | j                  	 d(||	|
d
|}|j                  ddd       |j                  dddd       |j                  ddddd|       |j                  ddd       |j                  dddt               |j                  ddt               |j                  dd dt               |j                  d!dt                ||       |j                  d"d#dt               |j                  d$dt               |j                  d%dt                ||        ||        ||       |j                  d&'       |S ))Nr   )dals)NULL   )add_parser_channelsadd_parser_jsonadd_parser_knownadd_parser_networkingzRSearch for packages and display associated information using the MatchSpec format.z	
        zD

        MatchSpec is a query language for conda packages.
        a  
        Examples:

        Search for a specific package named 'scikit-learn'::

            conda search scikit-learn

        Search for packages containing 'scikit' in the package name::

            conda search *scikit*

        Note that your shell may expand '*' before handing the command over to conda.
        Therefore, it is sometimes necessary to use single or double quotes around the query::

            conda search '*scikit'
            conda search "*scikit*"

        Search for packages for 64-bit Linux (by default, packages for your current
        platform are shown)::

            conda search numpy[subdir=linux-64]

        Search for a specific version of a package::

            conda search 'numpy>=1.12'

        Search for a package on a specific channel::

            conda search conda-forge::numpy
            conda search 'numpy[channel=conda-forge, subdir=osx-64]'
        )helpdescriptionepilogz--envs
store_truezSearch all of the current user's environments. If run as Administrator (on Windows) or UID 0 (on unix), search all known environments on the system.)actionr   z-iz--infoz0Provide detailed information about each package.z--subdirz
--platformstoresubdirzSearch the given subdir. Should be formatted like 'osx-64', 'linux-32', 'win-64', and so on. The default is to search the current platform.)r   destr   defaultz--skip-flexible-searchz7Do not perform flexible search if initial search fails.
match_spec*?)r   nargsr   z--canonicalz-fz--full-namez--names-onlyz-oz
--outdatedz--specz--reverse-dependencyzconda.cli.main_search.execute)func)search)
auxlib.ishr   common.constantsr   helpersr   r   r   r   
add_parseradd_argumentr   set_defaults)sub_parserskwargsr   r   r   r   r   r   summaryr   r   ps               5lib/python3.12/site-packages/conda/cli/main_search.pyconfigure_parserr1      s    !'  cG			 		K 	 FD 				
 	A NNX   NN?	   NNN   NN F  
 NN	   NN  
 NN	   NN  
 QNN	   NN  
 NN    !ANN7N8H    c                   ddl m} ddlm} ddlm} ddlm} ddlm	} ddl
m} ddlm} dd	lm dd
lm  || j$                        }	|	j'                  d      r|	j'                  d      f}
n|j(                  }
| j*                  r |d|	z  |j,                   xr |j.                   |j0                        5   ||	      }t3        fd|D              }ddd       |j0                  r	 |       y| j4                  rD ]  }|d   D ]  }t7        |         yddz  g}D ]e  }|d   D ][  }|j9                  |j:                  dd|j<                  dd|j>                  dd|j@                  j:                  dd|d   d	       ] g tC        djE                  |             y |d|j,                   xr |j.                   |j0                        5  |	j'                  d      }|r|fn|jF                  }tI        |jK                  |	||
      fd      }ddd       sr| jL                  sf|	j'                  d      rU ||	d|	j:                  z         }|j0                  stC        d!|	 d"|        tI        |jK                  ||
      fd#      }|sPt3         ||jF                  | jN                   |
d   | jP                  $            }dd%l)m*}  |tW        |	      f|      |j0                  r=tY        tZ              }|D ]   }||j:                     j9                  |       "  ||       y| j4                  r|D ]  }t7        |        yd&d'z  g}|D ]T  }|j9                  |j:                  dd|j<                  dd|j>                  dd|j@                  j:                  d       V tC        djE                  |             y# 1 sw Y   xY w# 1 sw Y   xY w)(z
    Implements `conda search` commands.

    `conda search <spec>` searches channels for packages.
    `conda search <spec> --envs` searches environments for packages.

    r   )context)stdout_json)Spinner)query_all_prefixes)calculate_channel_urls)
SubdirData)	MatchSpecr   )VersionOrderr   zSearching environments for %sc              3  j   K   | ]*  \  }}|t        t        fd |D        d             d , yw)c              3  B   K   | ]  } j                   |        y wN)from_objects).0
prefix_recr   s     r0   	<genexpr>z$execute.<locals>.<genexpr>.<genexpr>   s&      $. !; : :: Fs   c                    | j                   S r>   )_pkey)precs    r0   <lambda>z#execute.<locals>.<genexpr>.<lambda>   s
    TZZ r2   key)locationpackage_recordsN)tuplesorted)r@   prefixprefix_recsr   s      r0   rB   zexecute.<locals>.<genexpr>   sF      # (FK !'',2= !8(#s   03NrJ   z# %-13s %15s %15s  %-20s %-20s)NameVersionBuildChannelLocation15 z>15z  20rI   
r   zLoading channelschannelc                V    | j                    | j                        | j                  fS r>   nameversionbuildrecr;   s    r0   rF   zexecute.<locals>.<lambda>       SXX|CKK'@#))L r2   rG   r[   z*%s*)r[   zNo match found for: z
. Search: c                V    | j                    | j                        | j                  fS r>   rZ   r^   s    r0   rF   zexecute.<locals>.<lambda>   r`   r2   )channel_urlsprependplatform	use_local)PackagesNotFoundErrorz# %-18s %15s %15s  %-20s)rO   rP   rQ   rR   ).base.contextr4   
cli.commonr5   	common.ior6   core.envs_managerr7   
core.indexr8   core.subdir_datar9   models.match_specr:   models.recordsr   models.versionr;   r    get_exact_valuesubdirsenvsverbosequietjsonrK   infopretty_recordappendr[   r\   r]   rX   printjoinchannelsrL   	query_allskip_flexible_searchoverride_channelsre   
exceptionsrf   strr   list)argsparserr4   r5   r6   r7   r8   r9   r:   specrq   prefix_matchesordered_result	pkg_grouprE   builderspec_channelrb   matches	flex_specchannels_urlsrf   json_objmatchrecordr   r;   s                            @@r0   executer      s    '(#63--.-T__%DH%''13//yy+d25$5LL
 	
 05N" # ,:# N	* <<': 9 YY+ (	%&78 (D!$'((6 - 1	G , 	%&78 
DNN !II LL JJ LL--%j1	
 $))G$%	OO1GMM 1
 

 ++I6*6G<L<L  |W=L

 4449M9Mf9Ud$)));<	||(jDE  L'BL

 "$-- 222 ..	
 	7#SYL-@@||t$ 	/EUZZ ''.	/H6 3 
 	"F&!	"0 ' '
  		FNN KKNNLLNN''		 	dii !m	 	j
 
s   9O	AO	OO c                ,    ddl m} ddlm}  fd}g j	                   j
                  dz    j                  z   dz    j                  z          j	                  dt        d         z          |dd	        |d
d
        |dd        |dd        |dd       t         dd      }|j	                  ddd ||              |dd        |dd        |dd        |dd        j                  rTt        j                   j                  t        j                        j                  d      }j	                  ddd|        j                   r'j	                  ddd | j                                 j"                  r'j	                  ddd | j"                               j	                  ddd j$                  r | j$                        nd       j	                  d       t'        dj)                               y)zd
    Pretty prints a `PackageRecord`.

    :param record:  The `PackageRecord` object to print.
    r   )dashlist)human_bytesc                T    t        |d       }|j                  | dd|       y y )N12: )getattrrx   )display_name	attr_namevaluer   r   s      r0   	push_linez pretty_record.<locals>.push_line7  s-    	40NN,>? r2   rU   -r   z	file namefnr[   r\   r]   zbuild numberbuild_numbersizeNr   r   licenser   urlmd5z%Y-%m-%d %H:%M:%S %Z	timestamptrack_featuresconstraintsdependenciesz[]rW   )ri   r   utilsr   rx   r[   r\   r]   lenr   r   r   fromtimestampr   utcstrftimer   
constrainsdependsry   rz   )r   r   r   r   r   date_strr   s   `     @r0   rw   rw   .  s    %#@
 GNN6;;$v~~5;fllJKNN3WQZ()k4 ffi#gwnn-664(Dfk$.?@Ai#h!eUeU))&*:*:HLLIRR"
 	k8<=+Xf6K6K-LM	
 mXf>O>O5PQRNNv~~8FNN34O	Q NN4	$))G
r2   N)r,   r   returnr	   )r   r
   r   r	   r   int)r   r   r   None)__doc__
__future__r   argparser   collectionsr   r   r   typingr   r	   r
   r   rn   r   r1   r   rw    r2   r0   <module>r      s:   
 #  # '  EE.DNOd.r2   