
    iN2                    \   U 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 d dlZd dl	m
Z
 d dlZd dlmZ d d	lmZ d dl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  ed           G d d                      Zeeef         Zded<   d5dZd6dZd7d"Zd8d$Z d9d'Z!d:d*Z"d+Z#d;d1Z$d<d4Z%dS )=    )annotations)Iterable)Sequence)	dataclass)KW_ONLYN)Path)Literal)	TypeAlias   )
UsageError)failabsolutepath)
commonpathsafe_existsT)frozenc                  <    e Zd ZU dZded<   ded<   ded<   ded	<   d
S )ConfigValuea8  Represents a configuration value with its origin and parsing mode.

    This allows tracking whether a value came from a configuration file
    or from a CLI override (--override-ini), which is important for
    determining precedence when dealing with ini option aliases.

    The mode tracks the parsing mode/data model used for the value:
    - "ini": from INI files or [tool.pytest.ini_options], where the only
      supported value types are `str` or `list[str]`.
    - "toml": from TOML files (not in INI mode), where native TOML types
       are preserved.
    objectvaluer   _zLiteral['file', 'override']originzLiteral['ini', 'toml']modeN)__name__
__module____qualname____doc____annotations__     U/root/projects/qq-shell/venv/lib/python3.11/site-packages/_pytest/config/findpaths.pyr   r      sH           MMMJJJ''''      r!   r   r
   
ConfigDictpathr   returniniconfig.IniConfigc                    	 t          j        t          |                     S # t           j        $ r"}t	          t          |                    |d}~ww xY w)zParse the given generic '.ini' file using legacy IniConfig parser, returning
    the parsed object.

    Raise UsageError if the file cannot be parsed.
    N)	iniconfig	IniConfigstr
ParseErrorr   )r$   excs     r"   _parse_ini_configr-   .   sV    ,"3t99--- , , ,S""+,s    # AAAfilepathConfigDict | Nonec                  
 | j         dk    rDt          |           }d|v r$d |d                                         D             S | j        dv ri S n| j         dk    rqt          |           }d|j        v r$d |d                                         D             S d|j        v r*t          t                              d	          d
           nt| j         dk    rht          j	        dk    rddl
}nddl}|                     d          }	 |                    |          }n'# |j        $ r}t          |  d|           |d}~ww xY w| j        dv r8|                    di           }|rd |                                D             S i S |                    di                               di           }d |                                D             }|                    dd          }	|r|	rt          |  d          |rd |                                D             S |	$d d

fd|	                                D             S dS )!zLoad pytest configuration from the given file path, if supported.

    Return None if the file does not contain valid pytest configuration.
    z.inipytestc                :    i | ]\  }}|t          |d d          S fileinir   r   r   .0kvs      r"   
<dictcomp>z.load_config_dict_from_file.<locals>.<dictcomp>F   =       Aq ;qe<<<  r!   >   
pytest.ini.pytest.iniz.cfgztool:pytestc                :    i | ]\  }}|t          |d d          S r3   r7   r8   s      r"   r<   z.load_config_dict_from_file.<locals>.<dictcomp>T   r=   r!   	setup.cfg)filenameF)pytracez.toml)      r   Nzutf-8)encodingz: )pytest.toml.pytest.tomlc                :    i | ]\  }}|t          |d d          S r4   tomlr6   r7   r8   s      r"   r<   z.load_config_dict_from_file.<locals>.<dictcomp>q   =       1 {1V&AAA  r!   toolc                &    i | ]\  }}|d k    ||S )ini_optionsr    r8   s      r"   r<   z.load_config_dict_from_file.<locals>.<dictcomp>}   s(    VVVDAq1CUCU1aCUCUCUr!   rO   z: Cannot use both [tool.pytest] (native TOML types) and [tool.pytest.ini_options] (string-based INI format) simultaneously. Please use [tool.pytest] with native TOML types (recommended) or [tool.pytest.ini_options] for backwards compatibility.c                :    i | ]\  }}|t          |d d          S rJ   r7   r8   s      r"   r<   z.load_config_dict_from_file.<locals>.<dictcomp>   rL   r!   r;   r   r%   str | list[str]c                N    t          | t                    r| nt          |           S N)
isinstancelistr*   )r;   s    r"   make_scalarz/load_config_dict_from_file.<locals>.make_scalar   s!     *1d 3 3?11Q?r!   c                N    i | ]!\  }}|t           |          d d          "S r3   r7   )r9   r:   r;   rV   s      r"   r<   z.load_config_dict_from_file.<locals>.<dictcomp>   sF       1 {;;q>>&uMMM  r!   )r;   r   r%   rQ   )suffixr-   itemsnamesectionsr   CFG_PYTEST_SECTIONformatsysversion_infotomllibtomli	read_textloadsTOMLDecodeErrorr   get)r.   r(   r`   	toml_textconfigr,   pytest_configtool_pytesttoml_config
ini_configrV   s             @r"   load_config_dict_from_filerl   :   s0    &  %h//	y   %h/5577    } ===	 > 
F	"	"%h//	I... %m4::<<    +++ #**K*@@%PPPP
 
G	#	#w&&NNNN####&&&88		<]]9--FF& 	< 	< 	<11C1122;	< =;;;"JJx44M   - 3 3 5 5   
 I !**VR0044XrBBK WVK,=,=,?,?VVVK$==J z   P P P      + 1 1 3 3   
 '@ @ @ @    * 0 0 2 2   
 4s   	D 
E)D>>Einvocation_dirargsIterable[Path]:tuple[Path | None, Path | None, ConfigDict, Sequence[str]]c                   g d}d |D             }|s| g}d}g }|D ]}t          |          }|g|j        R D ]}|D ]}||z  }	|	                                r|	j        dk    r||	}t	          |	          }
|
n|                    |          }||dz   d         D ]?}||z  }|                                r$t	          |          |                    |           @||	|
|fc c c S ||j        |i g fS ddi g fS )a	  Search in the list of arguments for a valid ini-file for pytest,
    and return a tuple of (rootdir, inifile, cfg-dict, ignored-config-files), where
    ignored-config-files is a list of config basenames found that contain
    pytest configuration but were ignored.)rG   rH   r>   r?   pyproject.tomlztox.inirA   c                V    g | ]&}t          |                              d           $|'S )-)r*   
startswith)r9   xs     r"   
<listcomp>z!locate_config.<locals>.<listcomp>   s1    :::!3q66#4#4S#9#9:A:::r!   Nrr   r   )r   parentsis_filerZ   rl   indexappendparent)rm   rn   config_namesfound_pyproject_tomlignored_config_filesargargpathbaseconfig_nameprk   rz   	remainderp2s                 r"   locate_configr      s     L ;:t:::D  (,&( I Is##/w// 	I 	ID+ I I;&99;; Iv!1116J6R/0,!;A!>!>J!- , 2 2; ? ?)5eaikk)B G GI!%	!1B "

G$>r$B$B$N 4 ; ;I F F F#Q
4HHHHHHHHHI	I" '#*,@"bHHr2r!   pathsc                    d }|D ]L}|                                 s||}||j        v s||k    r,||j        v r|}8t          ||          }||}M|| }n|                                r|j        }|S rS   )existsrx   r   ry   r|   )rm   r   common_ancestorr$   shareds        r"   get_common_ancestorr      s     $(O - -{{}} 	""OO$,..$/2I2I000"&#D/::%&,O(		 	 	"	" 1)0r!   Iterable[str]
list[Path]c                Z    dddddd	fd
| D             }fd|D             S )Nrv   r*   r%   boolc                ,    |                      d          S )Nrt   )ru   rv   s    r"   	is_optionz%get_dirs_from_args.<locals>.is_option   s    ||C   r!   c                8    |                      d          d         S )Nz::r   )splitr   s    r"   get_file_part_from_node_idz6get_dirs_from_args.<locals>.get_file_part_from_node_id   s    wwt}}Qr!   r$   r   c                <    |                                  r| S | j        S rS   )is_dirr|   )r$   s    r"   get_dir_from_pathz-get_dirs_from_args.<locals>.get_dir_from_path   s    ;;== 	K{r!   c              3  ^   K   | ]'} |          t           |                    V  (d S rS   r   )r9   r   r   r   s     r"   	<genexpr>z%get_dirs_from_args.<locals>.<genexpr>   sY        y~~//4455     r!   c                D    g | ]}t          |           |          S r    r   )r9   r$   r   s     r"   rw   z&get_dirs_from_args.<locals>.<listcomp>   s2    TTT+dBSBSTd##TTTr!   )rv   r*   r%   r   )rv   r*   r%   r*   )r$   r   r%   r   r    )rn   possible_pathsr   r   r   s     @@@r"   get_dirs_from_argsr      s    ! ! ! !                N UTTTTTTTr!   override_iniSequence[str] | Nonec                    i }| pdD ]W}	 |                     dd          \  }}t          |dd          ||<   2# t          $ r}t          d|d          |d	}~ww xY w|S )
zParse the -o/--override-ini command line arguments and return the overrides.

    :raises UsageError:
        If one of the values is malformed.
    r    =r   overrider5   r6   z3-o/--override-ini expects option=value style (got: z).N)r   r   
ValueErrorr   )r   	overridesrk   keyuser_ini_valuees         r"   parse_override_inir      s     I #(b X X
	X","2"23":":C )
QVWWWIcNN  	 	 	VjVVV 	 s   9
AAAz][pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead.inifile
str | NoneSequence[str]rootdir_cmd_arg3tuple[Path, Path | None, ConfigDict, Sequence[str]]c                   d}t          |          }g }| r,t          |           }|}	t          |          pi }
||j        }nt	          ||          }t          ||g          \  }}	}
}|l|j|g|j        R D ]}|dz                                  r|} nB||gk    rt          ||          \  }}	}
}|#t	          |||g          }t          |          r|}|rSt          t          j
                            |                    }|                                st          d| d          t          |          }|
                    |           |J ||	|
|fS )a  Determine the rootdir, inifile and ini configuration values from the
    command line arguments.

    :param inifile:
        The `--inifile` command line argument, if given.
    :param override_ini:
        The -o/--override-ini command line arguments, if given.
    :param args:
        The free command line arguments.
    :param rootdir_cmd_arg:
        The `--rootdir` command line argument, if given.
    :param invocation_dir:
        The working directory when pytest was invoked.

    :raises UsageError:
    Nzsetup.pyzDirectory 'z+' not found. Check your '--rootdir' option.)r   r   rl   r|   r   r   rx   ry   
is_fs_rootosr$   
expandvarsr   r   r   update)r   r   rn   r   rm   rootdirdirsr   inipath_inipathinicfgancestorpossible_rootdirr   ini_overridess                  r"   determine_setupr     s   0 Gd##D*, +(('+H55;"oG&~t<<9FXJ:
 :
6&"6 ?6%-$A0@$A$A + + $z1::<< .GE H:%%2?PT2U2U/GWfa?1&(B G "'** +"* rw11/BBCC~~ 	RgRRR   '|44M
MM-   GV%999r!   r   r   c                    t           j                            t          |                     d         t           j        k    S )z
    Return True if the given path is pointing to the root of the
    file system ("/" on Unix and "C:\\" on Windows for example).
    r   )r   r$   
splitdriver*   sep)r   s    r"   r   r   Y  s,    
 7c!ff%%a(BF22r!   )r$   r   r%   r&   )r.   r   r%   r/   )rm   r   rn   ro   r%   rp   )rm   r   r   ro   r%   r   )rn   r   r%   r   )r   r   r%   r#   )r   r   r   r   rn   r   r   r   rm   r   r%   r   )r   r   r%   r   )&
__future__r   collections.abcr   r   dataclassesr   r   r   pathlibr   r^   typingr	   r
   r(   
exceptionsr   _pytest.outcomesr   _pytest.pathlibr   r   r   r   dictr*   r#   r   r-   rl   r   r   r   r   r\   r   r   r    r!   r"   <module>r      s1   " " " " " " " $ $ $ $ $ $ $ $ $ $ $ $ ! ! ! ! ! !       				       



                 " " " " " " ! ! ! ! ! ! ( ( ( ( ( ( & & & & & & ' ' ' ' ' ' $! ! ! ! ! ! ! !( S+-.
 . . . .	, 	, 	, 	,a a a aH, , , ,^   4U U U U,   , u @: @: @: @:F3 3 3 3 3 3r!   