o
    Ďi                     @   s   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZmZ d dlmZ e eZd	d
dededB defddZdedefddZdS )    N)
HTTPStatus)ApiGetKernelRequest)registry)build_kaggle_client)KaggleApiHTTPErrorhandle_call)UtilityScriptHandleparse_utility_script_handle)EXTRA_CONSOLE_BLOCKF)force_downloadhandler   returnc                C   s   t | }tjd|  di td tj|d|d\}}t|s1td|j d|j	 d |S |t
jvr<t
j| td	| d
 |S )ap  
    Downloads the utility script and adds the directory path to the system path.

    Args:
        handle: (string) the notebook handle under https://kaggle.com/code.
        force_download: (bool) Optional flag to force download motebook output, even if it's cached.


    Returns:
        A string representing the path to the requested notebook output files.
    zDownloading Utility Script: z ...)extraN)pathr   z
Notebook 'z' by user 'z?' is not a Utility Script
 and will not be added to system pathzAdded z to system path)r	   loggerinfoto_urlr
   r   notebook_output_resolver_is_notebook_utility_scriptnotebookownersysr   append)r   r   hutility_script_path_ r   U/home/jeff/fluffinator/venv/lib/python3.10/site-packages/kagglehub/utility_scripts.pyutility_script_install   s   
r   r   c              
      s   z1t  # t | j_| j_t fdd}d|jjv W  d    W S 1 s*w   Y  W d S  t	y` } z#|j
d urZ|j
jtjkrZtd| j d| j d W Y d }~dS |d }~ww )Nc                      s    j jS )N)kernelskernels_api_client
get_kernelr   
api_clientrr   r   <lambda>5   s    z-_is_notebook_utility_script.<locals>.<lambda>zutility scriptzCould not find 'z' metadata by user 'z'.F)r   r   r   	user_namer   kernel_slugr   metadatacategory_idsr   responsestatus_coder   	NOT_FOUNDr   r   )r   r*   er   r"   r   r   /   s   
(r   )loggingr   httpr   +kagglesdk.kernels.types.kernels_api_servicer   	kagglehubr   kagglehub.clientsr   kagglehub.exceptionsr   r   kagglehub.handler   r	   kagglehub.loggerr
   	getLogger__name__r   strboolr   r   r   r   r   r   <module>   s    
 