U
    [e\                     @   sn  d Z zddlZW n ek
r$   Y nX ddlZddlm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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 zddlZW n ek
r   ddlZY nX ddlmZ ddlZed	Zd
ZdZdZdZdZ dd Z!dd Z"d&ddZ#d'ddZ$dd Z%dd Z&dd Z'dd Z(d d! Z)d"d# Z*G d$d% d%eZ+dS )(a  The code in this module is mostly copy/pasted out of the distutils2 source
code, as recommended by Tarek Ziade.  As such, it may be subject to some change
as distutils2 development continues, and will have to be kept up to date.

I didn't want to use it directly from distutils2 itself, since I do not want it
to be an installation dependency for our packages yet--it is still too unstable
(the latest version on PyPI doesn't even install).
    N)defaultdict)errors)log)dist)	extension)extra_filesz\s*(.*?)\s*\((.*)\)\s*$)#))metadatanamer	   ))r   versionr
   ))r   authorr   ))r   author_emailr   ))r   
maintainerr   ))r   maintainer_emailr   ))r   Z	home_pageurl))r   project_urlsr   ))r   summarydescription))r   keywordsr   ))r   r   long_description))r   Zdescription_content_typeZlong_description_content_type))r   download_urlr   ))r   
classifierclassifiers))r   platform	platforms))r   licenser   ))r   Zrequires_distinstall_requires))r   Zsetup_requires_distsetup_requires))r   python_requiresr   ))r   requires_pythonr   ))r   Zprovides_distprovides))r   provides_extrasr    ))r   Zobsoletes_dist	obsoletes))filespackages_rootpackage_dir))r"   packagesr%   ))r"   package_datar&   ))r"   namespace_packagesr'   ))r"   
data_filesr(   ))r"   scriptsr)   ))r"   modules
py_modules))globalcommandscmdclass))backwards_compatzip_safer0   ))r/   tests_requirer1   ))r/   dependency_linksr2   ))r/   include_package_datar3   )r   r   r   r   r!   r'   r%   r&   r(   r)   r+   r2   r   r1   r   r.   r    )r   )r0   r3    c                 C   s4   t jdkr*| dd} dd t| D S t| S )Nnt\/c                 S   s   g | ]}| d dqS )r7   r6   )replace).0xr4   r4   J/var/www/html/services/stratfitenv/lib/python3.8/site-packages/pbr/util.py
<listcomp>   s     zshlex_split.<locals>.<listcomp>)osr	   r8   shlexsplit)pathr4   r4   r;   shlex_split   s    
rA   c              	   C   s   |  d}t|d }|d| }|d }|dkrztd||gd}W qW q* tk
r   |dkrh |d8 }|d| }|| }d}Y q*X q*||d D ]0}zt||}W q tk
r   t| Y qX q|S )zResolve a name like ``module.object`` to an object and return it.

    Raise ImportError if the module or name is not found.
    .   Nr   )fromlist )r?   len
__import__joinImportErrorgetattrAttributeError)r	   partscursormodule_name	attr_nameretpartr4   r4   r;   resolve_name   s*    
rS   	setup.cfgc              	   C   s(  t jdkrt }nt }tj| s>t	dtj
|  z|j| dd W n tk
rn   ||  Y nX i }| D ]6}t ||< ||D ]\}}||| |dd< qq|t|dd}t|d	d
}|rtj
|}t jd| z"|rdd t|D }|D ]}	t|	}
z|
| W nj tk
rB   td Y nL tk
r   t  d }td|	|f  tt  t d Y nX q
tj | t!||}d|d< d|d< t"| t#|}|r||d< t$|}|r||d< t|d	d}|rt%&t| W 5 |r"t jd X |S )a  Distutils2 to distutils1 compatibility util.

    This method uses an existing setup.cfg to generate a dictionary of
    keywords that can be used by distutils.core.setup(kwargs**).

    :param path:
        The setup.cfg path.
    :param script_args:
        List of commands setup.py was called with.
    :raises DistutilsFileError:
        When the setup.cfg file is not found.
    )   r   zfile '%s' does not existutf-8encoding-_r,   setup_hooksr"   r#   r   c                 S   s   g | ]}|d kr|qS )zpbr.hooks.setup_hookr4   )r9   hookr4   r4   r;   r<      s   zcfg_to_args.<locals>.<listcomp>z)setup hook %s terminated the installationrC   z#setup hook %s raised exception: %s
