
    U8j                         d Z ddlZddlZddlmZ ddlmZ dZ ej                  dej                        Z	de
defd	Zdefd
Zedk(  r ej                   e              yy)a  Check that Pine Script files don't exceed the 64 plot/plotchar call limit.

TradingView enforces a maximum of 64 plot() + plotchar() outputs per
indicator/strategy. Exceeding this causes silent truncation of data exports.

Exits 1 and prints the offending file + count if the limit is exceeded.
Usage: python3 tools/check_pine_plot_budget.py [file ...]
  Defaults to strategies/*.pine if no args given.
    N)glob)Path@   z:\bplot(?:char|shape|arrow|bar|candle)?\s*\(|\bbgcolor\s*\(pathreturnc                    t        |       j                  dd      }g }|j                         D ](  }|j                  t	        j
                  dd|             * dj                  |      }t        t        j                  |            S )Nzutf-8replace)encodingerrorsz//.* 
)
r   	read_text
splitlinesappendresubjoinlenPLOT_REfindall)r   textlineslinecleans        G/Users/jameslopez/projects/TradingBot25/tools/check_pine_plot_budget.pycount_plot_callsr      sl    :CDE!RVVGR./ "IIeEwu%&&    c                     t         j                  dd  xs t        t        d            } | st	        dt         j
                         yd}| D ]{  }t        |      j                         st        |      }|t        kD  r&t	        d|        t	        d| d	t                d
}Wt        |z
  }t	        d| d| dt         d| d	       } |rt	        dt         d       yy)N   zstrategies/*.pinezNo Pine files found.)filer   Fu   ❌  z    u-    plot/plotchar calls — exceeds TV limit of Tu   ✅  z  (/z plots, z remaining)zA
Fix: remove or combine plot() / plotchar() calls to stay within .)
sysargvsortedr   printstderrr   is_filer   
PLOT_LIMIT)targetsover_budgetr   count	remainings        r   mainr.   $   s    hhqrl?fT*=%>?G$3::6KDz!!# &:E$.!DLZLYZK"U*IE$s5':,hykUV  RS]R^^_`ar   __main__)__doc__r   r#   r   pathlibr   r)   compile	MULTILINEr   strintr   r.   __name__exit r   r   <module>r9      sw    
 
  
 "**ALL'3 '3 'c 4 zCHHTV r   