o
    wiGh                     @  s  U d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 ddl
mZmZ ddlmZmZ ddlmZmZmZmZmZmZmZ dd	l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# ddl$m%Z%m&Z& ddl'm(Z( ddl m)Z) erddl*m+Z+ ddl,m-Z- ddl.m/Z/ e0e1e2e1ef f Z3de4d< 	 e0e1e3f Z5de4d< 	 edddZ6	dMdNd$d%Z7dOd'd(Z8	)	dPdQd-d.Z9dRd3d4Z:dSd7d8Z;	dTdUd;d<Z<dVdAdBZ=G dCdD dDee6 Z>G dEdF dFe>d Z?G dGdH dHe>d Z@G dIdJ dJe(ZAG dKdL dLe(ZBdS )Wa<  
Load setuptools configuration from ``setup.cfg`` files.

**API will be made private in the future**

To read project metadata, consider using
``build.util.project_wheel_metadata`` (https://pypi.org/project/build/).
For simple scenarios, you can also try parsing the file directly
with the help of ``configparser``.
    )annotationsN)abstractmethod)defaultdict)IterableIterator)partialwraps)TYPE_CHECKINGAnyCallableClassVarGenericTypeVarcast)default_environment)InvalidRequirementRequirement)InvalidVersionVersion   )_static)StrPath)	FileErrorOptionError)SetuptoolsDeprecationWarning   )expand)	TypeAliasDistribution)DistributionMetadatar   SingleCommandOptionsAllCommandOptionsTargetr   r    Ffilepathr   find_othersboolignore_option_errorsreturndictc                 C  s8   ddl m} | }|r| ng }t|| ||}t|S )a,  Read given configuration file and returns options from it as a dict.

    :param str|unicode filepath: Path to configuration file
        to get options from.

    :param bool find_others: Whether to search for other configuration files
        which could be on in various places.

    :param bool ignore_option_errors: Whether to silently ignore
        options, values of which could not be resolved (e.g. due to exceptions
        in directives such as file:, attr:, etc.).
        If False exceptions are propagated as expected.

    :rtype: dict
    r   r   )setuptools.distr   find_config_files_applyconfiguration_to_dict)r$   r%   r'   r   dist	filenameshandlers r1   W/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/setuptools/config/setupcfg.pyread_configuration3   s
   r3   r.   c                 C  s   t | | |   | S )z`Apply the configuration from a ``setup.cfg`` file into an existing
    distribution object.
    )r,   _finalize_requires)r.   r$   r1   r1   r2   apply_configurationM   s   
r5   r1   other_filesIterable[StrPath]2tuple[ConfigMetadataHandler, ConfigOptionsHandler]c              	   C  s   ddl m} tj|}tj|std| dt }ttj	| g ||}z |j
| ttt |d t| | j|d}|   W t| |S t| w )zHRead configuration from ``filepath`` and applies to the ``dist`` object.r   )_DistributionzConfiguration file z does not exist.)r/   )r'   )r*   r9   ospathabspathisfiler   getcwdchdirdirnameparse_config_filesr   liststrparse_configurationcommand_options_finalize_license_files)r.   r$   r6   r'   r9   current_directoryr/   r0   r1   r1   r2   r,   V   s    

r,   
target_obj#Distribution | DistributionMetadatakeyrC   c                 C  s*   d| }t t| |}t| ||}| S )z
    Given a target object and option key, get that option from
    the target object, either through a get_{key} method or
    from an attribute directly.
    get_)	functoolsr   getattr)rH   rJ   getter_nameby_attributegetterr1   r1   r2   _get_optionu   s   
rQ   r0   KIterable[ConfigHandler[Distribution] | ConfigHandler[DistributionMetadata]]c                 C  s<   t t}| D ]}|jD ]}t|j|}|||j |< qq|S )zReturns configuration data gathered by given handlers as a dict.

    :param Iterable[ConfigHandler] handlers: Handlers list,
        usually from parse_configuration()

    :rtype: dict
    )r   r)   set_optionsrQ   rH   section_prefix)r0   config_dicthandleroptionvaluer1   r1   r2   r-      s   
r-   distributionrE   c                 C  s   t | 6}t| |||}|  | js|j| _t| j|||| j| j}|  | j	|j|j W d   ||fS 1 s>w   Y  ||fS )a  Performs additional parsing of configuration options
    for a distribution.

    Returns a list of used option handlers.

    :param Distribution distribution:
    :param dict command_options:
    :param bool ignore_option_errors: Whether to silently ignore
        options, values of which could not be resolved (e.g. due to exceptions
        in directives such as file:, attr:, etc.).
        If False exceptions are propagated as expected.
    :rtype: list
    N)
r   EnsurePackagesDiscoveredConfigOptionsHandlerparsepackage_dirConfigMetadataHandlermetadatasrc_root_referenced_filesupdate)rY   rE   r'   ensure_discoveredoptionsmetar1   r1   r2   rD      s4   
rD   label
orig_valueparsedrB   c              
     s   d|v s
t  dkrdS t  }zt d }|j|v r)tj|  d d W dS W dS  tyW } z t fdd|D rLtj	|  d d}t||W Y d}~dS d}~ww )am  Because users sometimes misinterpret this configuration:

    [options.extras_require]
    foo = bar;python_version<"4"

    It looks like one requirement with an environment marker
    but because there is no newline, it's parsed as two requirements
    with a semicolon as separator.

    Therefore, if:
        * input string does not contain a newline AND
        * parsed result contains two requirements AND
        * parsing of the two parts from the result ("<first>;<second>")
        leads in a valid Requirement with a valid marker
    a UserWarning is shown to inform the user about the possible problem.
    
r   Nr   )fieldreqc                 3  s    | ]
} d   |V  qdS )r   N
startswith).0markerrh   r1   r2   	<genexpr>       z8_warn_accidental_env_marker_misconfig.<locals>.<genexpr>)
len
marker_envkeysr   name_AmbiguousMarkeremitr   anymessage)rf   rg   rh   markersrk   exmsgr1   rp   r2   %_warn_accidental_env_marker_misconfig   s   


r~   c                   @  s   e Zd ZU dZded< 	 i Zded< 	 d5ddZed6ddZe	e
d7ddZd8ddZed9ddZedd Zedd Zedd  Zd:d#d$Zd;d&d'Zed(d) Zed*d+ Zed<d-d.Zd8d/d0Zd8d1d2Zd3d4 Zd,S )=ConfigHandlerz1Handles metadata supplied in configuration files.rC   rT   zClassVar[dict[str, str]]aliasesrH   r#   rd   r"   rc   expand.EnsurePackagesDiscoveredr(   Nonec                 C  s8   || _ || _t| || _g | _|| _tt  | _	d S N)
r'   rH   r)   _section_optionssectionsrS   rc   setrC   ra   selfrH   rd   r'   rc   r1   r1   r2   __init__   s   zConfigHandler.__init__*Iterator[tuple[str, SingleCommandOptions]]c                 c  s@    |  D ]\}}|| j\}}}|rq|d|fV  qd S )N.)items	partitionrT   lstrip)clsrd   	full_namerX   pre_seprv   r1   r1   r2   r     s   zConfigHandler._section_optionsdict[str, Callable]c                 C  s   t | jj d).Metadata item name to parser function mapping.z must provide .parsers property)NotImplementedError	__class____name__r   r1   r1   r2   parsers  s   zConfigHandler.parsersc           	   
   C  s   | j }| j||}zt||}W n ty" } zt||d }~ww |r'd S z| j|dd |}W n tf| j yB   Y d S w t	
|j|}t|d| |}|| | j| d S )Nc                 S  s   | S r   r1   )xr1   r1   r2   <lambda>(      z+ConfigHandler.__setitem__.<locals>.<lambda>set_)rH   r   getrM   AttributeErrorKeyErrorr   	Exceptionr'   rL   r   __setattr__rS   append)	r   option_namerX   rH   current_valueerh   simple_settersetterr1   r1   r2   __setitem__  s&   
zConfigHandler.__setitem__,c                 C  s8   t |tr|S d|v r| }n||}dd |D S )zRepresents value as a list.

        Value is split either by separator (defaults to comma) or by lines.

        :param value:
        :param separator: List items separator character.
        :rtype: list
        ri   c                 S  s   g | ]
}|  r|  qS r1   strip)rn   chunkr1   r1   r2   
<listcomp>D  s    z-ConfigHandler._parse_list.<locals>.<listcomp>)
isinstancerB   
splitlinessplit)r   rX   	separatorr1   r1   r2   _parse_list2  s   



zConfigHandler._parse_listc                 C  sR   d}i }|  |D ]}||\}}}||krtd| | || < q	|S )zPRepresents value as a dict.

        :param value:
        :rtype: dict
        =z&Unable to parse option value to dict: )r   r   r   r   )r   rX   r   resultlinerJ   sepvalr1   r1   r2   _parse_dictF  s   zConfigHandler._parse_dictc                 C  s   |  }|dv S )zQRepresents value as boolean.

        :param value:
        :rtype: bool
        )1trueyes)lowerr   rX   r1   r1   r2   _parse_boolW  s   zConfigHandler._parse_boolc                       fdd}|S )zReturns a parser function to make sure field inputs
        are not files.

        Parses a value after getting the key so error messages are
        more informative.

        :param key:
        :rtype: callable
        c                   s(   d}|  |rtd  dt| S )Nfile:z"Only strings are accepted for the z field, files are not accepted)rm   
ValueErrorr   Str)rX   exclude_directiverJ   r1   r2   parserm  s   


z3ConfigHandler._exclude_files_parser.<locals>.parserr1   )r   rJ   r   r1   r   r2   _exclude_files_parsera  s   	z#ConfigHandler._exclude_files_parserroot_dirStrPath | Nonec                 C  sh   d}t |ts	|S ||st|S |t|d }dd |dD }| j| tt	
||S )aO  Represents value as a string, allowing including text
        from nearest files using `file:` directive.

        Directive is sandboxed and won't reach anything outside
        directory with setup.py.

        Examples:
            file: README.rst, CHANGELOG.md, src/file.txt

        :param str value:
        :rtype: str
        r   Nc                 S  s   g | ]}|  qS r1   r   )rn   r;   r1   r1   r2   r         z-ConfigHandler._parse_file.<locals>.<listcomp>r   )r   rC   rm   r   r   rs   r   ra   rb   r   
read_files)r   rX   r   include_directivespec	filepathsr1   r1   r2   _parse_filex  s   


zConfigHandler._parse_filer   c                 C  s@   d}| |st|S ||d}|| jj t|||S )zRepresents value as a module attribute.

        Examples:
            attr: package.attr
            attr: package.module.attr

        :param str value:
        :rtype: str
        zattr: )	rm   r   r   replacerb   rc   r]   r   	read_attr)r   rX   r]   r   attr_directive	attr_descr1   r1   r2   _parse_attr  s   


zConfigHandler._parse_attrc                   r   )zReturns parser function to represents value as a list.

        Parses a value applying given methods one after another.

        :param parse_methods:
        :rtype: callable
        c                   s   | } D ]}||}q|S r   r1   )rX   rh   methodparse_methodsr1   r2   r\     s   
z1ConfigHandler._get_parser_compound.<locals>.parser1   )r   r   r\   r1   r   r2   _get_parser_compound  s   
z"ConfigHandler._get_parser_compoundc                 C  s,   i }|  D ]\}\}}|||||< q|S )a  Parses section options into a dictionary.

        Applies a given parser to each option in a section.

        :param dict section_options:
        :param callable values_parser: function with 2 args corresponding to key, value
        :rtype: dict
        )r   )r   section_optionsvalues_parserrX   rJ   _r   r1   r1   r2   _parse_section_to_dict_with_key  s   
z-ConfigHandler._parse_section_to_dict_with_keyNc                   s$    r fddndd }|  ||S )a   Parses section options into a dictionary.

        Optionally applies a given parser to each value.

        :param dict section_options:
        :param callable values_parser: function with 1 arg corresponding to option value
        :rtype: dict
        c                   s    |S r   r1   r   vr   r1   r2   r     s    z6ConfigHandler._parse_section_to_dict.<locals>.<lambda>c                 S  s   |S r   r1   r   r1   r1   r2   r     r   )r   )r   r   r   r   r1   r   r2   _parse_section_to_dict  s   
z$ConfigHandler._parse_section_to_dictc              	   C  sL   |  D ]\}\}}tt || |< W d   n1 sw   Y  qdS )zQParses configuration file section.

        :param dict section_options:
        N)r   
contextlibsuppressr   )r   r   rv   r   rX   r1   r1   r2   parse_section  s   
zConfigHandler.parse_sectionc                 C  sl   | j  D ].\}}d}|rd| }t| d| ddd}|du r/td| j d| d|| qdS )	zTParses configuration file items from one
        or more related sections.

        r   r   r   r   __Nz*Unsupported distribution option section: [])r   r   rM   r   r   rT   )r   section_namer   method_postfixsection_parser_methodr1   r1   r2   r\     s&   

zConfigHandler.parsec                   s   t   fdd}|S )zthis function will wrap around parameters that are deprecated

        :param msg: deprecation message
        :param func: function to be wrapped around
        c                    s.    dd tjdfi   | i |S )N
stacklevelr   z Deprecated config in `setup.cfg`)
setdefault_DeprecatedConfigrx   )argskwargsfunckwr}   r1   r2   config_handler  s   z@ConfigHandler._deprecated_config_handler.<locals>.config_handler)r   )r   r   r}   r   r   r1   r   r2   _deprecated_config_handler  s   z(ConfigHandler._deprecated_config_handler)rH   r#   rd   r"   rc   r   r(   r   )rd   r"   r(   r   r(   r   r(   r   )r   )r   r   )r   r   r   )r   
__module____qualname____doc____annotations__r   r   classmethodr   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r\   r   r1   r1   r1   r2   r      s@   
 
	


	







r   c                      sT   e Zd ZdZdddddZdZ	 dejfd fddZe	dddZ
dd Z  ZS ) r^   r_   urldescriptionclassifiers	platforms)	home_pagesummary
classifierplatformFNrH   r    rd   r"   r'   r&   rc   r   r]   dict | Noner   r   r(   r   c                   s"   t  |||| || _|| _d S r   )superr   r]   r   )r   rH   rd   r'   rc   r]   r   r   r1   r2   r     s   	
zConfigMetadataHandler.__init__r   c                 C  s   |  | jtj}|  | jtj}t| j| jd}| j	}i dtj
dtj
dtj
dtj
d|d|d|d	|d
|  ||d|dd|d|d|dtj
d| jdtj
d|S )r   r   authorauthor_email
maintainermaintainer_emailr   keywordsprovides	obsoletesr   licenselicense_filesr   long_descriptionlong_description_content_typeversionr   project_urls)r   r   r   Listr   Dictr   r   r   r   r   _parse_version)r   parse_list_staticparse_dict_static
parse_fileexclude_files_parserr1   r1   r2   r   '  sN   	
zConfigMetadataHandler.parsersc              
   C  st   |  || j}||kr.| }zt| W |S  ty- } ztd| d| |d}~ww t| || j	| jS )zSParses `version` option value.

        :param value:
        :rtype: str

        zVersion loaded from z does not comply with PEP 440: N)
r   r   r   r   r   r   r   r  r   r]   )r   rX   r  r   r1   r1   r2   r  C  s"   
z$ConfigMetadataHandler._parse_version)rH   r    rd   r"   r'   r&   rc   r   r]   r  r   r   r(   r   r   )r   r   r   rT   r   strict_moder:   curdirr   r   r   r  __classcell__r1   r1   r  r2   r^   
  s    r^   c                      s   e Zd ZdZd+ fddZedd Zdd Zd,ddZe	d-ddZ
dd Zdd Zdd Zd.dd Zd!d" Zd.d#d$Zd.d%d&Zd.d'd(Zd.d)d*Z  ZS )/r[   rd   rH   r   r"   r'   r&   rc   r   r(   r   c                   s$   t  |||| |j| _i | _d S r   )r  r   r`   r   r]   r   r  r1   r2   r   `  s   
zConfigOptionsHandler.__init__c                 C  s   | j |ddS )N;)r   )r   r   r1   r1   r2   _parse_list_semicolonk  s   z*ConfigOptionsHandler._parse_list_semicolonc                 C  s   | j || jdS )Nr  )r   r   )r   rX   r1   r1   r2   _parse_file_in_rooto  s   z(ConfigOptionsHandler._parse_file_in_rootrf   rC   rX   c                 C  s0   |  | |}t||| tdd |D S )Nc                 s  s    | ]
}| d s|V  qdS )#Nrl   )rn   r   r1   r1   r2   rq   x  rr   z@ConfigOptionsHandler._parse_requirements_list.<locals>.<genexpr>)r   r!  r~   r   r  )r   rf   rX   rh   r1   r1   r2   _parse_requirements_listr  s   z-ConfigOptionsHandler._parse_requirements_listr   c                 C  sN   | j }| j}| j}||| j|||| |dt| jd| j| j| j	|t
j|dS )r   zeThe namespace_packages parameter is deprecated, consider using implicit namespaces instead (PEP 420).install_requires)zip_safeinclude_package_datar]   scriptseager_resourcesdependency_linksnamespace_packagesr$  setup_requirespackagesentry_points
py_modulespython_requirescmdclass)r   r   _parse_cmdclassr   r   r   r#  r   _parse_packagesr!  r   SpecifierSet)r   
parse_list
parse_boolparse_cmdclassr1   r1   r2   r   {  s.   zConfigOptionsHandler.parsersc                 C  s   | j j}t| ||| jS r   )rc   r]   r   r0  r   r   )r   rX   r]   r1   r1   r2   r1    s   z$ConfigOptionsHandler._parse_cmdclassc                 C  sb   ddg}|  }||vr| |S | | jdi }|j||d k| j| jd tj	di |S )zTParses `packages` option value.

        :param value:
        :rtype: list
        zfind:zfind_namespace:zpackages.findr   )
namespacesr   fill_package_dirNr1   )
r   r   parse_section_packages__findr   r   rb   r   r]   r   find_packages)r   rX   find_directivestrimmed_valuefind_kwargsr1   r1   r2   r2    s   

z$ConfigOptionsHandler._parse_packagesc                   sN   |  || j}g d  fdd| D }|d}|dur%|d |d< |S )zParses `packages.find` configuration file section.

        To be used in conjunction with _parse_packages().

        :param dict section_options:
        )whereincludeexcludec                   s"   i | ]\}}| v r|r||qS r1   r1   )rn   kr   
valid_keysr1   r2   
<dictcomp>  s   " zEConfigOptionsHandler.parse_section_packages__find.<locals>.<dictcomp>r>  Nr   )r   r   r   r   )r   r   section_datar=  r>  r1   rB  r2   r9    s   
z1ConfigOptionsHandler.parse_section_packages__findc                 C  s   |  || j}|| d< dS )z`Parses `entry_points` configuration file section.

        :param dict section_options:
        r-  N)r   r   r   r   rh   r1   r1   r2   parse_section_entry_points  s   z/ConfigOptionsHandler.parse_section_entry_pointsc                 C  s   |  || j}t|S r   )r   r   r   canonic_package_data)r   r   package_datar1   r1   r2   _parse_package_data  s   
