
    Yfv                         d dl Z d dlZd dlZd dlmZ  e j
                  e      5  d dlmZm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZ e G d de             Zd	ed
dfdZddd       y# 1 sw Y   yxY w)    N)Any)Magicsline_cell_magic
line_magicmagics_class)scalene_profiler)ScaleneArguments)ScaleneParseArgsc                   `    e Zd ZdZdededdfdZeddededdfd	       Ze	ddeddfd
       Z
y)ScaleneMagicszHIPython (Jupyter) support for magics for Scalene (%scrun and %%scalene).argscodereturnNc                 h   dd l }dt        |j                         j                  j                        dz
   d}t        |d      5 }|j                  |       d d d        d|_        t        j                  j                          t        j                  j                  ||gd       y # 1 sw Y   RxY w)	Nr   z_ipython-input-   z-profilezw+FT)
is_jupyter)IPythonlenget_ipythonhistory_managerinput_hist_rawopenwritememoryr   Scaleneset_initializedrun_profiler)selfr   r   r   filenametmpfiles         V/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/scalene/scalene_magics.pyrun_codezScaleneMagics.run_code   s    
 )W-@-@-B-R-R-a-a)bcd)d(eemnHh% $d#$DK$$446$$11xjT 2 	$ $s   B((B1linecellc                     |r5ddg|j                         t        _        t        j                         \  }}n
t               }|r|r| j                  |d|z          yyy)zL%%scalene magic: see https://github.com/plasma-umass/scalene for usage info.scalene	--ipython
N)splitsysargvr
   
parse_argsr	   r"   )r   r#   r$   r   _lefts        r!   r&   zScaleneMagics.scalene&   sX     %{BTZZ\B 0 ; ; =u ()dD4K0 t    c                     t        d       |rYddg|j                         t        _        t	        j
                         \  }}|r"| j                  |dj                  |             yyy)zI%scrun magic: see https://github.com/plasma-umass/scalene for usage info.zSCRUN MAGICr&   r'    N)printr)   r*   r+   r
   r,   r"   join)r   r#   r   lefts       r!   scrunzScaleneMagics.scrun5   s[     - %{BTZZ\B/::<tMM$7  r.   ) )__name__
__module____qualname____doc__r	   strr"   r   r&   r   r4    r.   r!   r   r      sk    V	!1 	 	 	 
	1 	13 	1 	1 
	1 
	8c 	84 	8 
	8r.   r   ipr   c                 F   t        d       | j                  t               t        j                  t
              5  t        dd      5 }|j                         }d d d        t        j                  _	        |t        j                  _	        d d d        t        dj                  t        j                  d                   t        j                  dk(  r8t                t        dj                  t        j                  d                   y y # 1 sw Y   xY w# 1 sw Y   xY w)NLOADINGzscalene-usage.txtrr(   a7  Scalene extension successfully loaded. Note: Scalene currently only supports CPU+GPU profiling inside Jupyter notebooks. For full Scalene profiling, use the command line version. To profile in line mode, use `%scrun [options] statement`. To profile in cell mode, use `%%scalene [options]` followed by your code.darwinzNOTE: in Jupyter notebook on MacOS, Scalene cannot profile child processes. Do not run to try Scalene with multiprocessing in Jupyter Notebook.)r1   register_magicsr   
contextlibsuppress	Exceptionr   readr4   r9   r&   r2   textwrapwrapr*   platform)r<   usage	usage_strs      r!   load_ipython_extensionrK   ?   s    i
=)  + 	6)3/ )5!JJL	)*3M',5M!!)	6 	II N	
 <<8#G		MM j $) )	6 	6s#   DD2DD	DD )rB   r*   rF   typingr   rC   rD   IPython.core.magicr   r   r   r   r&   r   scalene.scalene_argumentsr	   scalene.scalene_parseargsr
   r   rK   r;   r.   r!   <module>rP      s}     
  Z# Q  )::)8 )8 )8V3 4 sQ Q Qs   7A%%A.