o
    ugqZ                     @   s  d dl Z d dlZd dlZd dl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 d dlZd dlmZmZ d dlmZmZ d dlmZ G d	d
 d
Zejdd ZdddZdd Zdd ZdddZG dd dZG dd deZG dd deZdS )    N)defaultdict)partialwraps)iglob)DistutilsOptionErrorDistutilsFileError)VersionInvalidVersion)SpecifierSetc                   @   s    e Zd ZdZdd Zdd ZdS )StaticModulez0
    Attempt to load the module by the name
    c                 C   s`   t j|}t|j}| }W d    n1 sw   Y  t|}t| 	t
  | `d S N)	importlibutil	find_specopenoriginreadastparsevarsupdatelocalsself)r   namespecstrmsrcmodule r   S/var/www/html/ecg_monitoring/venv/lib/python3.10/site-packages/setuptools/config.py__init__   s   

zStaticModule.__init__c              
      sN   zt  fdd| jjD W S  ty& } ztdjdi t |d }~ww )Nc                 3   sJ    | ] }t |tjr"|jD ]}t |tjr!|j krt|jV  qqd S r   )
isinstancer   AssigntargetsNameidliteral_evalvalue).0	statementtargetattrr   r    	<genexpr>#   s    



z+StaticModule.__getattr__.<locals>.<genexpr>z#{self.name} has no attribute {attr}r   )nextr   body	ExceptionAttributeErrorformatr   )r   r-   er   r,   r    __getattr__!   s   
zStaticModule.__getattr__N)__name__
__module____qualname____doc__r!   r5   r   r   r   r    r      s    r   c              	   c   s8    zt jd|  dV  W t j|  dS t j|  w )zH
    Add path to front of sys.path for the duration of the context.
    r   N)syspathinsertremove)r;   r   r   r    
patch_path0   s
   r>   Fc           	   	   C   s   ddl m}m} tj| } tj| std|  t }t	tj
|  z-| }|r1| ng }| |vr<||  |j||d t||j|d}W t	| t|S t	| w )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   )Distribution_Distributionz%Configuration file %s does not exist.)	filenames)ignore_option_errors)setuptools.distr?   r@   osr;   abspathisfiler   getcwdchdirdirnamefind_config_filesappendparse_config_filesparse_configurationcommand_optionsconfiguration_to_dict)	filepathfind_othersrB   r?   r@   current_directorydistrA   handlersr   r   r    read_configuration<   s$   

rU   c                 C   s2   dj di t }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.
    z	get_{key}Nr   )r3   r   	functoolsr   getattr)
target_objkeygetter_nameby_attributegetterr   r   r    _get_optioni   s   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_optionsr]   rX   section_prefix)rT   config_dicthandleroptionr(   r   r   r    rO   u   s   
rO   c                 C   s6   t | ||}|  t| j||| j}|  ||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
    )ConfigOptionsHandlerr   ConfigMetadataHandlermetadatapackage_dir)distributionrN   rB   optionsmetar   r   r    rM      s   rM   c                   @   s   e Zd ZdZdZ	 i Z	 d'ddZedd Zdd	 Z	e
