
    niH9                     j   d dl Z d dlZd dlZd dlmZmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZmZmZ d dlmZ d dlmZmZmZ d d	lmZmZ d d
lmZ d dlmZ ej        dk    r	 d dlZn# e $ r	 esd dl!ZY nw xY wd dl!Zd dl"m#Z# d dl$m%Z% d dl&m'Z' d dl(m)Z) erd dl*Z*ede
e+z  de,e+ef         fd            Z-ede
de
fd            Z.e	 d=dee+         de+dz  de/e
e+f         fd            Z0	 d=de/e+df         de+dz  de+dz  fdZ1 ed          de+de,e+ef         fd            Z2de,e+ef         de3e%         dz  fd Z4d!e+de3e%         dz  fd"Z5d!e+de3e%         dz  fd#Z6d$edefd%Z7ede
fd&            Z8ed'e
defd(            Z9	 d=de
d'e
d)e)dz  de:fd*Z;de
d'e
de
fd+Z<d,e+d'e
d-e,e
ef         de:fd.Z=d/e+d0ee+         dz  de:fd1Z>d2ee
         d'e
d3ee+         d4ee+         d5ee+         dz  d6ee+         dz  d)e)d-e,e
ef         dz  d7e:d8e:dee
         fd9Z?d:e j@        dee j@        d;f         fd<ZAdS )>    N)IterableIteratorSequence)	lru_cache)Path)Pattern)TYPE_CHECKINGAnyUnion)
mypyc_attr)InvalidSpecifier	SpecifierSpecifierSet)InvalidVersionVersion)GitIgnoreSpec)GitIgnorePatternError)      )"jupyter_dependencies_are_installed)TargetVersion)err)Reportpathreturnc                 ~    t          | d          5 }t          j        |          cd d d            S # 1 swxY w Y   d S )Nrb)opentomllibload)r   fs     H/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/black/files.py
_load_tomlr#   #   s~    	dD		 Q|A                 s   266c                 *    |                                  S N)resolver   s    r"   _cached_resolver(   )   s    <<>>    srcsstdin_filenamec                 D   t          fd| D                       } | s.t          t          t          j                                        g} d | D             }d |D             }t          t          j        d |D              d           }|g|j        R D ]}|dz  	                                r|d	fc S |d
z  
                                r|dfc S |dz                                  r0t          |dz            }d|                    di           v r|dfc S |dfS )aQ  Return a directory containing .git, .hg, or pyproject.toml.

    pyproject.toml files are only considered if they contain a [tool.black]
    section and are ignored otherwise.

    That directory will be a common parent of all files and directories
    passed in `srcs`.

    If no directory in the tree contains a marker that would specify it's the
    project root, the root of the file system is returned.

    Returns a two-tuple with the first element as the project root path and
    the second element as a string describing the method by which the
    project root was discovered.
    Nc              3   ,   K   | ]}|d k    rn|V  dS )-N ).0sr+   s     r"   	<genexpr>z$find_project_root.<locals>.<genexpr>B   s/      EE1qCxx^^QEEEEEEr)   c                 j    g | ]0}t          t          t          j                    |                    1S r/   )r(   r   cwd)r0   srcs     r"   
<listcomp>z%find_project_root.<locals>.<listcomp>F   s0    HHHCdhjj#!6!677HHHr)   c                 j    g | ]0}t          |j                  |                                r|gng z   1S r/   )listparentsis_dir)r0   r   s     r"   r6   z%find_project_root.<locals>.<listcomp>J   sG       CGT\=tff2>  r)   c              3   4   K   | ]}t          |          V  d S r%   )set)r0   r9   s     r"   r2   z$find_project_root.<locals>.<genexpr>O   s(      CCG3w<<CCCCCCr)   c                     | j         S r%   )partsr'   s    r"   <lambda>z#find_project_root.<locals>.<lambda>P   s     r)   )keyz.gitz.git directoryz.hgz.hg directorypyproject.tomlblacktoolzfile system root)tuplestrr(   r   r4   maxr<   intersectionr9   existsr:   is_filer#   get)r*   r+   	path_srcssrc_parentscommon_base	directorypyproject_tomls    `     r"   find_project_rootrP   .   s   & !EEEEEEEEE 2ODHJJ//001HH4HHHI KT  K CC{CCCD##  K
 "8K$788 
