a
    h                     @   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 qzqddd	d
ZeD ]Zde ee< qd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|s6t	
d |d~}|D ]h}| |}|sZqF|d|d }}| }|tv rFt|}tt| d }||ksFJ | dqFW d    n1 s0    Y  d S )	NzN(\.\. \|)(([A-Za-z]+\-?)+)(MinVersion\| replace::)( [0-9]+\.[0-9]+(\.[0-9]+)?)z
README.rstz%The README.rst file is not available.r      r    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    f/var/www/html/assistant/venv/lib/python3.9/site-packages/sklearn/tests/test_min_dependencies_readme.pytest_min_dependencies_readme   s$    

r"   c                 C   sZ  t d}|d u rg }t| }ttjjj}|d }| sFt d |	d}|
|}W d    n1 sp0    Y  | d}	|}
|	D ]}|
| }
qi }|
D ]J}d|v r|d\}}n&d|v r|d\}}nt| d|||< qt|t|ksJ | D ]H\}}t|}tt| d	 }||v r:q||ksJ | d
qd 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   sB    

(



r4   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.   )r4   )r,   r-   r.   r    r    r!   $test_min_dependencies_pyproject_tomlx   s    r6   )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"   r4   markZparametrizer6   r    r    r    r!   <module>   s4   & 
6