
    <hF                         S SK r S SKrS SKJr  S SKr\" S5      r/ SQrSrS rS r	S r
\S	:X  aO  \
" 5       r\(       a.  \" S
5        \ H  r\" S\ 35        M     \R                  " S5        \R                  " S 5        gg)    N)Pathzproject/COMPLEXITY_BACKLOG.md)zapi/srcsnitchzgonk-testUIg      @c                     0 n [         R                  5       (       d  U $ [        [         SSS9 nUR                  5       nSSS5        WSS  H  nUR	                  5       R                  S5      (       d  M)  UR                  S5       Vs/ s H  oDR	                  5       PM     nn[        U5      S:  a  Mh  US   R                  S	S
5      nUS   R                  S	S
5      nUS   nX`;  a  0 X'   XU   U'   M     U $ ! , (       d  f       N= fs  snf )zs
Loads the complexity backlog from the markdown file.
Returns a dictionary of {filepath: {function_name: status}}.
rutf-8)encodingN   |      `    )	BACKLOG_FILEexistsopen	readlinesstrip
startswithsplitlenreplace)	backlogflineslinepparts	file_pathfunction_namestatuss	            4/root/zotify-API/scripts/check_complexity_backlog.pyload_backlogr#   
   s    
 G  	lC'	2a 
3 ab	zz|&&s++$(JJsO4OqO4u:>!H$$S"-	a((b1q#!#G,2	=)   N' 
3	2 5s   C8D	8
Dc            
         / n [          H  n[        U5      R                  5       (       d  M#  Sn[        R                  " USSSSSU/SSSS	9nUR
                  S
:w  d  UR                  (       d  Mf   [        R                  " UR                  5      nUR                  5        H6  u  pVU H+  nUS   S;   d  M  US   nUS   n	U R                  XXU	45        M-     M8     M     U $ ! [        R                   a    [        SU 35         M  f = f)z
Runs radon on all source directories and parses the JSON output.
Returns a list of (filepath, function_name, complexity) tuples.
z2/home/jules/.pyenv/versions/3.12.11/bin/python3.12z-mradonccz-sz-jTr   )capture_outputtextr   r   type)functionmethodname
complexityz.Error decoding JSON from radon for directory: )SOURCE_DIRSr   is_dir
subprocessrun
returncodestdoutjsonloadsitemsappendJSONDecodeErrorprint)
resultsdir_path
radon_pathprocess
radon_datafilepath	functions	func_data	func_namer-   s
             r"   run_radon_ccrC   (   s   
 GH~$$&&I
..wdD(C	
 "'..	GNN3J'1'7'7'9#!*I (,BB$-f$5	%.|%<
Z'HI "+ (:#  8 N	 ## 	B8*MN	s   0AC 5%C  "DDc            
      d   [        5       n [        5       n/ nU H  u  p4nU[        ::  a  M  U R                  U0 5      R                  US5      nUS;  d  M<  US:X  a  SU SU SU S3nUR	                  U5        Ma  SU SU SU SU S3	nUR	                  U5        M     U(       d  [        S	5        U$ )
zn
Main function to check cyclomatic complexity against the backlog.
Returns a list of failure message strings.
Missing)
RefactoredVerifiedz	Function z::z (CC=z>) is over threshold and is missing from COMPLEXITY_BACKLOG.md.z$) is over threshold and has status 'z1' in backlog. Must be 'Refactored' or 'Verified'.uJ   ✅ All high-complexity functions are tracked and approved in the backlog.)r#   rC   COMPLEXITY_THRESHOLDgetr7   r9   )r   
cc_resultsfailuresfiler*   r-   r!   msgs           r"   check_complexityrN   L   s    
 nGJH&0"
--T2&**8Y?33"vRzzl CA B  $  vRzzl C''-h._a  $# '1& Z[O    __main__z 
--- Complexity Check Failed ---u   ❌ r   )r0   r4   pathlibr   sysr   r.   rH   r#   rC   rN   __name__rK   r9   r   exit rO   r"   <module>rV      s       
342 <"HB z!H12AD* HHQK rO   