o
    oÇh¤!  ã                   @   sì   d dl m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m	Z	 dd„ Z
G dd„ deƒZG d	d
„ d
eƒZd)dd„Zdd„ Zd*dd„Z		d+dd„ZeddƒZeddƒZd*dd„Zd,dd„Zdd „ Zd!d"„ Zd*d#d$„Zd%d&„ Zd'd(„ ZdS )-é    )Ú
namedtuple)Úsha256N)ÚXFAILc                 C   s$   t j ¡ dkstjdkrt| ƒS | S )NÚdarwinÚnt)ÚsysÚplatformÚlowerÚosÚnamer   )Úfunc© r   úu/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/utilities/_compilation/util.pyÚ	may_xfail   s   r   c                   @   s   e Zd ZdS )ÚCompilerNotFoundErrorN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r      s    r   c                   @   s   e Zd ZdZdS )ÚCompileErrorz2Failure to compile one or more C/C++ source files.N)r   r   r   Ú__doc__r   r   r   r   r      s    r   Ú.c                 C   s>   t j | ¡r| S t j |¡st j |¡}t j t j || ¡¡S )z Returns the absolute path.

    Parameters
    ==========

    path : str
        (relative) path.
    cwd : str
        Path to root of relative path.
    )r
   ÚpathÚisabsÚabspathÚjoin)r   Úcwdr   r   r   Úget_abspath   s   ÿr   c                 C   s~   | d dkrt j | dd… ¡}nt j | ¡}t|ƒdkr't j |¡s't|ƒ t j | ¡s5t  | d¡ dS t j | ¡s=J ‚dS )z2 Create directories (equivalent of ``mkdir -p``). éÿÿÿÿú/Nr   iÿ  )r
   r   ÚdirnameÚlenÚexistsÚ	make_dirsÚmkdirÚisdir)r   Úparentr   r   r   r"   2   s   r"   c                 C   sT   |pd}t | |d} t ||d}tj | ¡sdS tj |¡d tj | ¡kr(dS dS )ao  
    Investigate if path is non-existant or older than provided reference
    path.

    Parameters
    ==========
    path: string
        path to path which might be missing or too old
    other_path: string
        reference path
    cwd: string
        working directory (root of relative paths)

    Returns
    =======
    True if path is older or missing.
    r   ©r   Tgíµ ÷Æ°>F)r   r
   r   r!   Úgetmtime)r   Ú
other_pathr   r   r   r   Úmissing_or_other_newerB   s   r)   FTc           	      C   s0  |rt j | ¡st j || ¡} t j |¡st j ||¡}t j | ¡s)td | ¡ƒ‚|r6|d dks5|d }nt j |¡rDt j |¡rDd}|rV|}t j | ¡}t j ||¡}nt j 	|¡}t j |¡sm|rit
|ƒ ntdƒ‚|rvt|| ƒsvdS t j |¡rˆt jjt j |¡|d}t | |¡ |r–t | |¡ |S )a    Variation of ``shutil.copy`` with extra options.

    Parameters
    ==========

    src : str
        Path to source file.
    dst : str
        Path to destination.
    only_update : bool
        Only copy if source is newer than destination
        (returns None if it was newer), default: ``False``.
    copystat : bool
        See ``shutil.copystat``. default: ``True``.
    cwd : str
        Path to working directory (root of relative paths).
    dest_is_dir : bool
        Ensures that dst is treated as a directory. default: ``False``
    create_dest_dirs : bool
        Creates directories if needed.

    Returns
    =======

    Path to the copied file.

    zSource: `{}` does not existr   r   Tz You must create directory first.Nr&   )r
   r   r   r   r!   ÚFileNotFoundErrorÚformatr$   Úbasenamer   r"   r)   Úislinkr   ÚrealpathÚshutilÚcopyÚcopystat)	ÚsrcÚdstÚonly_updater1   r   Údest_is_dirÚcreate_dest_dirsÚdest_dirÚ
dest_fnamer   r   r   r0   ^   s>   €

r0   ÚGlobÚpathnameÚArbitraryDepthGlobÚfilenamec                 C   sT   |d urd}g }t  |¡D ]\}}}|D ]}t || ¡r&| t j ||¡¡ qq|S )Nr   )r
   ÚwalkÚfnmatchÚappendr   r   )Úfilename_globr   ÚglobbedÚrootÚdirsÚ	filenamesÚfnr   r   r   Úglob_at_depthª   s   €ýrF   é€   c                    s\   t ƒ ‰t| dƒ‰ t‡ ‡‡fdd„dƒD ]}ˆ |¡ qW d  ƒ ˆS 1 s'w   Y  ˆS )ab   Computes the SHA256 hash of a file.

    Parameters
    ==========

    path : string
        Path to file to compute hash of.
    nblocks : int
        Number of blocks to read per iteration.

    Returns
    =======

    hashlib sha256 hash object. Use ``.digest()`` or ``.hexdigest()``
    on returned object to get binary or hex encoded string.
    Úrbc                      s   ˆ   ˆˆj ¡S ©N)ÚreadÚ
