a
    zn„fi   ã                   @  s¸   d Z ddlmZ ddlZddlZddlZddlm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d„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ ZdS )%a3  
This module defines functions that import external libraries used by Uproot, but not
required by an Uproot installation. (Uproot only requires NumPy).

If a library cannot be imported, these functions raise ``ModuleNotFoundError`` with
error messages containing instructions on how to install the library.
é    )ÚannotationsN)Úparse_versionc               
   C  sf   zddl } W n. ty: } ztdƒ|‚W Y d}~n
d}~0 0 t| jƒtdƒkrR| S td| j› �ƒ‚dS )z*
    Imports and returns ``awkward``.
    r   NzÌinstall the 'awkward' package with:

    pip install awkward

Alternatively, you can use ``library="np"`` or globally set ``uproot.default_library``
to output as NumPy arrays, rather than Awkward arrays.
z2.4.6zKUproot 5.1+ can only be used with Awkward 2.4.6 or newer; you have Awkward )ÚawkwardÚModuleNotFoundErrorr   Ú__version__)r   Úerr© r   úP/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/uproot/extras.pyr      s    ÿø	
ÿr   c               
   C  sD   zddl } W n. ty: } ztdƒ|‚W Y d}~nd}~0 0 | S dS )z)
    Imports and returns ``pandas``.
    r   NzXinstall the 'pandas' package with:

    pip install pandas

or

    conda install pandas)Úpandasr   )r
   r   r   r   r	   r
   +   s    ÿø
r
   c               
   C  sH   zddl m}  W n. ty> } ztdƒ|‚W Y d}~nd}~0 0 | S dS )z.
    Imports and returns ``minio.Minio``.
    r   )ÚMiniozUinstall the 'minio' package with:

    pip install minio

or

    conda install minioN)Zminior   r   )r   r   r   r   r	   ÚMinio_client?   s    ÿø
r   c               
     sn   dt jd< zddl‰ ddl‰ W n. tyL }  ztdƒ| ‚W Y d} ~ n
d} ~ 0 0 tdƒrhtj‡ fdd„ƒ}ˆ jS )	zž
    Imports and returns ``XRootD.client`` (after setting the
    ```XRD_RUNFORKHANDLER`` environment variable to ``"1"``, to allow
    multiprocessing).
    Ú1ZXRD_RUNFORKHANDLERr   NzÕInstall XRootD python bindings with:

    conda install -c conda-forge xrootd

(or download from http://xrootd.org/dload.html and manually compile with cmake; setting PYTHONPATH and LD_LIBRARY_PATH appropriately).z5.1.0c               	     sV   ddl } |  ¡ D ]@}zt|ˆ jjjƒo,| ¡ }W n tyB   Y q0 |r| ¡  qdS )zøClean up any open xrootd file objects at exit

            Required to avoid deadlocks from XRootD, for details see:
            * https://github.com/scikit-hep/uproot/issues/504
            * https://github.com/xrootd/xrootd/pull/1260
            r   N)	ÚgcZget_objectsÚ
isinstanceÚclientÚfileÚFileZis_openÚReferenceErrorÚclose)r   ÚobjZisopen©ÚXRootDr   r	   Úcleanup_open_filesk   s    z)XRootD_client.<locals>.cleanup_open_files)	ÚosÚenvironr   ZXRootD.clientr   Úolder_xrootdÚatexitÚregisterr   )r   r   r   r   r	   ÚXRootD_clientS   s    
ÿù	r   c                 C  s>   t ƒ }|du rdS zt|ƒt| ƒk W S  ty8   Y dS 0 dS )aD  
    Check if the installed XRootD bindings are newer than a given version
    without importing. Defaults to False if XRootD is not installed. Unrecognized
    versions (i.e. self-built XRootD, whose version numbers are strings)
    return False: that is, they're assumed to be new, so that no warnings
    are raised.
    NF)Úxrootd_versionr   Ú	TypeError)Úmin_versionÚversionr   r   r	   r   �   s    r   c                   C  sP   zt j d¡W S  tyJ   zt j d¡W  Y S  tyD   Y Y dS 0 Y n0 dS )zG
    Gets the XRootD version if installed, otherwise returns None.
    ZxrootdZpyxrootdN)Ú	importlibÚmetadatar"   r   r   r   r   r	   r   “   s    r   c               
   C  sD   zddl } W n. ty: } ztdƒ|‚W Y d}~nd}~0 0 | S dS )z%
    Import and return ``isal``.
    r   NzYinstall the 'isal' package with:

    pip install isal

or

    conda install python-isal)Úisalr   )r%   r   r   r   r	   r%   ¡   s    ÿø
r%   c               
   C  sD   zddl } W n. ty: } ztdƒ|‚W Y d}~nd}~0 0 | S dS )z(
    Import and return ``deflate``.
    r   Nz^install the 'deflate' package with:

    pip install deflate

or

    conda install libdeflate)Údeflater   )r&   r   r   r   r	   r&   µ   s    ÿø
r&   c               
   C  sD   zddl } W n. ty: } ztdƒ|‚W Y d}~nd}~0 0 | S dS )z)
    Import and returns ``cramjam``.
    r   Nz[install the 'cramjam' package with:

    pip install cramjam

or

    conda install cramjam)Úcramjamr   )r'   r   r   r   r	   r'   É   s    ÿø
r'   c               
   C  sD   zddl } W n. ty: } ztdƒ|‚W Y d}~nd}~0 0 | S dS )z)
    Imports and returns ``xxhash``.
    r   Nz`install the `xxhash` packages with:

    pip install xxhash

or

    conda install python-xxhash)Úxxhashr   )r(   r   r   r   r	   r(   Ý   s    ÿø
r(   c               
   C  sD   zddl } W n. ty: } ztdƒ|‚W Y d}~nd}~0 0 | S dS )z2
    Imports and returns ``boost-histogram``.
    r   Nz‚install the 'boost-histogram' package with:

    pip install boost-histogram

