
    h2                        S SK Jr  S SKrS SKrS SKrS SKrS SKJr   " S S5      r\	S:X  a  \
" \R                  5       5        gg)    )annotationsN)Pathc                  J    \ rS rSrSr\SS j5       r\S	S j5       rSS jrSr	g)
CPUInfo   a  
Provide cross-platform CPU brand and model information.

Query platform-specific sources to retrieve a human-readable CPU descriptor and normalize it for consistent
presentation across macOS, Linux, and Windows. If platform-specific probing fails, generic platform identifiers are
used to ensure a stable string is always returned.

Methods:
    name: Return the normalized CPU name using platform-specific sources with robust fallbacks.
    _clean: Normalize and prettify common vendor brand strings and frequency patterns.
    __str__: Return the normalized CPU name for string contexts.

Examples:
    >>> CPUInfo.name()
    'Apple M4 Pro'
    >>> str(CPUInfo())
    'Intel Core i7-9750H 2.60GHz'
c                     [         R                  S:X  aN  [        R                  " / SQSSS9R                  R                  5       n U (       a  [        R                  U 5      $ GO![         R                  R                  S5      (       au  [        S5      nUR                  5       (       aT  UR                  SS9R                  5        H3  nS	U;   d  M  [        R                  UR                  S
S5      S   5      s  $    O[         R                  R                  S5      (       ad   SSKnUR                  UR                   S5       nUR#                  US5      u  pVU(       a  [        R                  U5      sSSS5        $  SSS5        [        R&                  " 5       =(       d<    [)        [        R*                  " 5       SS5      =(       d    [        R,                  " 5       n [        R                  U =(       d    S5      $ ! , (       d  f       N= f! [$         a     Nf = f! [$         a[    [        R&                  " 5       =(       d    [        R,                  " 5       =(       d    Sn [        R                  U =(       d    S5      s $ f = f)zDReturn a normalized CPU model string from platform-specific sources.darwin)sysctlz-nzmachdep.cpu.brand_stringT)capture_outputtextlinuxz/proc/cpuinfoignore)errorsz
model name:   winr   Nz.HARDWARE\DESCRIPTION\System\CentralProcessor\0ProcessorNameString	processor zUnknown CPU)sysplatform
subprocessrunstdoutstripr   _clean
startswithr   exists	read_text
splitlinessplitwinregOpenKeyHKEY_LOCAL_MACHINEQueryValueEx	Exceptionr   getattrunamemachine)splinewrkval_s          O/home/james-whalen/.local/lib/python3.13/site-packages/ultralytics/utils/cpu.pynameCPUInfo.name    s    	6||x'NN@QU\`&  ">>!,, ((11)88:: !8 < G G I'4/#*>>$**S!2DQ2G#HH !J ((//	'B$9$9;lmqr!#4I!J#*>>##6 nm n ""$h0@+r(RhV^VfVfVhA>>!"4}55 nm !   	6""$@(8(8(:@bA>>!"4}55	6su   AH "A*H )H :'H " H 0G;2	H =H A5H ;
H	H H 	H 
HH HH A"J Jc                :   [         R                  " SSU R                  5       5      n U R                  SS5      R                  SS5      R                  SS5      R                  SS5      R                  5       n [         R                  " SU [         R
                  5      nU(       a%  UR                  S	5       SUR                  S
5       3$ [         R                  " SU [         R
                  5      nU(       a%  UR                  S	5       SUR                  S
5       3$ U $ )z3Normalize and prettify a raw CPU descriptor string.z\s+ z(TM)r   z(tm)z(R)z(r)z%(Intel.*?i\d[\w-]*) CPU @ ([\d.]+GHz)r      z((AMD.*?Ryzen.*?[\w-]*) CPU @ ([\d.]+GHz))resubr   replacesearchIgroup)r*   ms     r1   r   CPUInfo._cleanE   s     FF63	*IIfb!))&"5==eRHPPQVXZ[aacII>244Hggaj\1771:,//IIA1bddKggaj\1771:,//    c                "    U R                  5       $ )zReturn the normalized CPU name.)r2   )selfs    r1   __str__CPUInfo.__str__T   s    yy{r?    N)returnstr)r*   rF   rE   rF   )
__name__
__module____qualname____firstlineno____doc__staticmethodr2   r   rB   __static_attributes__rD   r?   r1   r   r      s5    & "6 "6H  r?   r   __main__)
__future__r   r   r7   r   r   pathlibr   r   rG   printr2   rD   r?   r1   <module>rR      sC    #  	  
 J JZ z	',,. r?   