block_sizer   ©ÚfÚnblocksÚshr   r   Ú<lambda>È   s    z sha256_of_file.<locals>.<lambda>ó    N)r   ÚopenÚiterÚupdate)r   rN   Úchunkr   rL   r   Úsha256_of_fileµ   s   ÿ
ÿýrV   c                 C   s   t ƒ }| | ¡ |S )z' Computes the SHA256 hash of a string. )r   rT   )ÚstringrO   r   r   r   Úsha256_of_stringÍ   s   
rX   c                 C   s¬   t | ƒH}|D ]<}| d¡rCd|v rC| d¡}t|ƒdkrq|\}}| ¡  ¡ d  ¡ dkrC| ¡  ¡ d  ¡ dkrC W d  ƒ d	S qW d  ƒ d
S 1 sOw   Y  d
S )z³
    Inspect a Cython source file (.pyx) and look for comment line like:

    # distutils: language = c++

    Returns True if such a file is present in the file, else False.
    ú#ú=é   r   Úlanguager   zc++NTF)rR   Ú
startswithÚsplitr    Ústripr	   )r   ÚfhÚlineÚsplittedÚlhsÚrhsr   r   r   Úpyx_is_cplusÔ   s"   

÷€
ÿ
ö
re   c                 C   sì   t j | ¡\}}t j |¡\}}| d¡d }tjd dkrSddlm}m} |||gƒ\}} }|rJ|D ]}	t j 	| ¡t j 	|	¡k rIt
d |	| ¡ƒ‚q3|||| |ƒ}
|
S ddl}|j || ¡}|du rht
d|  ƒ‚|j |¡}
|j |
¡ |
S )a$   Imports Python extension (from shared object file)

    Provide a list of paths in `only_if_newer_than` to check
    timestamps of dependencies. import_ raises an ImportError
    if any is newer.

    Word of warning: The OS may cache shared objects which makes
    reimporting same path of an shared object file very problematic.

    It will not detect the new time stamp, nor new checksum, but will
    instead silently use old module. Use unique names for this reason.

    Parameters
    ==========

    filename : str
        Path to shared object.
    only_if_newer_than : iterable of strings
        Paths to dependencies of the shared object.

    Raises
    ======

    ``ImportError`` if any of the files specified in ``only_if_newer_than`` are newer
    than the file given by filename.
    r   r   r[   )Úfind_moduleÚload_modulez{} is newer than {}NzFailed to import: '%s')r
   r   r^   Úsplitextr   Úversion_infoÚimprf   rg   r'   ÚImportErrorr+   Úimportlib.utilÚutilÚspec_from_file_locationÚmodule_from_specÚloaderÚexec_module)r<   Úonly_if_newer_thanr   r   Úextrf   rg   ÚfobjÚdataÚdepÚmodÚ	importlibÚspecr   r   r   Úimport_module_from_fileè   s(   ÿúrz   c                 C   s@   ddl m} | D ]}||ƒ}|r|r||f  S qtd | ¡ƒ‚)a<   Finds binary first matching name among candidates.

    Calls ``which`` from shutils for provided candidates and returns
    first hit.

    Parameters
    ==========

    candidates : iterable of str
        Names of candidate commands

    Raises
    ======

    CompilerNotFoundError if no candidates match.
    r   )Úwhichz$No binary located for candidates: {})r/   r{   r   r+   )Ú
candidatesr{   ÚcÚbinary_pathr   r   r   Úfind_binary_of_command  s   €r   c                 C   s$   g }| D ]}||vr|  |¡ q|S )z) Uniquify a list (skip duplicate items). )r?   )ÚlÚresultÚxr   r   r   Úunique_list2  s   
€rƒ   )r   rI   )FTNFF)rG   )Úcollectionsr   Úhashlibr   r
   r/   r   r>   Úsympy.testing.pytestr   r   r*   r   Ú	Exceptionr   r   r"   r)   r0   r9   r;   rF   rV   rX   re   rz   r   rƒ   r   r   r   r   Ú<module>   s2    



ÿ
I



0