HEX
Server: Apache/2.4.65 (Debian)
System: Linux kubikelcreative 5.10.0-35-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64
User: www-data (33)
PHP: 8.4.13
Disabled: NONE
Upload Files
File: //usr/share/dh-python/dhpython/build/__pycache__/base.cpython-39.pyc
a

��:`�,�@s�ddlZddlmZddlmZddlmZmZddlm	Z	m
Z
mZddlm
Z
mZddlmZmZmZddlmZzdd	lmZWney�d
d�ZYn0e�d�Zddd�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!srZdhpython�{build_dir}�){home_dir}/testfiles_to_rm_before_install��test�testscs���fdd�}|S)Ncst������fdd��}|S)Nc
	s�ddh}dD]�}|j|dj|d|djd�}t|dd�|��}t|�rt|d	d
��2}dd�|��D�}Wd�q�Wd�q1s�0Yqt�}	|D]�}
t|d|
�}t�jfi|��|
�d
d�d�}t|�r�t|��st	|��rt
||�n
t||�|	�|d�|ds�d|dvr�|j
j�s@|j
jr�|
�vr�|
|d<q�|	�r���r�t�jfi|��d��}|�|	�Wd�n1�s�0Y�|||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>�/�����
�argsZPYBUILD_TEST_ARGS�ENV�a)�format�name�majorr	r�open�	readlines�set�rsplitrrr
�add�cfg�test_pytest�	test_nose�
writelines)
�self�contextr-�oargs�kwargsZ
files_to_copy�tpl�fpath�fpZfiles_to_remover1Z	src_dpathZ	dst_dpath)�add_to_args�dest�filelist�funcrr�__copy_test_files/sB�0"


���
*zDcopy_test_files.<locals>._copy_test_files.<locals>.__copy_test_filesr)rFrG�rCrDrE�rFr�_copy_test_files-s#z)copy_test_files.<locals>._copy_test_filesr)rDrErCrJrrHr�copy_test_files)s'rKc@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>�pythonzpython{version}zpython{version}-dbg�python3z
python-dbgzpython3-dbgz
.pytest_cachez	.coveragecCs
||_dS)N)r8)r<r8rrr�__init__nsz
Base.__init__cCs
d|jS)NzBuildSystem(%s))�NAME)r<rrr�__repr__qsz
Base.__repr__cCsD|jD]8}td|gttd�}|��\}}|jdkrtd|��qdS)NZwhich)�stdout�stderrrzmissing command: %s)�REQUIRED_COMMANDSr
rZcommunicate�
returncode�	Exception)�cls�commandZprocess�out�errrrr�	is_usablets


zBase.is_usablec	Cs�d}d}i|_|jD]N}d}|�d�D].}t|d|�}|r&d}|j�|g��|�q&|r|d7}q|jr�|t|t|j�d�7}i|_|j	�
�D]6\}}t|d|�}|r�||7}|j�|g��|�q�|dkr�dS|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)ZDETECTED_REQUIRED_FILES�REQUIRED_FILES�splitr�
setdefault�extend�int�lenZDETECTED_OPTIONAL_FILES�OPTIONAL_FILES�items)	r<r=�resultZrequired_files_numr@�foundZftpl�resZscorerrr�detect|s.


zBase.detectc
Cs�|jjrJt|dd�}t|�rJzt|�WntyHt�d|�Yn0|jD]|}t|d|�}t|�r�zt|�Wq�ty�t�d|�Yq�0qPt	|�rPzt
|�WqPty�t�d|�YqP0qPt|d�D]�\}}}|D]Z}	|	dkr�t||	�}
t�d|
�zt|
�Wn t�y6t�d|
�Yq�0|�
|	�q�|D]V}|�d��rHt||�}t�d|�zt
|�Wn t�y�t�d|�Yn0�qHq�dS)Nr!z.toxzcannot remove %s�__pycache__zremoving dir: %s)z.pycz.pyozremoving: %s)
r8�test_toxr	rrrV�log�debug�CLEAN_FILESrrr�endswith)r<r=r-Ztox_dir�fn�path�root�dirsZ
file_namesr1ZdpathrArrr�clean�sJ


z
Base.cleancCstd|j��dS)Nz&configure method not implemented in %s��NotImplementedErrorrP�r<r=r-rrr�	configure�szBase.configurecCstd|j��dS)Nz$install method not implemented in %srvrxrrr�install�szBase.installcCstd|j��dS)Nz"build method not implemented in %srvrxrrr�build�sz
Base.buildcCs\|jjrdS|jjrdS|jjr$dS|jjr0dS|ddksT|dd?sT|dd	krXd
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}zHcd {build_dir}; tox -c {dir}/tox.ini -e py{version.major}{version.minor}rz2.7z3.1rZpypyz<cd {build_dir}; {interpreter} -m unittest discover -v {args})r8Z
test_nose2r:r9rlrxrrrr�s$z	Base.testNcCsb|dur|jjrd}|jfi|��}t|d�}d|vrF|�|d�t�|�t||d||�S)NFr.r!)r8Zreally_quietr0�dict�updaterm�infor)r<r=r-rX�log_file�envrrrr�s
zBase.executec
Cs�|j}t|j�dkrjt|j�dkrjd|jdvrj|jd}d|vrXt|jfi|���q�t|�|d��nH|jD]@}d|vr�t|jfi|���qptd�|d||�|d���qpdS)Nr*z	{version}r�{rz	{} {}: {}r)r8rd�
print_argsr�printr0�get)r<r=r-r8rrrrr��s*

zBase.print_args)N)�__name__�
__module__�__qualname__�__doc__ZDESCRIPTIONrTr_reZSUPPORTED_INTERPRETERSrorOrQ�classmethodr[rjruryrzr{rKrrr�rrrrrLWs(

%*


rLcst���fdd��}|S)Nc
	s�|�dd�}|s8�|||g|�Ri|��}t|t�r8|S|sbt�d|j�j|�d�|�d��|S|jj	r�t
|dd��j��}nd}tdd	�|�
�D��}|jfi|��}|�||||�}|d
dkr�d�|d
|�}	|r�|	d
�|�7}	t|	��dS)NrXzBmissing command (plugin=%s, method=%s, interpreter=%s, version=%s)rrZhome_dirz
{}_cmd.logFcss8|]0\}}|dvs|�d�r(|t|�fn||fVqdS))r!ZdestdirZ_dirN)rpr)r&�krrrr�	<genexpr>s
��z6shell_command.<locals>.wrapped_func.<locals>.<genexpr>rUrzexit code={}: {}z$
full command log is available in {}T)�pop�
isinstancercrm�warnrPr�r�r8�quietr	r0r|rfrrV)
r<r=r-r>r?rXrZquoted_args�output�msgrIrr�wrapped_func�s2
��z#shell_command.<locals>.wrapped_funcr)rFr�rrIr�
shell_command�sr�)rrr)Zlogging�	functoolsrZglobr�osrr�os.pathrrr	�
subprocessr
rZshutilrr
rZdhpython.toolsrZshlexr�ImportErrorZ	getLoggerrmrKrLr�rrrr�<module>s&
�
.%