HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/share/dh-python/dhpython/build/__pycache__/base.cpython-310.pyc
o

O�Ibh.�@s�ddlZddlmZddlmZddlmZmZddlm	Z	m
Z
mZddlm
Z
mZddlmZmZmZddlmZzdd	lmZWn
eyOd
d�ZYnwe�d�Z	
		ddd�ZGdd�d�Zdd�ZdS)�N��wraps)�glob1)�remove�walk)�exists�isdir�join)�Popen�PIPE)�rmtree�copyfile�copytree)�execute)�quotecCs|sdSd|�dd�dS)Nz''�'z'"'"')�replace)�s�r�+/usr/share/dh-python/dhpython/build/base.pyr!sr�dhpython�{build_dir}�){home_dir}/testfiles_to_rm_before_install��test�testscs���fdd�}|S)Ncst������fdd��}|S)Nc
	s�ddh}dD]A}|j|dj|d|djd�}t|dd�|��}t|�rGt|d	d
��}dd�|��D�}	Wd�n	1sBwYqt�}	|D]R}
t|d|
�}t�jdi|��|
�d
d�d�}t|�r�t|�s�t	|�ryt
||�nt||�|	�|d�|ds�d|dvr�|j
js�|j
jr�|
�vr�|
|d<qM|	rĈr�t�jdi|��d��
}|�|	�Wd�n1s�wY�|||g|�Ri|��S)Nrr)z_{i}{v}z_{i}{m}��interpreter�version)�i�v�m�dirzdebian/pybuild{}.testfileszutf-8)�encodingcSsg|]}|�d�s|���qS)�#)�
startswith�strip)�.0�linerrr�
<listcomp>;s�zXcopy_test_files.<locals>._copy_test_files.<locals>.__copy_test_files.<locals>.<listcomp>�/�����
�args�PYBUILD_TEST_ARGS�ENV�ar)�format�name�majorr	r�open�	readlines�set�rsplitrrr
�add�cfg�test_pytest�	test_nose�
writelines)
�self�contextr.�oargs�kwargs�
files_to_copy�tpl�fpath�fp�files_to_remover3�	src_dpath�	dst_dpath)�add_to_args�dest�filelist�funcrr�__copy_test_files/sH� ��"
����zDcopy_test_files.<locals>._copy_test_files.<locals>.__copy_test_filesr)rLrM�rIrJrK�rLr�_copy_test_files-s#z)copy_test_files.<locals>._copy_test_filesr)rJrKrIrPrrNr�copy_test_files)s'rQc@s�eZdZdZdZgZgZiZhd�ZddhZ	dd�Z
dd	�Zed
d��Z
dd
�Zdd�Zdd�Zdd�Zdd�Ze�dd��Zddd�Zdd�ZdS)�Basea�Base class for build system plugins

    :attr REQUIRED_COMMANDS: list of command checked by default in :meth:is_usable,
        if one of them is missing, plugin cannot be used.
    :type REQUIRED_COMMANDS: list of strings
    :attr REQUIRED_FILES: list of files (or glob templates) required by given
        build system
    :attr OPTIONAL_FILES: dictionary of glob templates (key) and score (value)
        used to detect if given plugin is the best one for the job
    :type OPTIONAL_FILES: dict (key is a string, value is an int)
    :attr SUPPORTED_INTERPRETERS: set of interpreter templates (with or without
        {version}) supported by given plugin
    r>�
python-dbg�python3-dbg�python{version}�python{version}-dbg�python�python3z
.pytest_cachez	.coveragecCs
||_dS�N)r:)r>r:rrr�__init__n�
z
Base.__init__cCs
d|jS)NzBuildSystem(%s))�NAME)r>rrr�__repr__qr[z
Base.__repr__cCsD|jD]}td|gttd�}|��\}}|jdkrtd|��qdS)N�which)�stdout�stderrrzmissing command: %s)�REQUIRED_COMMANDSr
r�communicate�
returncode�	Exception)�cls�command�process�out�errrrr�	is_usablets

��zBase.is_usablec	Cs�d}d}i|_|jD]'}d}|�d�D]}t|d|�}|r*d}|j�|g��|�q|r1|d7}q
|jrB|t|t|j�d�7}i|_|j	�
�D]\}}t|d|�}|re||7}|j�|g��|�qJ|dkrldS|S)	aJReturn certainty level that this plugin describes the right build system

        This method is using cls.{REQUIRED,OPTIONAL}_FILES only by default,
        please extend it in the plugin if more sofisticated methods can be used
        for given build system.

        :return: 0 <= certainty <= 100
        :rtype: int
        rF�|r"Tr+�2�d)�DETECTED_REQUIRED_FILES�REQUIRED_FILES�splitr�
