o
    Eec                     @   sH  d 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 ddlm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZ ddlmZmZ dd	lmZ dd
lmZ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	rzddl'm(Z( ddl)m*Z* ee+ej,f Z-ededef f Z.	 ede.f Z/eded dZ0	dAde-de1fddZ2ddde-ddfddZ3		dBddde-d ee- d!e4ded" f
d#d$Z5d%e0d&e+fd'd(Z6d)ed" de1fd*d+Z7	dCd,dd-e/ded. fd/d0Z8d1e+d2e+d3e9fd4d5Z:G d6d7 d7ee0 Z;G d8d9 d9e;d: Z<G d;d< d<e;d Z=G d=d> d>e$Z>G d?d@ d@e$Z?dS )Da<  
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``.
    N)defaultdict)partialwraps)TYPE_CHECKINGCallableAnyDictGenericIterableListOptionalSetTupleTypeVarUnion   )	FileErrorOptionError)default_environment)InvalidRequirementRequirement)SpecifierSet)InvalidVersionVersion)SetuptoolsDeprecationWarning   )expand)DistributionMetadataDistributionstrTarget)r    r   )boundFfilepathreturnc                 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$   find_othersignore_option_errorsr    dist	filenameshandlers r/   [/var/www/bmteknikk.ddns.net/venv/lib/python3.10/site-packages/setuptools/config/setupcfg.pyread_configuration8   s
   r1   r,   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$   r/   r/   r0   apply_configurationR   s   
r3   r/   other_filesr+   )ConfigHandler.c              	   C   s   ddl m} tj|}tj|std| dt }ttj	| g ||}z|j
| |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&   r6   ospathabspathisfiler   getcwdchdirdirnameparse_config_filesparse_configurationcommand_options_finalize_license_files)r,   r$   r4   r+   r6   current_directoryr-   r.   r/   r/   r0   r(   [   s    

r(   
target_objkeyc                 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)rC   rD   getter_nameby_attributegetterr/   r/   r0   _get_optiony   s   
rK   r.   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 list[ConfigHandler] handlers: Handlers list,
        usually from parse_configuration()

    :rtype: dict
    )r   dictset_optionsrK   rC   section_prefix)r.   config_dicthandleroptionvaluer/   r/   r0   r)      s   
r)   distributionr@   )ConfigMetadataHandlerConfigOptionsHandlerc                 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   EnsurePackagesDiscoveredrU   parsepackage_dirrT   metadatasrc_root_referenced_filesupdate)rS   r@   r+   ensure_discoveredoptionsmetar/   r/   r0   r?      s4   
r?   label
orig_valueparsedc              
      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rb   r/   r0   	<genexpr>   s    z8_warn_accidental_env_marker_misconfig.<locals>.<genexpr>)