z(ConfigOptionsHandler._parse_package_datac                 C     |  || d< dS )z`Parses `package_data` configuration file section.

        :param dict section_options:
        rI  NrJ  r   r   r1   r1   r2   parse_section_package_data     z/ConfigOptionsHandler.parse_section_package_datac                 C  rK  )zhParses `exclude_package_data` configuration file section.

        :param dict section_options:
        exclude_package_dataNrL  rM  r1   r1   r2   "parse_section_exclude_package_data  rO  z7ConfigOptionsHandler.parse_section_exclude_package_datac                   s&     | fdd}t| d< dS )zbParses `extras_require` configuration file section.

        :param dict section_options:
        c                   s     d|  d|S )Nzextras_require[r   )r#  )rA  r   r   r1   r2   r     r   zCConfigOptionsHandler.parse_section_extras_require.<locals>.<lambda>extras_requireN)r   r   r  rF  r1   r   r2   parse_section_extras_require  s
   
z1ConfigOptionsHandler.parse_section_extras_requirec                 C  s$   |  || j}t|| j| d< dS )z^Parses `data_files` configuration file section.

        :param dict section_options:
        
data_filesN)r   r   r   canonic_data_filesr   rF  r1   r1   r2   parse_section_data_files  s   z-ConfigOptionsHandler.parse_section_data_files)
rH   r   rd   r"   r'   r&   rc   r   r(   r   )rf   rC   rX   rC   r   r   )r   r   r   rT   r   r   r   r!  r#  r   r   r1  r2  r9  rG  rJ  rN  rQ  rS  rV  r  r1   r1   r  r2   r[   ]  s$    

	



r[   c                   @  s$   e Zd ZdZdZdZedd ZdS )rw   zAmbiguous requirement marker.z
    One of the parsed requirements in `{field}` looks like a valid environment marker:

        {req!r}

    Please make sure that the configuration file is correct.
    You can use dangling lines to avoid this problem.
    z'userguide/declarative_config.html#opt-2c                 K  s"   d| j  }| j| j| j||dS )Nz%https://setuptools.pypa.io/en/latest/)see_urlformat_args)	_SEE_DOCS_format_SUMMARY_DETAILS)r   r   docsr1   r1   r2   rz     s   z_AmbiguousMarker.messageN)r   r   r   r[  r\  rY  r   rz   r1   r1   r1   r2   rw     s    rw   c                   @  s   e Zd ZdZdS )r   z!userguide/declarative_config.htmlN)r   r   r   rY  r1   r1   r1   r2   r     s    r   )FF)r$   r   r%   r&   r'   r&   r(   r)   )r.   r   r$   r   r(   r   )r1   F)
r.   r   r$   r   r6   r7   r'   r&   r(   r8   )rH   rI   rJ   rC   )r0   rR   r(   r)   )F)rY   r   rE   r"   r'   r&   r(   r8   )rf   rC   rg   rC   rh   rB   )Cr   
__future__r   r   rL   r:   abcr   collectionsr   collections.abcr   r   r   r   typingr	   r
   r   r   r   r   r   packaging.markersr   rt   packaging.requirementsr   r   packaging.versionr   r   r   r   _pathr   errorsr   r   warningsr   r   typing_extensionsr   r*   r   distutils.distr    r)   rC   tupler!   r   r"   r#   r3   r5   r,   rQ   r-   rD   r~   r   r^   r[   rw   r   r1   r1   r1   r2   <module>   s\    $



.   'S 