3 
3	&&(( 	/.....%%'' 	.o----((1133 	3'	4D(DEEN.,,VR8888 "22222(((r)   path_search_start.c                 B   t          | |          \  }}|dz  }|                                rt          |          S 	 t                      }|                                rt          |          ndS # t          t
          f$ r}t          d|           Y d}~dS d}~ww xY w)z;Find the absolute filepath to a pyproject.toml if it existsrA   Nz-Ignoring user configuration directory due to )rP   rI   rE   find_user_pyproject_tomlPermissionErrorRuntimeErrorr   )rQ   r+   path_project_root_path_pyproject_tomlpath_user_pyproject_tomles          r"   find_pyproject_tomlr[   b   s     -->OOq+.>>""$$ (&'''
#;#=#=  (//11C()))	

 \*   AAAABBBttttts   2A0 0BBBT)	patchablepath_configc                     t          |           }|                    di                               di           }d |                                D             }d|vr t          |          }|d |D             |d<   |S )zParse a pyproject toml file, pulling out relevant parts for Black.

    If parsing fails, will raise a tomllib.TOMLDecodeError.
    rC   rB   c                 j    i | ]0\  }}|                     d d                               dd          |1S )z-- r.   rW   )replace)r0   kvs      r"   
<dictcomp>z(parse_pyproject_toml.<locals>.<dictcomp>   s<    RRR41aaiib!!))#s33QRRRr)   target_versionNc                 @    g | ]}|j                                         S r/   )namelowerr0   rc   s     r"   r6   z(parse_pyproject_toml.<locals>.<listcomp>   s"    'X'X'X1'X'X'Xr)   )r#   rJ   itemsinfer_target_version)r]   rO   configinferred_target_versions       r"   parse_pyproject_tomlrn   x   s      ,,N+//;;??LLFRR6<<>>RRRFv%%"6~"F"F".'X'X@W'X'X'XF#$Mr)   rO   c                     |                      di           }|                     dd          }|G	 t          |          S # t          $ r Y nw xY w	 t          |          S # t          t          f$ r Y nw xY wdS )a#  Infer Black's target version from the project metadata in pyproject.toml.

    Supports the PyPA standard format (PEP 621):
    https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#requires-python

    If the target version cannot be inferred, returns None.
    projectzrequires-pythonN)rJ   parse_req_python_versionr   parse_req_python_specifierr   )rO   project_metadatarequires_pythons      r"   rk   rk      s     &)))R88&**+<dCCO"	+O<<< 	 	 	D		-o>>> .1 	 	 	D	 4s!   ? 
AAA A32A3rt   c                     t          |           }|j        d         dk    rdS 	 t          |j        d                   gS # t          t          f$ r Y dS w xY w)zParse a version string (i.e. ``"3.7"``) to a list of TargetVersion.

    If parsing fails, will raise a packaging.version.InvalidVersion error.
    If the parsed version cannot be mapped to a valid TargetVersion, returns None.
    r   r   N   )r   releaser   
IndexError
ValueError)rt   versions     r"   rq   rq      sl     o&&GqQtgoa01122
#   tts   ? AAc                     t          t          |                     }|sdS d t          D             t          |                                        }|rfd|D             S dS )zParse a specifier string (i.e. ``">=3.7,<3.10"``) to a list of TargetVersion.

    If parsing fails, will raise a packaging.specifiers.InvalidSpecifier error.
    If the parsed specifier cannot be mapped to a valid TargetVersion, returns None.
    Nc                 $    i | ]}d |j          |S )z3.)valueri   s     r"   rd   z.parse_req_python_specifier.<locals>.<dictcomp>   s"    CCC.qw..!CCCr)   c                      g | ]
}|         S r/   r/   )r0   rc   target_version_maps     r"   r6   z.parse_req_python_specifier.<locals>.<listcomp>   s    CCC!"1%CCCr)   )strip_specifier_setr   r   r8   filter)rt   specifier_setcompatible_versionsr   s      @r"   rr   rr      s     (_(E(EFFM tCC]CCC%)-*>*>?Q*R*R%S%S DCCCC/BCCCC4r)   r   c                 l   g }| D ]}dt          |          v r|                    |           *|j        dv rOt          |j                  }t          |j         |j         d|j                   }|                    |           |j        dk    rat          |j                  }t          |j	                  dk    rt          d|j         d|j                   }|                    |           |                    |           t          d                    d |D                                 S )	zStrip minor versions for some specifiers in the specifier set.

    For background on version specifiers, see PEP 440:
    https://peps.python.org/pep-0440/#version-specifiers
    *)z~=z==>=z===.>   r   ,c              3   4   K   | ]}t          |          V  d S r%   )rE   )r0   r1   s     r"   r2   z&strip_specifier_set.<locals>.<genexpr>   s(       < <AQ < < < < < <r)   )rE   appendoperatorr   rz   r   majorminorlenrw   r   join)r   