len
marker_envkeysr   name_AmbiguousMarkeremitr   anymessage)r`   ra   rb   markersre   exmsgr/   rj   r0   %_warn_accidental_env_marker_misconfig   s   


rw   c                   @   s   e Zd ZU dZeed< 	 i Zeeef ed< 	 dede	de
jfddZede	fd	d
Zedd Zdd Zed*ddZedd Zedd Zedd ZdefddZdefddZedd Zedd  Zed+d"d#Zd$d% Zd&d' Zd(d) Zd!S ),r5   z1Handles metadata supplied in configuration files.rN   aliasesrC   r^   r]   c                 C   s4   || _ || _t| || _g | _|| _t | _d S N)	r+   rC   rL   _section_optionssectionsrM   r]   setr[   selfrC   r^   r+   r]   r/   r/   r0   __init__   s   zConfigHandler.__init__c                 c   s@    |  D ]\}}|| j\}}}|rq|d|fV  qd S )N.)items	partitionrN   lstrip)clsr^   	full_namerR   presepro   r/   r/   r0   rz     s   zConfigHandler._section_optionsc                 C   s   t d| jj ).Metadata item name to parser function mapping.z!%s must provide .parsers property)NotImplementedError	__class____name__r~   r/   r/   r0   parsers  s   
zConfigHandler.parsersc              	   C   s   | j }| j||}zt||}W n ty   t|w |r!d S z| j|dd |}W n tf| j y<   Y d S w t	
|j|}t|d| |}|| | j| d S )Nc                 S   s   | S ry   r/   )xr/   r/   r0   <lambda>%      z+ConfigHandler.__setitem__.<locals>.<lambda>zset_%s)rC   rx   getrG   AttributeErrorKeyErrorr   	Exceptionr+   rF   r   __setattr__rM   append)r~   option_namerR   rC   current_valuerb   simple_settersetterr/   r/   r0   __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
        rc   c                 S   s   g | ]
}|  r|  qS r/   strip)rh   chunkr/   r/   r0   
<listcomp>A  s    z-ConfigHandler._parse_list.<locals>.<listcomp>)
isinstancelist
splitlinessplit)r   rR   	separatorr/   r/   r0   _parse_list/  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   rR   r   resultlinerD   r   valr/   r/   r0   _parse_dictC  s   zConfigHandler._parse_dictc                 C   s   |  }|dv S )zQRepresents value as boolean.

        :param value:
        :rtype: bool
        )1trueyes)lowerr   rR   r/   r/   r0   _parse_boolT  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 | S )Nfile:zCOnly strings are accepted for the {0} field, files are not accepted)rg   
ValueErrorformat)rR   exclude_directiverD   r/   r0   parserj  s   
z3ConfigHandler._exclude_files_parser.<locals>.parserr/   )r   rD   r   r/   r   r0   _exclude_files_parser^  s   	z#ConfigHandler._exclude_files_parserroot_dirc                 C   s\   d}t |ts	|S ||s|S |t|d }dd |dD }| j| 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 r/   r   )rh   r8   r/   r/   r0   r         z-ConfigHandler._parse_file.<locals>.<listcomp>r   )	r   r!   rg   rl   r   r[   r\   r   
read_files)r~   rR   r   include_directivespec	filepathsr/   r/   r0   _parse_fileu  s   

zConfigHandler._parse_filec                 C   s:   d}| |s	|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: )rg   replacer\   r]   rX   r   	read_attr)r~   rR   rX   r   attr_directive	attr_descr/   r/   r0   _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 ry   r/   )rR   rb   methodparse_methodsr/   r0   rW     s   
z1ConfigHandler._get_parser_compound.<locals>.parser/   )r   r   rW   r/   r   r0   _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_parserrR   rD   _r   r/   r/   r0   _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 ry   r/   r   vr   r/   r0   r     s    z6ConfigHandler._parse_section_to_dict.<locals>.<lambda>c                 S   s   |S ry   r/   r   r/   r/   r0   r     r   r   )r   r   r   r   r/   r   r0   _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   ro   r   rR   r/   r/   r0   parse_section  s   
zConfigHandler.parse_sectionc                 C   sh   | 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   z_%szparse_section%sr   __Nz*Unsupported distribution option section: [])r{   r   rG   r   r   rN   )r~   section_namer   method_postfixsection_parser_methodr/   r/   r0   rW     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_DeprecatedConfigrq   )argskwargsfunckwrv   r/   r0   config_handler  s   z@ConfigHandler._deprecated_config_handler.<locals>.config_handlerr   )r~   r   rv   r   r   r/   r   r0   _deprecated_config_handler  s   z(ConfigHandler._deprecated_config_handler)r   ry   )r   
__module____qualname____doc__r!   __annotations__rx   r	   r"   AllCommandOptionsr   rV   r   classmethodrz   propertyr   r   r   r   r   r   _Pathr   r   r   r   r   r   rW   r   r/   r/   r/   r0   r5      sJ   
 



	



r5   c                       sp   e Zd ZdZdddddZdZ	 dejfd	d
dede	de
jdee def fddZedd Zdd Z  ZS )rT   rY   urldescriptionclassifiers	platforms)	home_pagesummary
classifierplatformFNrC   r   r^   r+   r]   rX   r   c                    s"   t  |||| || _|| _d S ry   )superr   rX   r   )r~   rC   r^   r+   r]   rX   r   r   r/   r0   r     s   	
zConfigMetadataHandler.__init__c                 C   sL   | j }t| j| jd}| j}| j}||||| |||d|||| j|dS )r   r   license)r   keywordsprovides	obsoletesr   r   license_filesr   long_descriptionversionproject_urls)r   r   r   r   r   r   r   _parse_version)r~   
parse_list
parse_file
parse_dictexclude_files_parserr/   r/   r0   r   #  s    
zConfigMetadataHandler.parsersc                 C   sh   |  || j}||kr(| }zt| W |S  ty'   td| d| w t| || j	| jS )zSParses `version` option value.

        :param value:
        :rtype: str

        zVersion loaded from z does not comply with PEP 440: )
r   r   r   r   r   r   r   r   r   rX   )r~   rR   r   r/   r/   r0   r  9  s   
z$ConfigMetadataHandler._parse_version)r   r   r   rN   rx   strict_moder7   curdirr   boolr   rV   r   rL   r   r   r   r   r  __classcell__r/   r/   r   r0   rT     s6    
rT   r   c                       s   e Zd ZdZdddededejf fddZe	dd	 Z
d
d ZdedefddZedd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Z  ZS )$rU   r^   rC   r    r+   r]   c                    s$   t  |||| |j| _i | _d S ry   )r   r   rZ   r   rX   r}   r   r/   r0   r   V  s   
zConfigOptionsHandler.__init__c                 C   s   | j |ddS )N;)r   )r   r   r/   r/   r0   _parse_list_semicolona  s   z*ConfigOptionsHandler._parse_list_semicolonc                 C   s   | j || jdS )Nr   )r   r   )r~   rR   r/   r/   r0   _parse_file_in_roote  s   z(ConfigOptionsHandler._parse_file_in_rootr`   rR   c                 C   s*   |  | |}t||| dd |D S )Nc                 S   s   g | ]	}| d s|qS )#rf   )rh   r   r/   r/   r0   r   n  s    zAConfigOptionsHandler._parse_requirements_list.<locals>.<listcomp>)r  r  rw   )r~   r`   rR   rb   r/   r/   r0   _parse_requirements_listh  s   z-ConfigOptionsHandler._parse_requirements_listc                 C   sT   | j }| j}| j}| j}||||||| |dt| jd| j| j| j| j	|t
|dS )r   zeThe namespace_packages parameter is deprecated, consider using implicit namespaces instead (PEP 420).install_requires)zip_safeinclude_package_datarX   scriptseager_resourcesdependency_linksnamespace_packagesr  setup_requirestests_requirepackagesentry_points
py_modulespython_requirescmdclass)r   r   r   _parse_cmdclassr   r   r  r  _parse_packagesr  r   )r~   r  
parse_boolr  parse_cmdclassr/   r/   r0   r   p  s2   zConfigOptionsHandler.parsersc                 C   s   | j j}t| ||| jS ry   )r]   rX   r   r  r   r   )r~   rR   rX   r/   r/   r0   r    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_dirNr/   )
r   r   parse_section_packages__findr{   r   r\   r   rX   r   find_packages)r~   rR   find_directivestrimmed_valuefind_kwargsr/   r/   r0   r    s   