setdefault�extend�int�len�DETECTED_OPTIONAL_FILES�OPTIONAL_FILES�items)	r>r?�result�required_files_numrC�found�ftpl�res�scorerrr�detect|s4

���zBase.detectc
Cs�|jjr%t|dd�}t|�r%zt|�Wnty$t�d|�Ynw|jD]=}t|d|�}t|�rKzt|�Wq(tyJt�d|�Yq(wt	|�rezt
|�Wq(tydt�d|�Yq(wq(t|d�D]_\}}}|D],}	|	dkr�t||	�}
t�d|
�zt|
�Wnty�t�d|
�Yqsw|�
|	�qs|D](}|�d�r�t||�}t�d|�zt
|�Wq�ty�t�d|�Yq�wq�qldS)Nr"z.toxzcannot remove %s�__pycache__zremoving dir: %s)z.pycz.pyozremoving: %s)
r:�test_toxr	rrrd�log�debug�CLEAN_FILESrrr�endswith)r>r?r.�tox_dir�fn�path�root�dirs�
file_namesr3�dpathrDrrr�clean�s^�
���
�
�

����z
Base.cleancC�td|j��)Nz&configure method not implemented in %s��NotImplementedErrorr\�r>r?r.rrr�	configure��zBase.configurecCr�)Nz$install method not implemented in %sr�r�rrr�install�r�zBase.installcCr�)Nz"build method not implemented in %sr�r�rrr�build�r�z
Base.buildcCs�|jjrdS|jjrdS|jjrdS|jjr't|dd�}t|�r%t|�dS|jjr-dS|dd	ks?|dd
?s?|ddkrAd
SdS)Nz0cd {build_dir}; {interpreter} -m nose2 -v {args}z/cd {build_dir}; {interpreter} -m nose -v {args}z.cd {build_dir}; {interpreter} -m pytest {args}�home_dirz.pydistutils.cfgz^cd {build_dir}; tox -c {dir}/tox.ini --sitepackages -e py{version.major}{version.minor} {args}zcd {build_dir}; {args}rz2.7z3.1r�pypyz<cd {build_dir}; {interpreter} -m unittest discover -v {args})	r:�
test_nose2r<r;r�r	rr�test_custom)r>r?r.�pydistutils_cfgrrrr�s $�z	Base.testNcCsb|dur
|jjr
d}|jdi|��}t|d�}d|vr#|�|d�t�|�t||d||�S)NFr0r"r)r:�really_quietr2�dict�updater��infor)r>r?r.rf�log_file�envrrrr�s
zBase.executec
Cs�|j}t|j�dkr7t|j�dkr7d|jdvr7|jd}d|vr-t|jdi|���dSt|�|d��dS|jD] }d|vrKt|jdi|���q:td�|d||�|d���q:dS)	Nr+z	{version}r�{rz	{} {}: {}rr)r:rt�
print_argsr�printr2�get)r>r?r.r:rrrrr��s*

 �zBase.print_argsrY)�__name__�
__module__�__qualname__�__doc__�DESCRIPTIONrarorv�SUPPORTED_INTERPRETERSr�rZr]�classmethodrjr~r�r�r�r�rQrrr�rrrrrRWs*

%*


rRcst���fdd��}|S)Nc
	s�|�dd�}|s�|||g|�Ri|��}t|t�r|S|s1t�d|j�j|�d�|�d��|S|jj	rAt
|dd��j��}nd}tdd	�|�
�D��}|jdi|��}|�||||�}|d
dkryd�|d
|�}	|ru|	d
�|�7}	t|	��dS)NrfzBmissing command (plugin=%s, method=%s, interpreter=%s, version=%s)rrr�z
{}_cmd.logFcss:�|]\}}|dvs|�d�r|t|�fn||fVqdS))r"�destdir�_dirN)r�r)r'�kr rrr�	<genexpr>s���
�z6shell_command.<locals>.wrapped_func.<locals>.<genexpr>rcrzexit code={}: {}z$
full command log is available in {}Tr)�pop�
isinstancersr��warnr\r�r�r:�quietr	r2r�rwrrd)
r>r?r.r@rArfr��quoted_args�output�msgrOrr�wrapped_funcs2
��z#shell_command.<locals>.wrapped_funcr)rLr�rrOr�
shell_commandsr�)rrr)�logging�	functoolsr�globr�osrr�os.pathrrr	�
subprocessr
r�shutilrr
r�dhpython.toolsr�shlexr�ImportError�	getLoggerr�rQrRr�rrrr�<module>s*�

�.,