d(ddZe
d(ddZe
dd Ze
dd Ze
dd Ze
dd Zedd Zedd Ze
d)ddZe
dd Ze
d)dd Zd!d" Zd#d$ Zd%d& ZdS )*ConfigHandlerz1Handles metadata supplied in configuration files.NFc                 C   s^   i }| j }| D ]\}}||sq	||dd}|||< q	|| _|| _|| _g | _d S )N .)	r`   items
startswithreplacestriprB   rX   sectionsr_   )r   rX   ri   rB   rr   r`   section_namesection_optionsr   r   r    r!      s   


zConfigHandler.__init__c                 C   s   t d| jj ).Metadata item name to parser function mapping.z!%s must provide .parsers property)NotImplementedError	__class__r6   )r   r   r   r    parsers   s   
zConfigHandler.parsersc           	      C   s   t  }| j}| j||}t|||}||u rt||rd S d}| j|}|r?z||}W n ty>   d}| js< Y nw |rCd S t|d| d }|d u rVt	||| n|| | j
| d S )NFTzset_%s)tuplerX   aliasesgetrW   KeyErrorrx   r1   rB   setattrr_   rK   )	r   option_namer(   unknownrX   current_valueskip_optionparsersetterr   r   r    __setitem__   s4   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
        
c                 S   s   g | ]
}|  r|  qS r   )rq   )r)   chunkr   r   r    
<listcomp>  s    z-ConfigHandler._parse_list.<locals>.<listcomp>)r"   list
splitlinessplit)clsr(   	separatorr   r   r    _parse_list   s   



zConfigHandler._parse_listc              	      sj   d}| j  |d}g }|D ]% t fdd|D r-|tdd ttj D  q|  q|S )a  Equivalent to _parse_list() but expands any glob patterns using glob().

        However, unlike with glob() calls, the results remain relative paths.

        :param value:
        :param separator: List items separator character.
        :rtype: list
        )*?[]{}r   c                 3   s    | ]}| v V  qd S r   r   )r)   charr(   r   r    r.     s    z1ConfigHandler._parse_list_glob.<locals>.<genexpr>c                 s   s"    | ]}t j|t  V  qd S r   )rD   r;   relpathrG   r)   r;   r   r   r    r.     s
    
)	r   anyextendsortedr   rD   r;   rE   rK   )r   r(   r   glob_charactersvaluesexpanded_valuesr   r   r    _parse_list_glob  s   
zConfigHandler._parse_list_globc                 C   sP   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: %s)r   	partitionr   rq   )r   r(   r   resultlinerY   sepvalr   r   r    _parse_dict   s   zConfigHandler._parse_dictc                 C   s   |  }|dv S )zQRepresents value as boolean.

        :param value:
        :rtype: bool
        )1trueyes)lower)r   r(   r   r   r    _parse_bool3  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)ro   
ValueErrorr3   )r(   exclude_directiverY   r   r    r   I  s   
z3ConfigHandler._exclude_files_parser.<locals>.parserr   )r   rY   r   r   r   r    _exclude_files_parser=  s   	z#ConfigHandler._exclude_files_parserc                    s\   d}t |ts	|S ||s|S |t|d }dd |dD }d fdd|D 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     | ]}t j| V  qd S r   )rD   r;   rE   rq   r   r   r   r    r.   k  s    z,ConfigHandler._parse_file.<locals>.<genexpr>r   r   c                 3   s4    | ]}  |s	 	 tj|r |V  qdS )TN)_assert_localrD   r;   rF   
_read_filer   r   r   r    r.   l  s    

)r"   strro   lenr   join)r   r(   include_directiver   	filepathsr   r   r    _parse_fileT  s   

zConfigHandler._parse_filec                 C   s   |  t std|  d S )Nz#`file:` directive can not access %s)ro   rD   rG   r   )rP   r   r   r    r   r  s   zConfigHandler._assert_localc                 C   s:   t j| dd}| W  d    S 1 sw   Y  d S )Nzutf-8)encoding)ior   r   )rP   fr   r   r    r   w  s   $zConfigHandler._read_filec              	   C   s0  d}| |s	|S ||d d}| }d|}|p d}t }|ra|d |v rR||d  }|dd}	t	|	dkrOtj
t |	d }|	d }n|}nd|v ratj
t |d }t|& ztt||W W  d   S  ty   t|}
Y nw W d   n1 sw   Y  t|
|S )	zRepresents value as a module attribute.

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

        :param str value:
        :rtype: str
        zattr:rl   rm   r!   r   /   N)ro   rp   rq   r   popr   rD   rG   rsplitr   r;   r>   rW   r   r1   r   import_module)r   r(   rg   attr_directive
attrs_path	attr_namemodule_nameparent_pathcustom_pathpartsr   r   r   r    _parse_attr|  s8   




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   r   )r(   parsedmethodparse_methodsr   r    r     s   
z1ConfigHandler._get_parser_compound.<locals>.parser   )r   r   r   r   r   r    _get_parser_compound  s   
z"ConfigHandler._get_parser_compoundc                 C   s6   i }|pdd }|  D ]\}\}}||||< q|S )zParses section options into a dictionary.

        Optionally applies a given parser to values.

        :param dict section_options:
        :param callable values_parser:
        :rtype: dict
        c                 S   s   | S r   r   )r   r   r   r    <lambda>  s    z6ConfigHandler._parse_section_to_dict.<locals>.<lambda>)rn   )r   rt   values_parserr(   rY   _r   r   r   r    _parse_section_to_dict  s
   
z$ConfigHandler._parse_section_to_dictc              	   C   s8   |  D ]\}\}}z|| |< W q ty   Y qw dS )zQParses configuration file section.

        :param dict section_options:
        N)rn   r|   )r   rt   r   r   r(   r   r   r    parse_section  s   zConfigHandler.parse_sectionc                 C   sb   | j  D ])\}}d}|rd| }t| d| ddd}|du r*td| j|f || qdS )zTParses configuration file items from one
        or more related sections.

        rl   z_%szparse_section%srm   __Nz0Unsupported distribution option section: [%s.%s])rr   rn   rW   rp   r   r`   )r   rs   rt   method_postfixsection_parser_methodr   r   r    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 warning_class: class of warning exception to be raised
        :param func: function to be wrapped around
        c                     s   t   | i |S r   )warningswarn)argskwargsfuncmsgwarning_classr   r    config_handler  s   z@ConfigHandler._deprecated_config_handler.<locals>.config_handlerr   )r   r   r   r   r   r   r   r    _deprecated_config_handler  s   z(ConfigHandler._deprecated_config_handlerF)r   r   )r6   r7   r8   r9   r`   rz   r!   propertyrx   r   classmethodr   r   r   r   r   r   staticmethodr   r   r   r   r   r   r   r   r   r   r   r    rk      sF    

&

	



-
rk   c                       sL   e Zd ZdZdddddZdZ	 	d fd	d
	Zedd Zdd Z	  Z
S )re   rf   urldescriptionclassifiers	platforms)	home_pagesummary
classifierplatformFNc                    s   t t| ||| || _d S r   )superre   r!   rg   )r   rX   ri   rB   rg   rw   r   r    r!     s   

zConfigMetadataHandler.__init__c                 C   s^   | j }| j}| j}| j}|||| |dt|| |||d| |ddt|||| j|dS )ru   z[The requires parameter is deprecated, please use install_requires for runtime dependencies.licenselicense_filezDThe license_file parameter is deprecated, use license_files instead.)r   keywordsprovidesrequires	obsoletesr   r   r   license_filesr   long_descriptionversionproject_urls)r   r   r   r   r   DeprecationWarningr   _parse_version)r   
parse_list
parse_file
parse_dictexclude_files_parserr   r   r    rx     s4   
zConfigMetadataHandler.parsersc                 C   s   |  |}||kr)| }zt| W |S  ty(   d}t|jdi t w | || j}t	|r7| }t
|tsOt|drKdtt|}|S d| }|S )zSParses `version` option value.

        :param value:
        :rtype: str

        zCVersion loaded from {value} does not comply with PEP 440: {version}__iter__rm   z%sNr   )r   rq   r	   r
   r   r3   r   r   rg   callabler"   r   hasattrr   map)r   r(   r   tmplr   r   r    r   ?  s(   

	

z$ConfigMetadataHandler._parse_version)FN)r6   r7   r8   r`   rz   strict_moder!   r   rx   r   __classcell__r   r   r   r    re     s    
!re   c                   @   sd   e Zd Z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dS )rd   ri   c                 C   sN   | j }t| j dd}| j}| j}| j}||||||||||| j| j|t|dS )ru   ;r   )zip_safeinclude_package_datarg   scriptseager_resourcesdependency_linksnamespace_packagesinstall_requiressetup_requirestests_requirepackagesentry_points
py_modulespython_requirescmdclass)r   r   r   r   _parse_cmdclass_parse_packagesr   r   )r   r   parse_list_semicolon
parse_boolr   parse_cmdclassr   r   r    rx   i  s*   zConfigOptionsHandler.parsersc                    s$   dd   fdd|  | D S )Nc                 S   s8   |  d}| |d d  }| d | }t|}t||S )Nrm   r   )rfind
__import__rW   )qualified_class_nameidx
class_namepkg_namer   r   r   r    resolve_class  s
   

