
    .Ph4                     0   d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
 d dlmZmZmZmZmZmZ d dlmZmZ d dlmZmZ d dlmZ d dlmZmZmZmZmZ  G d d	e          Z d
d
d
ddedee!         dee!         deee                  def
dZ"de
eef         de
e!ef         fdZ#dee!ef         defdZ$d
ddedeee                  dee ee!e
eef         f         f         fdZ%de	e e&f         de	e!e!e!f         fdZ'de dee!         fdZ(dee!         defdZ)d
S )    )defaultdict)AnyDictList
NamedTupleOptionalSetTupleUnion)TOMLDocumentcommentdocumentinline_tableitemtable)InlineTableTable)EditableDependencyunify_platform_independent_deps)warn)
DependencyLockSpecificationURLDependencyVCSDependencyVersionedDependencyc                   >    e Zd ZU dZeed<   ee         ed<   eed<   dS )TomlTableKeya,  Represents a key in a pixi.toml table.

    It can be rendered into a TOML header using `toml_header_sequence`.

    >>> toml_header_sequence(
    ...     TomlTableKey(category="dev", platform="linux-64", manager="pip")
    ... )
    ['feature', 'dev', 'target', 'linux-64', 'pypi-dependencies']
    categoryplatformmanagerN)__name__
__module____qualname____doc__str__annotations__r        [/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/conda_lock/export_lock_spec.pyr   r      s>           MMMsmLLLLLr(   r   N)project_name	with_cuda	editables	lock_specr*   r+   r,   returnc                    t                      }dddgd | j        D             R D ]$}|                    t          |                     %|d}t	          | j                                                  }t                      }|D ],}| j        |         D ]}	|                    |	j                   -ddh|k    rt          d	          |                    d
t          t          |t          |          d | j        D                                            t          | j                  dk    rt          d           | j        D ]!}
|
j        rt          d|
j         d           "t%          | |          }|                                D ]\  }}t)          |          }d |                                D             }|}|D ]I}||vr"|                    |t+                                 ||         }t-          |t.                    sJ |}J|                    |           t          |          dk    r#|                    dt3          |                     |r1|                    dt          t          |                               |S )zFRender a pixi.toml from a LockSpecification as a tomlkit TOMLDocument.zGThis file was generated by conda-lock for the pixi environment manager.zVFor more information, see <https://github.com/conda/conda-lock> and <https://pixi.sh>.zSource files:c              3   D   K   | ]}d |                                  V  dS )z- N)as_posix).0src_files     r)   	<genexpr>z#render_pixi_toml.<locals>.<genexpr>3   s7      	G	G
$x  ""
$
$	G	G	G	G	G	Gr(   Nzproject-name-placeholdermaindefaultz:Cannot have both 'main' and 'default' as categories/extrasprojectc                     g | ]	}|j         
S r'   )url)r2   channels     r)   
<listcomp>z$render_pixi_toml.<locals>.<listcomp>J   s    HHH''+HHHr(   )name	platformschannelsr   z~No channels defined in the lock file! Consider defining channels, e.g. via the command line by adding `--channel conda-forge`.zChannel zD uses environment variables, which will be dropped in the pixi.toml.r,   c                 4    i | ]\  }}|t          |          S r'   )toml_dependency_value)r2   r<   deps      r)   
<dictcomp>z$render_pixi_toml.<locals>.<dictcomp>`   s4     
 
 
1:sD',,
 
 
r(      environmentszsystem-requirements)cuda)r   sourcesaddr   sorteddependencieskeyssetr   
ValueErrorr   dictlistr>   lenr   used_env_varsr9   arrange_for_tomlitemstoml_header_sequencer   
isinstancer   updatetoml_environments_table)r-   r*   r+   r,   	pixi_tomllineall_platformsall_categoriesr   rB   r:   arranged_depskeydeps_by_nameheader_sequence
inner_dictnodeheader	next_nodes                      r)   render_pixi_tomlrd   %   s    

IQ	!	
 
H	GY5F	G	G	G  % % 	gdmm$$$$191668899M"uuN! - -)(3 	- 	-Cs|,,,,	-	n,, UVVVMM!}--HHY5GHHH  	
 	
	 	 	 9!##F	
 	
 	
 %    	/7; / / /   %Y)DDDM*0022    \%9#%>%>
 
>J>P>P>R>R
 
 

 ,5% 	 	FT!!)))VIi/////DDJ >Qn&=n&M&MNNN  I+T$I2F2F2F-G-GHHHr(   rB   c                     i }t          | t                    r| j        pd|d<   | j        dk    r.|d         d                                         rd|d          |d<   | j        
| j        |d<   | j        t          d|            | j        
| j        |d	<   | j	        r/| j	        r| j        d
k    rt          d|             n
| j	        |d<   t          |          dk    r|d         S t          |          S t          | t                    rt          d|            t          | t                    rt          d|            t          | t                    r#t          t!          | j        d                    S t%          d|            )a  Render a conda-lock Dependency as a pixi.toml line as VersionSpec or matchspec.

    The result is suitable for the values used in the `dependencies` or
    `pypi-dependencies` tables of a pixi TOML file.

    >>> toml_dependency_value(VersionedDependency(name="numpy", version="2.1.1"))
    '2.1.1'

    >>> toml_dependency_value(VersionedDependency(name="numpy", version=""))
    '*'

    >>> toml_dependency_value(
    ...     VersionedDependency(
    ...         name="numpy",
    ...         version="2.1.1",
    ...         conda_channel="conda-forge",
    ...         build="py313h4bf6692_0"
    ...     )
    ... )
    {'version': '2.1.1', 'build': 'py313h4bf6692_0', 'channel': 'conda-forge'}

    >>> toml_dependency_value(
    ...     VersionedDependency(
    ...         name="xarray",
    ...         version="",
    ...         extras=["io", "parallel"],
    ...         manager="pip",
    ...     )
    ... )
    {'version': '*', 'extras': ['io', 'parallel']}
    *versionpipr   z==NbuildzHash not yet supported in r:   condaz"Extras not supported in Conda dep extrasrD   zURL not yet supported in zVCS not yet supported in T)patheditablezUnknown dependency type )rU   r   rg   r    isdigitri   hashNotImplementedErrorconda_channelrk   r   rP   _dict_to_inline_tabler   r   r   rN   rl   rM   )rB   	matchspecs     r)   rA   rA   {   s   D !#I#*++ ;"{1c	);%Ii$8$;$C$C$E$E#>	)(<#>#>Ii 9 !$Ig8%&H3&H&HIII(#&#4Ii : 	1z 1ckW44?#??@@@@&)j	(#y>>QY''(333	C	'	' ;!"Cc"C"CDDD	C	'	' ;!"Cc"C"CDDD	C+	,	, ;$Tsx$%G%G%GHHH9C99:::r(   dc                 B    t                      } |j        |            |S )z,Convert a dictionary to a TOML inline table.)r   rV   )rt   r   s     r)   rr   rr      s    NNEELOOOLr(   r?   c          	      
   t          | j        |          }t          t                    }|                                D ]p\  }}t          |j        |j        |j                  }|j	        ||         v r+||         |j	                 }t          d| d| d|           |||         |j	        <   qd |                                D             }t          t          |                                t                              }	|	S )zFArrange dependencies into a structured dictionary for TOML generation.r?   r   r   r    zDuplicate key z for z and c           	      r    i | ]4\  }}|t          t          |                                                    5S r'   )rN   rI   rS   )r2   toml_keyr^   s      r)   rC   z$arrange_for_toml.<locals>.<dictcomp>   sJ       "Hl 	$vl00223344  r(   )r]   )r   rJ   r   rN   rS   r   r   r   r    r<   RuntimeErrorrI   toml_ordering)
r-   r,   unified_depsunsorted_resultdep_keyrB   ry   preexisting_depalphabetized_resultsorted_results
             r)   rR   rR      s<    3)  L 	D  %**,, 6 6%%O
 
 

 <?8444 .h7EOJJJsJJJJ   36!',// &5&;&;&=&=    3 9 9 ; ;OOOPPMr(   r   c                 j    | d         }|j         dv rdn|j         }|j        |j        nd}|||j        fS )a  Make a sort key to properly order the dependency tables in the pixi.toml.

    The main category = default feature comes first. Then the other categories.

    Within each category, the platform-independent dependencies come first, followed by
    the platform-specific dependencies.

    Within each platform, we declare the conda dependencies first, followed by the pip
    dependencies.

    Within each table determined by the hierarchy of category, platform, and manager,
    the dependencies are sorted alphabetically by name. But the key here is just for
    sorting the tables that occur, not the dependencies within them.

    We define the ordering via a tuple of strings: (category, platform, manager).
    The main category and the platform-independent dependencies are represented by
    empty strings so that they come lexicographically first.

    >>> toml_ordering(
    ...     (TomlTableKey(category="main", platform=None, manager="conda"), {})
    ... )
    ('', '', 'conda')

    >>> toml_ordering(
    ...     (TomlTableKey(category="main", platform="linux-64", manager="conda"), {})
    ... )
    ('', 'linux-64', 'conda')

    >>> toml_ordering((TomlTableKey(category="dev", platform=None, manager="pip"), {}))
    ('dev', '', 'pip')
    r   r5   r6    rw   )r   r]   r   r   s       r)   r{   r{      sG    @ q'C\%888rrclH"|7s||RHXs{**r(   r]   c                     g }| j         dvr|                    d| j         g           | j        r|                    d| j        g           |                    | j        dk    rdnd           |S )a;  Generates a TOML header based on the dependency type, platform, and manager.

    >>> toml_header_sequence(
    ...     TomlTableKey(category="main", platform=None, manager="conda")
    ... )
    ['dependencies']

    >>> toml_header_sequence(
    ...     TomlTableKey(category="main", platform="linux-64", manager="conda")
    ... )
    ['target', 'linux-64', 'dependencies']

    >>> toml_header_sequence(
    ...     TomlTableKey(category="main", platform=None, manager="pip")
    ... )
    ['pypi-dependencies']

    >>> toml_header_sequence(
    ...     TomlTableKey(category="main", platform="linux-64", manager="pip")
    ... )
    ['target', 'linux-64', 'pypi-dependencies']

    >>> toml_header_sequence(
    ...     TomlTableKey(category="dev", platform=None, manager="conda")
    ... )
    ['feature', 'dev', 'dependencies']

    >>> toml_header_sequence(
    ...     TomlTableKey(category="dev", platform="linux-64", manager="conda")
    ... )
    ['feature', 'dev', 'target', 'linux-64', 'dependencies']

    >>> toml_header_sequence(TomlTableKey(category="dev", platform=None, manager="pip"))
    ['feature', 'dev', 'pypi-dependencies']

    >>> toml_header_sequence(
    ...     TomlTableKey(category="dev", platform="linux-64", manager="pip")
    ... )
    ['feature', 'dev', 'target', 'linux-64', 'pypi-dependencies']
    r   featuretargetrj   rJ   zpypi-dependencies)r   extendr   appendr    )r]   partss     r)   rT   rT     s|    R E
|...i.///
| /h-...	LL3;'#9#9?RSSSLr(   r[   c                     t           ddhz
            }t          |          dk    rt          d          t                      }|                    t          d                     |                    d|           g d}t           fd|D             d          }|)t          d	d
                    |          z   dz              n8|                    t          d                     |                    |g            |                    t          d                     |D ]}|                    ||g           |S )a  Define the environments section of a pixi.toml file.

    >>> environments_table = toml_environments_table({"main", "dev", "docs"})
    >>> print(environments_table.as_string())
    # Redefine the default environment to include all categories.
    default = ["dev", "docs"]
    # Define a minimal environment with only the default feature.
    minimal = []
    # Create an environment for each feature.
    dev = ["dev"]
    docs = ["docs"]
    <BLANKLINE>
    r5   r6   r   z*Expected at least one non-default categoryz;Redefine the default environment to include all categories.)minimalprodr5   c              3   $   K   | ]
}|v|V  d S )Nr'   )r2   r<   r[   s     r)   r4   z*toml_environments_table.<locals>.<genexpr>`  s-      RR$t>7Q7Q7Q7Q7Q7QRRr(   NzFCan't find a name for the 'minimal' environment since categories for 'z', 'z ' are already defined. Skipping.z;Define a minimal environment with only the default feature.z'Create an environment for each feature.)	rI   rP   rM   r   rH   r   nextr   join)r[   non_default_categoriesrE   MINIMAL_ENVIRONMENT_NAMESminimal_category_namer   s   `     r)   rW   rW   F  s    $Nfi5H$HII
!""a''EFFF77LMNN   Y 6777 ; ; ; RRRR3RRRTX  $Tkk344501	
 	
 	
 	
 	QRR	
 	
 	
 	.333WFGGHHH* / /H:....r(   )*collectionsr   typingr   r   r   r   r   r	   r
   r   tomlkitr   r   r   r   r   r   tomlkit.itemsr   r   3conda_lock._export_lock_spec_compute_platform_indepr   r   conda_lock.commonr   conda_lock.models.lock_specr   r   r   r   r   r   r%   rd   rA   rr   rR   rN   r{   rT   rW   r'   r(   r)   <module>r      s   # # # # # # K K K K K K K K K K K K K K K K K K K K N N N N N N N N N N N N N N N N , , , , , , , ,        # " " " " "                 :   & #'#48S S S S 3-S }	S
 /01S S S S Sl>;	z--	.>;
3>; >; >; >;BT#s(^      59' ' ' ' /01' 
,S%
4F(F"GGH
HI	' ' ' 'T$+lD01 $+eCcM6J $+ $+ $+ $+N/l /tCy / / / /d+CH + + + + + + +r(   