or

    conda install -c conda-forge boost-histogram)Úboost_histogramr   )r)   r   r   r   r	   r)   ñ   s    ÿø
r)   c               
   C  sD   zddl } W n. ty: } ztdƒ|‚W Y d}~nd}~0 0 | S dS )z'
    Imports and returns ``hist``.
    r   Nz6install the 'hist' package with:

    pip install hist)Úhistr   )r*   r   r   r   r	   r*     s    ÿür*   c               
   C  sL   zddl } ddl} W n. tyB } ztdƒ|‚W Y d}~nd}~0 0 | S dS )z'
    Imports and returns ``dask``.
    r   Nú‰for uproot.dask with 'library="np"', install the complete 'dask' package with:
    pip install "dask[complete]"
or
    conda install dask)ÚdaskZdask.blockwiser   )r,   r   r   r   r	   r,     s    ÿûr,   c               
   C  sH   zddl m}  W n. ty> } ztdƒ|‚W Y d}~nd}~0 0 | S dS )z-
    Imports and returns ``dask.array``.
    r   Nr+   )Z
dask.arrayÚarrayr   )Údar   r   r   r	   Ú
dask_array'  s    ÿûr/   c               
   C  sf   zddl } W n. ty: } ztdƒ|‚W Y d}~n
d}~0 0 t| jƒtdƒkrR| S td| j› �ƒ‚dS )z/
    Imports and returns ``dask_awkward``.
    r   Nz¨for uproot.dask, install 'dask' and the 'dask-awkward' package with:
    pip install "dask[complete] dask-awkward"
or
    conda install -c conda-forge dask dask-awkwardz	2023.10.0zYUproot 5.1+ can only be used with dask-awkward 2023.10.0 or newer; you have dask-awkward )Údask_awkwardr   r   r   )r0   r   r   r   r	   r0   8  s    ÿû
ÿr0   c               
   C  sD   zddl } W n. ty: } ztdƒ|‚W Y d}~nd}~0 0 | S dS )z1
    Imports and returns ``awkward_pandas``.
    r   Nz|install the 'awkward-pandas' package with:
    pip install awkward-pandas
or
    conda install -c conda-forge awkward-pandas)Úawkward_pandasr   )r1   r   r   r   r	   r1   M  s    ÿûr1   )Ú__doc__Ú
__future__r   r   Úimportlib.metadatar#   r   Zuproot._utilr   r   r
   r   r   r   r   r%   r&   r'   r(   r)   r*   r,   r/   r0   r1   r   r   r   r	   Ú<module>   s*   .