specifiersr1   rz   strippeds        r"   r   r      sB    J ! !#a&&==a    Z444ai((G AJ!O!O!O!O!OPPHh''''Z3ai((G7?##a''B7=BB7=BBCCa    a     < < < < <<<===r)   c                      t           j        dk    rt          j                    dz  } nDt          j                            dd          }t          |                                          dz  } t          |           S )a:  Return the path to the top-level user configuration for black.

    This looks for ~\.black on Windows and ~/.config/black on Linux and other
    Unix systems.

    May raise:
    - RuntimeError: if the current user has no homedir
    - PermissionError: if the current process cannot access the user's homedir
    win32z.blackXDG_CONFIG_HOMEz	~/.configrB   )	sysplatformr   homeosenvironrJ   
expanduserr(   )user_config_pathconfig_roots     r"   rS   rS      si     |w9;;1jnn%6DD,,7799GC+,,,r)   rootc                 6   | dz  }g }|                                 rB|                    d          5 }|                                }ddd           n# 1 swxY w Y   	 t          j        |          S # t
          $ r}t          d| d|             d}~ww xY w)z=Return a GitIgnoreSpec matching gitignore content if present.z
.gitignorezutf-8)encodingNzCould not parse z: )rI   r   	readlinesr   
from_linesr   r   )r   	gitignorelinesgfrZ   s        r"   get_gitignorer      s     |#IE #^^W^-- 	#LLNNE	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#'...    /y//A//000s)   AAAA3 3
B=BBreportc                    	 t          |           }n3# t          $ r&}|r|                    | d|            Y d}~dS d}~ww xY w	 |                    |           n,# t          $ r |r|                    | d|            Y dS w xY wdS )z
    Returns whether the path is a symbolic link that points outside the
    root directory. Also returns True if we failed to resolve the path.
    zcannot be read because NTz'is a symbolic link that points outside F)r(   OSErrorpath_ignoredrelative_tory   )r   r   r   resolved_pathrZ   s        r"   $resolves_outside_root_or_cannot_statr      s    '--    	E&C&C&CDDDttttt!!$''''    	X&VPT&V&VWWWtt 5s$    
A=AA %BBc                 (   	 |                                                                S # t          $ r Y nw xY wt          fd| j        D             d           }||                     |          S t          |                                         S )Nc              3   B   K   | ]}t          |          k    |V  d S r%   )r(   )r0   pr   s     r"   r2   z,best_effort_relative_path.<locals>.<genexpr>  s5      NNa?13E3E3M3M3M3M3M3MNNr)   )absoluter   ry   nextr9   r(   )r   r   root_parents    ` r"   best_effort_relative_pathr     s    }}**4000   NNNN4<NNNPTUUK,,,4  ,,T222s   &* 
77root_relative_pathgitignore_dictc                    || z  }|                                 D ]p\  }}	 |                    |                                          }|                                r|dz   }n# t          $ r Y  nw xY w|                    |          r dS qdS )N/TF)rj   r   as_posixr:   ry   
match_file)r   r   r   r   gitignore_pathpatternrelative_paths          r"   _path_is_ignoredr   $  s    
 $$D $2#7#7#9#9  	 ,,^<<EEGGM{{}} 4 - 3 	 	 	EE	m,, 	44	5s   A A!!
A/.A/normalized_pathr   c                 |    |r|                     |           nd }t          |o|                    d                    S )Nr   )searchboolgroup)r   r   matchs      r"   path_is_excludedr   8  s<     07@GNN?+++DE(%++a..)))r)   pathsincludeexcludeextend_excludeforce_excludeverbosequietc             #     K   |                                 sJ d|             | D ]}
|
                                 sJ |
                    |                                          }|r(t          |||          r|                    |
d           jd|z   }|
                                r|dz  }t          ||          r|                    |
d           t          ||          r|                    |
d           t          ||          r|                    |
d           t          |
||          r|
                                rP|i |||
z  t          |
          i}nd}t          |

                                |||||||||	
  
        E d{V  t|
                                r?|
j        d	k    rt          |p|	 
          s|r|                    |          nd}|r|
V  dS )a7  Generate all files under `path` whose paths are not excluded by the
    `exclude_regex`, `extend_exclude`, or `force_exclude` regexes,
    but are included by the `include` regex.

    Symbolic links pointing outside of the `root` directory are ignored.

    `report` is where output about exclusions goes.
    z/INTERNAL ERROR: `root` must be absolute but is z!matches a .gitignore file contentr   z(matches the --exclude regular expressionz/matches the --extend-exclude regular expressionz.matches the --force-exclude regular expressionN)r   r   z.ipynb)warnT)is_absoluter   r   r   r   r:   r   r   r   gen_python_filesiterdirrI   suffixr   r   )r   r   r   r   r   r   r   r   r   r   childr   new_gitignore_dictinclude_matchs                 r"   r   r   @  s     , WWWQUWWWWW ? ?  """"""..t44==??  	.n
 
 	 'JKKK !#55<<>> 	&#%.88 	'QRRR.?? 	H   .>> 	'WXXX/tVDD 	<<>> 	 )&$&5L-"6"6& &""
 &*"'"           ]]__ 	|x''0R)E	1 1 1' BISGNN+=>>>tM ? ?r)   r!   zcolorama.AnsiToWin32c                 T    	 ddl m}  || dddd          S # t          $ r | cY S w xY w)at  
    Wrap stream with colorama's wrap_stream so colors are shown on Windows.

    If `colorama` is unavailable, the original stream is returned unmodified.
    Otherwise, the `wrap_stream()` function determines whether the stream needs
    to be wrapped for a Windows environment and will accordingly either return
    an `AnsiToWin32` wrapper or the original stream.
    r   )wrap_streamNFT)convertstrip	autoresetwrap)colorama.initialiser   ImportError)r!   r   s     r"   wrap_stream_for_windowsr     s]    U333333
 {1d%5tTTTT	    s    ''r%   )Bior   r   collections.abcr   r   r   	functoolsr   pathlibr   rer   typingr	   r
   r   mypy_extensionsr   packaging.specifiersr   r   r   packaging.versionr   r   pathspecr   pathspec.patterns.gitignorer   version_infor   r   tomliblack.handle_ipynb_magicsr   
black.moder   black.outputr   black.reportr   coloramarE   dictr#   r(   rD   rP   r[   rn   r8   rk   rq   rr   r   rS   r   r   r   r   r   r   r   TextIOWrapperr   r/   r)   r"   <module>r      s   				 				 



 8 8 8 8 8 8 8 8 8 8                   , , , , , , , , , , & & & & & & J J J J J J J J J J 5 5 5 5 5 5 5 5 " " " " " " = = = = = =w$ $ $ $ 	$####$
  H H H H H H $ $ $ $ $ $             OOO TCZ DcN    
 $ 4     6:0) 0)
3-0)),t0)
490) 0) 0) 0)h FJ S#X8;d
4Z   , dc d38n    "cN	-4   2c d=6ID6P     ]8Kd8R    ">| > > > > >2 -$ - - - -&      " ! 

 TM 
	   0
3D 
3 
3 
3 
3 
3 
3
 },- 
	   (**S\D * 
* * * *VD>V
V S\V S\	V
 CL4'V 3<$&V V },-4V V V d^V V V VrU	U
2334U U U U U Us   #A( (A65A6