Tr3   Fr0   ext_modulesentry_pointsr   )'sysversion_infoconfigparserConfigParserSafeConfigParserr=   r@   existsr   DistutilsFileErrorabspathread	TypeErrorsectionsdictitemsr8   has_get_optioninsertpopsplit_multilinerS   
SystemExitr   error	Exceptionexc_info	traceback
format_excexitpbrhooksZ
setup_hooksetup_cfg_to_setup_kwargsregister_custom_compilersget_extension_modulesget_entry_pointsr   Zset_extra_files)r@   script_argsparserconfigsectionkvaluer[   r$   r\   Zhook_fnekwargsr]   r^   Zfiles_extra_filesr4   r4   r;   cfg_to_args   sp    




r   c           *   
   C   s2  i }i }t D ]\}}|\}}t| ||}|s|dkrt| |d}|rt|}d}	|D ]6}
tj|
dd}z|	|  d 7 }	W 5 |  X qV|	}|sq|tkrt	|}|t
krt|}nb|tkri }t|D ]$}|dd\}}| || < q|}n"|tkr| d	krd
}nd}|r|dkr:dd |D }|dkrg }d}|D ]<}t||}|d }|d }|||f qP||d< n2|dkrd|i}n|dkri }d
}d}|D ]}d|kr>|dd\}}	t| d }||	  }}	||kr(|| }|t|	 nt|	 }|| < n(|rTtd| n|t|  d}q|dkrt| }|}nB|dkri }t }|D ]"}t|}||} |||  < q|}|||< qd| krd}| d }!d|!kr ddlm}" d|" |"j!"dd |!d< |!D ]\}#g }$t|!|# }%|%D ]8}t||}|d }&|d}|$|&|f q<|$||#< q$i }'|D ]}(||( D ]z\}}|rd!|(|f })d"|krzt#$d#| r|(})W n" t%k
r   t&'d$  Y nX n|(})|'(|)g | qq|')dg |d< |'|d%< |S )&zConvert config options to kwargs.

    Processes the setup.cfg options and converts them to arguments accepted
    by setuptools' setup() function.
    r   description_filerF   rV   rW   z

=rC   )truet1yesyTF)r   r1   c                 S   s   g | ]}t d |qS )z\1\2)_VERSION_SPEC_REsub)r9   predr4   r4   r;   r<   e  s   z-setup_cfg_to_setup_kwargs.<locals>.<listcomp>r   z6(?P<package>[^;]*);?(?P<env_marker>[^#]*?)(?:\s*#.*)?$package
env_markerr$   )r&   r(   Nr   z1malformed package_data first line %r (misses "=")r(   r.   extrasz6(?P<package>[^:]*):?(?P<env_marker>[^#]*?)(?:\s*#.*)?$test)	packaging
;:z%s:(%s)bdist_wheelz(%s)zMarker evaluation failed, see the following error.  For more information see: http://docs.openstack.org/pbr/latest/user/using.html#environment-markersextras_require)*CFG_TO_PY_SETUP_ARGSrl   ro   ioopencloserg   strip
CSV_FIELDS	split_csvMULTI_FIELDS
MAP_FIELDSr?   BOOL_FIELDSlowerrematchgroupappendrA   extendr   DistutilsOptionErrorsortedrk   st_distDistributionrS   get_command_namerw   r   rI   parse_requirementsZTEST_REQUIREMENTS_FILESr8   pkg_resourcesevaluate_markerSyntaxErrorr   rq   
setdefaultrn   )*r   r}   r   all_requirementsaliasargr   optionZin_cfg_valuer   filenamer   Z
in_cfg_mapir   vr   Zrequirement_patternrequirementmZrequirement_packager   r(   	firstlineprevlinekeyZkey_unquotedr.   r   cls_nameclscmdr   r   extraZextra_requirementsrequirementsZextras_valuer   Z	req_groupZ
extras_keyr4   r4   r;   ry   /  s    












 



ry   c                 C   s   t | dd}|rt|}|D ]p}t|}t|dr:|j}n|j}t|drR|j}nd| }|j}tj	j
}||j|f||< tj| tjd| < qdS )zHandle custom compilers.

    This has no real equivalent in distutils, where additional compilers could
    only be added programmatically, so we have to hack it in somehow.
    r,   	compilersr	   r   zcustom compiler %sz
