
    ]jH9                        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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<ZAy# e $ r
 esd dl!ZY w xY w)>    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                 p    t        | d      5 }t        j                  |      cd d d        S # 1 sw Y   y xY w)Nrb)opentomllibload)r   fs     5/root/env/lib/python3.12/site-packages/black/files.py
_load_tomlr#   #   s.    	dD	 Q||A  s   ,5c                 "    | j                         S N)resolver   s    r"   _cached_resolver(   )   s    <<>    srcsstdin_filenamec           	         t        fd| D              } | s't        t        t        j                                     g} | D cg c])  }t        t        t        j                         |            + }}|D cg c]-  }t        |j                        |j                         r|gng z   / }}t        t        j                  d |D         d       }|g|j                  D ]p  }|dz  j                         r|dfc S |dz  j                         r|dfc S |d	z  j                         sIt        |d	z        }d
|j                  di       v sl|d	fc S  dfS c c}w c c}w )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.
    c              3   0   K   | ]  }|d k(  rn|  yw)-N ).0sr+   s     r"   	<genexpr>z$find_project_root.<locals>.<genexpr>B   s     E1qCx^Q6Es   c              3   2   K   | ]  }t        |        y wr%   )set)r0   parentss     r"   r2   z$find_project_root.<locals>.<genexpr>O   s     CG3w<C   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   cwdlistr5   is_dirmaxr4   intersectionexistsis_filer#   get)	r*   r+   src	path_srcsr   src_parentscommon_base	directorypyproject_tomls	    `       r"   find_project_rootrN   .   sj   & !EEEODHHJ/01CGHCdhhj#!67HIH
 LUCGT\\tf2>K  C{CD#K
 "8K$7$78 
3	&&(...%%'o--((113'	4D(DEN.,,VR88 "222
3 (((3 Is   .E92Epath_search_start.c                    t        | |      \  }}|dz  }|j                         rt        |      S 	 t               }|j                         rt        |      S dS # t        t
        f$ r}t        d|       Y d}~yd}~ww xY w)z;Find the absolute filepath to a pyproject.toml if it existsr;   Nz-Ignoring user configuration directory due to )rN   rF   r?   find_user_pyproject_tomlPermissionErrorRuntimeErrorr   )rO   r+   path_project_root_path_pyproject_tomlpath_user_pyproject_tomles          r"   find_pyproject_tomlrY   b   s     -->Oq+.>>""$&''
#;#=  (//1 ()	
 	

 \* ;A5ABs   $A A A?'A::A?T)	patchablepath_configc                 t   t        |       }|j                  di       j                  di       }|j                         D ci c](  \  }}|j                  dd      j                  dd      |* }}}d|vr8t	        |      }|+|D cg c]  }|j
                  j                          c}|d<   |S c c}}w c c}w )zParse a pyproject toml file, pulling out relevant parts for Black.

    If parsing fails, will raise a tomllib.TOMLDecodeError.
    r=   r<   z-- r.   rU   target_version)r#   rG   itemsreplaceinfer_target_versionnamelower)r[   rM   configkvinferred_target_versions         r"   parse_pyproject_tomlrh   x   s      ,N+//;??LFCI<<>R41aaiib!))#s3Q6RFRv%"6~"F".@W'X1'XF#$M S
 (Ys   -B/!B5rM   c                     | j                  di       }|j                  dd      }|	 t        |      S y# t        $ r Y nw xY w	 t        |      S # t        t        f$ r Y yw xY w)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)rG   parse_req_python_versionr   parse_req_python_specifierr   )rM   project_metadatarequires_pythons      r"   ra   ra      s     &)))R8&**+<dCO"	+O<<   			-o>> .1 		s    
4 	A A 
A A! A!rn   c                     t        |       }|j                  d   dk7  ry	 t        |j                  d         gS # t        t        f$ r Y y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)rn   versions     r"   rk   rk      sU     o&GqQgooa0122
# s   9 A
Ac                     t        t        |             }|syt        D ci c]  }d|j                   | }}t	        |j                  |            }|r|D cg c]  }||   	 c}S yc c}w c c}w )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.
    Nz3.)strip_specifier_setr   r   valuerA   filter)rn   specifier_setrf   target_version_mapcompatible_versionss        r"   rl   rl      s|     (_(EFM5BCBqwwi.!+CC%)-*>*>?Q*R%S/BC!"1%CC	 D Ds   A)A.ry   c                 j   g }| D ]  }dt        |      v r|j                  |       #|j                  dv rWt        |j                        }t        |j                   |j                   d|j                         }|j                  |       |j                  dk(  rdt        |j                        }t        |j                        dkD  r%t        d|j                   d|j                         }|j                  |       |j                  |        t        dj                  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   2   K   | ]  }t        |        y wr%   )r?   )r0   r1   s     r"   r2   z&strip_specifier_set.<locals>.<genexpr>   s      <AQ <r6   )r?   appendoperatorr   rt   r   majorminorlenrq   r   join)ry   