z;ConfigOptionsHandler._parse_cmdclass.<locals>.resolve_classc                    s   i | ]	\}}| |qS r   r   r)   kvr"  r   r    
<dictcomp>  s    z8ConfigOptionsHandler._parse_cmdclass.<locals>.<dictcomp>)r   rn   )r   r(   r   r&  r    r    s   	z$ConfigOptionsHandler._parse_cmdclassc                 C   sn   ddg}|  }||vr| |S ||d k}| | jdi }|r*ddlm} nddlm} |d	i |S )
zTParses `packages` option value.

        :param value:
        :rtype: list
        zfind:zfind_namespace:r   zpackages.findr   )find_namespace_packages)find_packagesNr   )rq   r   parse_section_packages__findrr   r{   
setuptoolsr(  r)  )r   r(   find_directivestrimmed_valuefindnsfind_kwargsr)  r   r   r    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   r#  
valid_keysr   r    r     s   $ zEConfigOptionsHandler.parse_section_packages__find.<locals>.<listcomp>r0  Nr   )r   r   r^   rn   r{   )r   rt   section_datar/  r0  r   r3  r    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   rt   r   r   r   r    parse_section_entry_points  s   z/ConfigOptionsHandler.parse_section_entry_pointsc                 C   s.   |  || j}|d}|r||d< |d= |S )Nr   rl   )r   r   r{   )r   rt   r   rootr   r   r    _parse_package_data  s   
z(ConfigOptionsHandler._parse_package_datac                 C      |  || d< dS )z`Parses `package_data` configuration file section.

        :param dict section_options:
        package_dataNr9  r   rt   r   r   r    parse_section_package_data     z/ConfigOptionsHandler.parse_section_package_datac                 C   r:  )zhParses `exclude_package_data` configuration file section.

        :param dict section_options:
        exclude_package_dataNr<  r=  r   r   r    "parse_section_exclude_package_data  r?  z7ConfigOptionsHandler.parse_section_exclude_package_datac                 C   s"   t | jdd}| ||| d< dS )zbParses `extras_require` configuration file section.

        :param dict section_options:
        r  r   extras_requireN)r   r   r   )r   rt   r   r   r   r    parse_section_extras_require  s   z1ConfigOptionsHandler.parse_section_extras_requirec                 C   s(   |  || j}dd | D | d< dS )z^Parses `data_files` configuration file section.

        :param dict section_options:
        c                 S   s   g | ]\}}||fqS r   r   r#  r   r   r    r     s    zAConfigOptionsHandler.parse_section_data_files.<locals>.<listcomp>
data_filesN)r   r   rn   r6  r   r   r    parse_section_data_files  s   z-ConfigOptionsHandler.parse_section_data_filesN)r6   r7   r8   r`   r   rx   r  r  r*  r7  r9  r>  rA  rC  rE  r   r   r   r    rd   e  s    


rd   )FFr   ) r   r   rD   r:   r   rV   r   collectionsr   r   r   globr   
contextlibdistutils.errorsr   r   #setuptools.extern.packaging.versionr	   r
   &setuptools.extern.packaging.specifiersr   r   contextmanagerr>   rU   r]   rO   rM   rk   re   rd   r   r   r   r    <module>   s6    

-
  ca