z$ConfigOptionsHandler._parse_packagesc                    sR   |  || j}g d t 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$   g | ]\}}| v r|r||fqS r/   r/   )rh   kr   
valid_keysr/   r0   r     s   $ zEConfigOptionsHandler.parse_section_packages__find.<locals>.<listcomp>r(  Nr   )r   r   rL   r   r   )r~   r   section_datar'  r(  r/   r,  r0   r#    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   rb   r/   r/   r0   parse_section_entry_points  s   z/ConfigOptionsHandler.parse_section_entry_pointsc                 C   s   |  || j}t|S ry   )r   r   r   canonic_package_data)r~   r   package_datar/   r/   r0   _parse_package_data  s   
z(ConfigOptionsHandler._parse_package_datac                 C      |  || d< dS )z`Parses `package_data` configuration file section.

        :param dict section_options:
        r2  Nr3  r~   r   r/   r/   r0   parse_section_package_data     z/ConfigOptionsHandler.parse_section_package_datac                 C   r4  )zhParses `exclude_package_data` configuration file section.

        :param dict section_options:
        exclude_package_dataNr5  r6  r/   r/   r0   "parse_section_exclude_package_data  r8  z7ConfigOptionsHandler.parse_section_exclude_package_datac                    s      | fdd}| d< dS )zbParses `extras_require` configuration file section.

        :param dict section_options:
        c                    s     d|  d|S )Nzextras_require[r   )r  )r+  r   r   r/   r0   r     r   zCConfigOptionsHandler.parse_section_extras_require.<locals>.<lambda>extras_requireNr   r/  r/   r   r0   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   r/  r/   r/   r0   parse_section_data_files  s   z-ConfigOptionsHandler.parse_section_data_files)r   r   r   rN   r   r  r   rV   r   r   r  r  r!   r  r   r   r  r  r#  r0  r3  r7  r:  r<  r?  r	  r/   r/   r   r0   rU   S  s4    

 rU   c                   @   s$   e Zd ZdZdZdZedd ZdS )rp   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   docsr/   r/   r0   rs      s   z_AmbiguousMarker.messageN)r   r   r   rD  rE  rB  r   rs   r/   r/   r/   r0   rp     s    rp   c                   @   s   e Zd ZdZdS )r   z!userguide/declarative_config.htmlN)r   r   r   rB  r/   r/   r/   r0   r     s    r   )FF)r/   F)F)@r   r   rF   r7   collectionsr   r   r   typingr   r   r   r	   r
   r   r   r   r   r   r   r   errorsr   r   extern.packaging.markersr   rm   extern.packaging.requirementsr   r   extern.packaging.specifiersr   extern.packaging.versionr   r   warningsr   r   r   distutils.distr   r&   r    r!   PathLiker   SingleCommandOptionsr   r"   rL   r1   r3   r  r(   rK   r)   r?   r   rw   r5   rT   rU   rp   r   r/   r/   r/   r0   <module>   s|    
8


.   #M  