specifiersr1   rt   strippeds        r"   rv   rv      s    J !#a&=a ZZ44aii(G AJJ<a!OPHh'ZZ3aii(G7??#a'7==/7==/BCa a !  < <<==r)   c                      t         j                  dk(  r"t        j                         dz  } t        |       S t        j
                  j                  dd      }t        |      j                         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	~/.configr<   )	sysplatformr   homeosenvironrG   
expanduserr(   )user_config_pathconfig_roots     r"   rQ   rQ      sk     ||w99;1 +,, jjnn%6D,779GC+,,r)   rootc                    | dz  }g }|j                         r+|j                  d      5 }|j                         }ddd       	 t        j                  |      S # 1 sw Y   xY w# 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: )rF   r   	readlinesr   
from_linesr   r   )r   	gitignorelinesgfrX   s        r"   get_gitignorer      s     |#IE^^W^- 	#LLNE	#''..	# 	# ! ykA3/0s#   AA% A"%	B.B  Breportc                     	 t        |       }	 |j                  |       y# t        $ r!}|r|j                  | d|        Y d}~yd}~ww xY w# t        $ r |r|j                  | d|        Y yw xY w)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_tors   )r   r   r   resolved_pathrX   s        r"   $resolves_outside_root_or_cannot_statr      s    '-
!!$'
   (?s&CD  (OPTv&VWs%     A 	A
AA
 A0/A0c                     	 | j                         j                        S # t        $ r Y nw xY wt        fd| j                  D        d       }|| j                  |      S t        |       j                        S )Nc              3   @   K   | ]  }t        |      k(  s|  y wr%   )r(   )r0   pr   s     r"   r2   z,best_effort_relative_path.<locals>.<genexpr>  s     Na?13E3MNs   )absoluter   rs   nextr5   r(   )r   r   root_parents    ` r"   best_effort_relative_pathr     su    }}**400 N4<<NPTUK,,4 ,,T22s   " 	..root_relative_pathgitignore_dictc                     || z  }|j                         D ]M  \  }}	 |j                  |      j                         }|j                         r|dz   }|j                  |      sM y y# t        $ r Y  yw xY w)N/TF)r_   r   as_posixrB   rs   
match_file)r   r   r   r   gitignore_pathpatternrelative_paths          r"   _path_is_ignoredr   $  s    
 $$D $2#7#7#9 	 ,,^<EEGM{{} - 3 m, 	  	 		s   4A''	A43A4normalized_pathr   c                 h    |r|j                  |       nd }t        |xr |j                  d            S )Nr   )searchboolgroup)r   r   matchs      r"   path_is_excludedr   8  s.     07GNN?+DE(%++a.))r)   pathsincludeexcludeextend_excludeforce_excludeverbosequietc             #   T  K   |j                         s
J d|        | D ]  }
|
j                         sJ |
j                  |      j                         }|r t        |||      r|j	                  |
d       Wd|z   }|
j                         r|dz  }t        ||      r|j	                  |
d       t        ||      r|j	                  |
d       t        ||      r|j	                  |
d       t        |
||      r|
j                         rF|i |||
z  t        |
      i}nd}t        |
j                         |||||||||	
      E d{    2|
j                         sD|
j                  d	k(  rt        |xs |	 
      sf|r|j                  |      nd}|s|
  y7 [w)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   rB   r   r   r   gen_python_filesiterdirrF   suffixr   r   )r   r   r   r   r   r   r   r   r   r   childr   new_gitignore_dictinclude_matchs                 r"   r   r   @  s    , W!PQUPVWW ?  """"..t4==? .n
 'JK !#55<<>#%.8'QR.?H .>'WX/tVD<<> )&$&5L-"6&"
 &*"'"   ]]_||x'0R)E	1 BIGNN+=>tM?Vs   EF(
F&F(#9F(	F(r!   zcolorama.AnsiToWin32c                 L    	 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     s6    U3
 1d%5t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   coloramar?   dictr#   r(   r>   rN   rY   rh   rA   ra   rk   rl   rv   rQ   r   r   r   r   r   r   r   TextIOWrapperr   r/   r)   r"   <module>r      s   	 	 
 8 8    , , & J J 5 " =w$  H $   TCZ DcN  
 $ 4   6:0)
3-0)),t0)
49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
 },- 
	(**S\D * 
*VD>V
V S\V S\	V
 CL4'V 3<$&V V },-4V V V d^VrU	U
2334UM  $#$s   'G# #G21G2