distutils.N)rl   ro   rS   hasattrr	   __name__r   
__module__	distutilsZ	ccompilerZcompiler_classr_   r*   )r   r   compilerr	   descrO   ccr4   r4   r;   rz     s    

rz   c           
      C   s*  d}g }| D ]}d|kr(| dd}n| dd}dd |D }t|dkr|d d	kri }|D ]}t| ||}|sxqbt|}|d
krg }|D ]P}	|	 dd}	t|	dkr|	d  df}	n|	d  |	d  f}	||	 q|}|||< qb|rd|kr
|d |d< |tj|df| q|S )zHandle extension modules)sourcesinclude_dirsdefine_macrosundef_macroslibrary_dirs	librariesruntime_library_dirsextra_objectsextra_compile_argsextra_link_argsexport_symbols	swig_optsdependsr   rC   r   c                 S   s   g | ]}|  qS r4   r   )r9   labelr4   r4   r;   r<     s     z)get_extension_modules.<locals>.<listcomp>   r   r   r   Nr	   )	r?   rG   rl   ro   r   r   r   	Extensionrn   )
r   ZEXTENSION_FIELDSr]   r   labelsZext_argsfieldr   macrosmacror4   r4   r;   r{     s>    


r{   c                 C   s&   d| kri S t dd | d  D S )a  Process the [entry_points] section of setup.cfg.

    Processes setup.cfg to handle setuptools entry points. This is, of course,
    not a standard feature of distutils2/packaging, but as there is not
    currently a standard alternative in packaging, we provide support for them.
    r^   c                 s   s   | ]\}}|t |fV  qd S N)ro   )r9   r   r   r4   r4   r;   	<genexpr>G  s   z#get_entry_points.<locals>.<genexpr>)rj   rk   )r   r4   r4   r;   r|   <  s
    
r|   c                 C   s(   || kr || | kr | | | S dS d S )NFr4   )r   r   r   r4   r4   r;   rl   K  s    rl   c                 C   s"   dd dd |  dD D } | S )z3Special behaviour when we have a multi line optionsc                 S   s   g | ]}|r| d s|qS )#)
startswithr9   elementr4   r4   r;   r<   U  s     
z#split_multiline.<locals>.<listcomp>c                 s   s   | ]}|  V  qd S r   r   )r9   r   r4   r4   r;   r   V  s     z"split_multiline.<locals>.<genexpr>r   r?   r   r4   r4   r;   ro   R  s    ro   c                 C   s"   dd dd |  dD D } | S )z8Special behaviour when we have a comma separated optionsc                 S   s   g | ]}|r|qS r4   r4   r   r4   r4   r;   r<   ^  s    zsplit_csv.<locals>.<listcomp>c                 s   s   | ]}|  V  qd S r   r   )r9   chunkr4   r4   r;   r   _  s     zsplit_csv.<locals>.<genexpr>,r   r   r4   r4   r;   r   [  s    r   c                       s"   e Zd ZdZd fdd	Z  ZS )DefaultGetDictzDLike defaultdict, but get() also sets and returns the default value.Nc                    s"   |d kr|   }tt| ||S r   )default_factorysuperr   r   )selfr   default	__class__r4   r;   geth  s    zDefaultGetDict.get)N)r   r   __qualname____doc__r   __classcell__r4   r4   r   r;   r   e  s   r   )rT   r4   )r4   ),r   multiprocessingrJ   loggingcollectionsr   r   r=   r   r>   r_   rt   distutils.ccompilerr   r   r   r   
setuptoolsr   r   r   rb   ra   rw   r   Z	pbr.hookscompiler   r   r   r   r   r   rA   rS   r   ry   rz   r{   r|   rl   ro   r   r   r4   r4   r4   r;   <module>.   sT   
.
 
_
 6#5	
