o
    Z&ie                     @   s   d Z ddlZddlZddlmZ ddlmZ ddlZddlZddl	m
Z
 ddlmZ eeZe
 D ]\Z\ZZedD ]	Zee e q=q2dd	d
ZeD ]	Zde ee< qOdd Z	dddZejde dd ZdS )zCTests for the minimum dependencies in README.rst and pyproject.toml    N)defaultdict)Path)dependent_packages)parse_versionz, zbuild-system.requireszproject.dependencies)buildinstallzproject.optional-dependencies.c            	      C   s   t d} ttjjj}|d }tj|st	
d |d@}|D ]4}| |}|s-q#|d|d}}| }|tv rWt|}tt| d }||ksWJ | dq#W d    d S 1 scw   Y  d S )NzE\.\. \|([A-Za-z-]+)MinVersion\| replace::( [0-9]+\.[0-9]+(\.[0-9]+)?)z
README.rstz%The README.rst file is not available.rr       has a mismatched version)recompiler   sklearn__file__parentospathexistspytestskipopenmatchgrouplowerr   r   )	patternZreadme_pathZreadme_fileflineZmatchedpackageversionmin_version r   UC:\wamp64\www\opt\env\Lib\site-packages\sklearn/tests/test_min_dependencies_readme.pytest_min_dependencies_readme   s*   

"r!   c                 C   sP  t d}|d u rg }t| }ttjjj}|d }| s#t d |	d}|
|}W d    n1 s8w   Y  | d}	|}
|	D ]}|
| }
qFi }|
D ]%}d|v r_|d\}}nd|v rk|d\}}nt| d|||< qQt|t|ksJ | D ] \}}t|}tt| d	 }||v rq||ksJ | d
qd S )Ntomllibzpyproject.tomlz pyproject.toml is not available.rb.z>=z==zV not supported yet in this test. Only >= and == are supported for version requirementsr   r
   )r   Zimportorskip-min_depencies_tag_to_packages_without_versionr   r   r   r   r   r   r   loadsplitNotImplementedErrorsorteditemsr   r   )pyproject_sectionmin_dependencies_tagskip_version_check_forr"   Zexpected_packagesZroot_directorypyproject_toml_pathr   pyproject_tomlZpyproject_section_keysinfokeyZpyproject_build_min_versionsrequirementr   r   Zexpected_min_versionr   r   r    check_pyproject_sectionB   sF   




r3   z'min_dependencies_tag, pyproject_sectionc                 C   s$   |dkrdgnd}t | ||d dS )zFCheck versions in pyproject.toml is consistent with _min_dependencies.r   numpyN)r-   )r3   )r+   r,   r-   r   r   r    $test_min_dependencies_pyproject_tomlx   s   
r5   )N)__doc__r   r   collectionsr   pathlibr   r   r   Zsklearn._min_dependenciesr   Zsklearn.utils.fixesr   listr%   r*   r   r   extrasr'   extraappendZ)min_dependencies_tag_to_pyproject_sectiontagr!   r3   markZparametrizer5   r   r   r   r    <module>   s8    &
6