
    c0                        d 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mZmZmZmZ ej        d	k     rddlZnddlZ G d
 de          ZdS )z=Source for pyproject.toml files or more generally toml files.    )annotationsN)Path)Source)Key)UniversalConfig)_dict_to_dataclassfind_config_filemax_py_versionmin_py_versionparse_dependencies)      r   c                  x    e Zd ZU dZded<   dZded<   dZded<   d	Zded
<   ded<   	 	 dddZddZ	ddZ
ddZdS ) 	PyProjectz_Source for pyproject.toml and pytool.toml files.

    Can be extended to other toml files.
    strtoolNzdict | None	toml_dictpyproject.tomlnamez
    PEP 518 defines pyproject.toml as a configuration file to store build system
    requirements for Python projects. With the help of tools like Poetry or Flit
    it can fully replace the need for setup.py and setup.cfg files.
    descriptionzPath | NonefileTworking_directoryr   baseslist[str] | None	recursiveboolc                Z    |rt          |d|          | _        n
|dz  | _        || _        dS )aT  Initialize the TOML configuration.

        :param working_directory: Working Directory
        :param tool: name of your tool. Will read configuration from [tool.yourtool]
        :param bases: Base files/folders to look for (besides pyproject.toml)
        :param recursive: search recursively up the directory tree for the file.
        r   N)r	   r   r   )selfr   r   r   r   s        >lib/python3.11/site-packages/pytoolconfig/sources/pyproject.py__init__zPyProject.__init__(   s;      	=():<LeTTDII),<<DI			    returnc                >   | j         r| j                                         sdS t          j        | j                                                   | _        | j        dS d| j                                        vrdS | j        | j        d                                         v S )NFr   )r   existstomllibloads	read_textr   keysr   r   s    r   _readzPyProject._read<   s    y 		 0 0 2 2 	5 ty':':'<'<==> 	5,,... 	5yDN62779999r!   dict[str, Key] | Nonec                p    |                                  sdS | j        sJ | j        d         | j                 S )zParse the TOML file.Nr   )r*   r   r   r)   s    r   parsezPyProject.parseF   s9    zz|| 	4~~f%di00r!   r   c                   | j         st                      S d| j                             di                                           v r't	          t          | j         d         d                   }nt                      }d| j                                         v r| j         d         }d|                                v r0|d         }t          |          |_        t          |          |_        d|v r)t          |d                   }t          |          |_	        d|v rHi }|d         
                                D ]$\  }}t          t          |                    ||<   %||_        d|v r|d         |_        |S )zParse the file for the universal config object's fields.

        Only implement the relevant fields such as minimum python version.

        Pre: file was read but tool isn't necessarily in file.
        pytoolconfigr   projectzrequires-pythondependencieszoptional-dependenciesversion)r   r   getr(   r   r   r
   r   listr1   itemsoptional_dependenciesr2   )r   configr0   raw_python_verr1   optional_depsgroupdepss           r   universalconfigzPyProject.universalconfigM   s    ~ 	%"$$$T^//;;@@BBB 	''!7!G FF %&&F++--- 	4nY/G GLLNN2 G!():!;(6~(F(F%(6~(F(F%( 91'.2IJJ&*<&8&8#&'1 = "#*+B#C#I#I#K#K J JKE4+/0B40H0H+I+IM%((/<,G# 4!(!3r!   )NT)r   r   r   r   r   r   r   r   )r"   r   )r"   r+   )r"   r   )__name__
__module____qualname____doc____annotations__r   r   r   r    r*   r-   r<    r!   r   r   r      s          
 III!I!!!! D    K    
  #'    (: : : :1 1 1 1           r!   r   )r@   
__future__r   syspathlibr   pytoolconfig.sources.sourcer   pytoolconfig.typesr   pytoolconfig.universal_configr   pytoolconfig.utilsr   r	   r
   r   r   version_infotomlir%   r   rB   r!   r   <module>rL      s   C C " " " " " " 



       . . . . . . " " " " " " 9 9 9 9 9 9              j  NNNU U U U U U U U U Ur!   