bgfdZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z mZmZmZmZmZmZddlmZdd lmZd d lmZmZmZd d lmZmZmZmZd d l m!Z!m"Z"m#Z#d dlm$Z$m%Z%d dl&m'Z(d dl&m)Z*d dl+m,Z,m-Z-m.Z.GddeZ/de-dddfde0dee0de.dee de1dee1efde de0fdZ2dde-ddfde0dee1efdee0de.dee de1de de1fdZ3de-ddddfd ed!edee0de.dee de1dee1efd"e1de de1fd#Z4dde-ddfd edee1efdee0de.dee de1de de1fd$Z5de-dddfd%ee0e fdee1efde.dee de1dee0de de1fd&Z6d'e%de fd(Z7ej8deefd)Z9ej8d%ee0e fd'e%deefd*Z:de-ddddddfd%ee0e fdee0de.dee de1d+e1dee1efd,e1d-eede de1fd.Z;e-dddfde0de.dee d/ee1e/fd0e1de deej<fd1Z=e-ddddfd ede.dee d/ee1e/fd0e1d2eee0de deej<fd3Z>e-dddfd%ee0e fde.dee d/ee1e/fd0e1de deej<fd4Z?e-dddfd5eee0e fde.dee d/ee1e/fd0e1de deej<fd6Z@de-fd7ee de.de de.fd8ZAdS)9) ImportKeycheck_code_string check_file check_streamfind_imports_in_codefind_imports_in_filefind_imports_in_pathsfind_imports_in_stream place_moduleplace_module_with_reasonsort_code_string sort_file sort_streamN)EnumStringIO)chain)Path)AnyIteratorOptionalSetTextIOUnioncast)warn)core)filesidentifyio)ExistingSyntaxErrorsFileSkipCommentFileSkipSettingIntroducedSyntaxErrors)$ask_whether_to_apply_changes_to_filecreate_terminal_printershow_unified_diff)EmptyFile)module)module_with_reason)CYTHON_EXTENSIONSDEFAULT_CONFIGConfigc"eZdZdZdZdZdZdZdS)raDefines how to key an individual import, generally for deduping. Import keys are defined from less to more specific: from x.y import z as a ______| | | | | | | | PACKAGE | | | ________| | | | | | MODULE | | _________________| | | | ATTRIBUTE | ______________________| | ALIAS rN)__name__ __module__ __qualname____doc__PACKAGEMODULE ATTRIBUTEALIASZ/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/isort/api.pyrr+s.&G FI EEEr=rFcode extensionconfig file_pathdisregard_skip show_diff config_kwargsreturnc t|}t}td||d|}t||||||||d|S)aSorts any imports within the provided code string, returning a new string with them sorted. - **code**: The string of code with imports that need to be sorted. - **extension**: The file extension that contains imports. Defaults to filename extension or py. - **config**: The config object to use when sorting imports. - **file_path**: The disk location where the code string was pulled from. - **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file. - **show_diff**: If `True` the changes that need to be done will be printed to stdout, if a TextIO stream is provided results will be written to it, otherwise no diff will be computed. - ****config_kwargs**: Any config modifications. pathrA)r@rArBrCrDrr<)r_configrseekread) r?r@rArBrCrDrE input_stream output_streams r>r r Es(D>>LJJM  D)F D Dm D DF%q     r=c dtd||d|}tt||||||S)a2Checks the order, format, and categorization of imports within the provided code string. Returns `True` if everything is correct, otherwise `False`. - **code**: The string of code with imports that need to be sorted. - **show_diff**: If `True` the changes that need to be done will be printed to stdout, if a TextIO stream is provided results will be written to it, otherwise no diff will be computed. - **extension**: The file extension that contains imports. Defaults to filename extension or py. - **config**: The config object to use when sorting imports. - **file_path**: The disk location where the code string was pulled from. - **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file. - ****config_kwargs**: Any config modifications. rHrDr@rArBrCr<)rJrr)r?rDr@rArBrCrEs r>rrisM* D)F D Dm D DF %    r=TrMrN raise_on_skipc |p|r|jdpd}|rt} t|} t d | | |||||d|} | d| dt | | ||dur|n||j| Std ||d|}t|pd} |s&|r$| |rt| |} |j r |}t|| d dd nA#t$r4|tvrt!| |jrt%| d YnwxYwt|}|st} t)j|| ||| } n#t,$rt-| wxYw|j r| d t| | d dd | dnA#t$r4|tvrt/| |jrt%| d YnwxYw| |kr'|| | S)aSorts any imports within the provided code stream, outputs to the provided output stream. Returns `True` if anything is modified from the original input stream, otherwise `False`. - **input_stream**: The stream of code with imports that need to be sorted. - **output_stream**: The stream where sorted imports should be written to. - **extension**: The file extension that contains imports. Defaults to filename extension or py. - **config**: The config object to use when sorting imports. - **file_path**: The disk location where the code string was pulled from. - **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file. - **show_diff**: If `True` the changes that need to be done will be printed to stdout, if a TextIO stream is provided results will be written to it, otherwise no diff will be computed. - ****config_kwargs**: Any config modifications. .py)rMrNr@rArBrCrQrT file_input file_outputrBoutput color_outputrHzPassed in contentexecrz< Python AST errors found but ignored due to Cython extension)r@rArQr<)suffixlstriprrLrrKr(rYrJstr is_skippedr$atomiccompile SyntaxErrorr-r"verboserreadablerprocessr#r%write)rMrNr@rArBrCrDrQrE_output_stream _input_streamchangedcontent_source_internal_output file_contents r>rrs}0QiHI,<,C,CC,H,HQTI! !2!2!4!455   &()'       A1$))++&++--$-$5$5==9,       D)F D Dm D DF9&9::N .i.F,=,=i,H,H.n---$ }* ',,..L L.&!Q ? ? ? ?    111*>:::~ %ccc   -- %%'' *'zz  .,  '     ...n---.} 9a     $))++^VQ J J J  ! !! $ $ $ $    111,^<<<~ %ccc   } , ,    0 5 5 7 7 8 8 8 Ns0''E;F  F GG6:I;JJc td ||d|}|r!t|}t|t||||}t |j|j|j}|s*|j r!|j s| |pdddS| |pdd|rt} | d|} tt| | ||||| dt| | ||durd n||j d S) aEChecks any imports within the provided code stream, returning `False` if any unsorted or incorrectly imports are found or `True` if no problems are identified. - **input_stream**: The stream of code with imports that need to be sorted. - **show_diff**: If `True` the changes that need to be done will be printed to stdout, if a TextIO stream is provided results will be written to it, otherwise no diff will be computed. - **extension**: The file extension that contains imports. Defaults to filename extension or py. - **config**: The config object to use when sorting imports. - **file_path**: The disk location where the code string was pulled from. - **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file. - ****config_kwargs**: Any config modifications. rH)rMrNr@rArBrC)colorerrorsuccessz Everything Looks Good!Tz1 Imports are incorrectly sorted and/or formatted.rNrUFr<)rJrrLrr)r'rY format_errorformat_successrb only_modifiedrornrKr() rMrDr@rArBrCrErhprinterrN file_contentss r>rrs* D)F D Dm D DF5 1 1 3 344 !% G&!) I&"6 I OOyBGGG H H Ht MMY_"WWWXXX  !$))++ !-00')      1$%**,,$,,44),      5r=filenamec ~|}d|vr`|dd}|rH||} |jrt| dd|t di| d}t j|5} t| j f||||p| j |d|cdddS#1swxYwYdS)a)Checks any imports within the provided file, returning `False` if any unsorted or incorrectly imports are found or `True` if no problems are identified. - **filename**: The name or Path of the file to check. - **show_diff**: If `True` the changes that need to be done will be printed to stdout, if a TextIO stream is provided results will be written to it, otherwise no diff will be computed. - **config**: The config object to use when sorting imports. - **file_path**: The disk location where the code string was pulled from. - **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file. - **extension**: The file extension that contains imports. Defaults to filename extension or py. - ****config_kwargs**: Any config modifications. config_trieNr used for file rrPr<) popsearchrbprintr/r!r*rLrstreamrI) rvrDrArBrCr@rE file_configrx config_info source_files r>rr1s9*!K %%#'' t<<  3%,,X66K~ DQBBBBCCC 22;q>22K h    ;   3;#3)                        sB22B69B6rcP|j|jjdzS)Nz.isorted)rI with_suffixr[)rs r> _tmp_filer]s$   ' ' (8(?*(L M MMr=c#.KtdVdS)N)newlinerr<r=r> _in_memory_output_stream_contextras# 4      r=c#Kt|}|d|jd5}tj|||VddddS#1swxYwYdS)Nzw+rp)encodingr)ropenrshutilcopymode)rvrtmp_filerNs r>_file_output_stream_contextrfs%%H tk&:B G G=(+++sAAA ask_to_applywrite_to_stdoutrXc |} d| vr`| dd} | rH| |} |jrt| dd|t di| d} t j|5} |p| j}td|| d| }d} |r&t| j tj ||||}n`| |jrt}nt!|| }|5}t| j |||||}|d|ro|s|r| j dt%| j |||d urdnt't(||j |s#|rvt-t/| jsU ddd |js#t1| }|n#t4$rYnwxYwddddS| j |jr\|d| jd 5}t;j||dddn #1swxYwYdddn #1swxYwY|rN|js)t1| }|| j|j std | j |js#t1| }|n#t4$rYnwxYw# |js$t1| }|ww#t4$rYwwxYwxYwt| j |||||}|ry|rw| j d|dt%| j |||d urdn||j | j n?#tB$rtE|d Yn!tF$rtE|dYnwxYw|cdddS#1swxYwYdS)a:Sorts and formats any groups of imports imports within the provided file or Path. Returns `True` if the file has been changed, otherwise `False`. - **filename**: The name or Path of the file to format. - **extension**: The file extension that contains imports. Defaults to filename extension or py. - **config**: The config object to use when sorting imports. - **file_path**: The disk location where the code string was pulled from. - **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file. - **ask_to_apply**: If `True`, prompt before applying any changes. - **show_diff**: If `True` the changes that need to be done will be printed to stdout, if a TextIO stream is provided results will be written to it, otherwise no diff will be computed. - **write_to_stdout**: If `True`, write to stdout instead of the input file. - **output**: If a TextIO is provided, results will be written there rather than replacing the original file content. - ****config_kwargs**: Any config modifications. rxNrryrrHF)rMrNrArBrCr@TrUwzFixing z- unable to sort due to existing syntax errorsz5 unable to sort as isort introduces new syntax errorsr<)$rzr{rbr|r/r!r*rLrIrJrr}sysstdoutoverwrite_in_placerrrKr(rrrYr&r]runlinkFileNotFoundErrorcloserr copyfileobjreplacequietr"rr%)rvr@rArBrCrrDrrXrEr~rxrractual_file_pathrhoutput_stream_contextrNrfss r>r r ns8!K %%#'' t<<  3%,,X66K~ DQBBBBCCC 22;q>22K h  `;$8 (8T.{TTmTTZ ]T /%!,!3"%*!.#1' >5!!44T4V4V114O (+5513!Nm&1-8-?.;'-*:/=*3 '''G*..q111&N#,!5 !5$/$6$;$;A$>$>$>$53>3E3J3J3L3L4A4F4F4H4H2B+4+<+<04t-1&)-D-D5;5H%&%&%&%&(1%5(4%50T,/ 0@,A,A1*1*%5 059!N!N!N!N!N!NR!#)#<2+4[+A+A ( 1 1 10!!! D!I````````h!, 2 8 8 : : :#)#<!N$1$6$6q$9$9$9)4)9)>)>s)C)C%Nr(.(:="(M(M(M%N%N%N%N%N%N%N%N%N%N%N%N%N%N%NA!N!N!N!N!N!N!N!N!N!N!N!N!N!N!ND#D#)#<C+4[+A+A ( 0 01A B B B#)<D %&B 0@&B&B C C C!#)#<2+4[+A+A ( 1 1 10!!! D! !#)#<2+4[+A+A ( 1 1 1 12 1!!! D!*%0%7&,%"2'5"+ G 9 #*//222 A)'2'9'>'>'@'@(. &6+4+<+<44))/)<  &,,...# U U U $SSS T T T T T% ] ] ] $[[[ \ \ \ \ \ ]A``````````````````sQ8"+P+(L;6CJ$ L;*G?>P+? H  P+ H  P+AJ$+J  J$ J J$J J$ L;$J( (L;+J( ,AL;*L+*P++ L85P+7L88P+;M9=*M)'M9) M6 3M95M6 6M99B1P+*Q8+Q'Q8 Q'$Q8&Q''Q88Q<?Q<uniquetop_onlyc +TKtdt|||||d|Ed{VdS)aFinds and returns all imports within the provided code string. - **code**: The string of code with imports that need to be sorted. - **config**: The config object to use when sorting imports. - **file_path**: The disk location where the code string was pulled from. - **unique**: If True, only the first instance of an import is returned. - **top_only**: If True, only return imports that occur before the first function or class. - ****config_kwargs**: Any config modifications. rMrArBrrNr<)r r)r?rArBrrrEs r>rrsk"&d^^   r=_seenc+Ktdd|i|}tj||||}|s|Ed{V|tn|}|D]} |dtjfvr| } nj|tjkr| jd| j } nH|tj kr| j} n0|tj kr | j dd} | r| |vr| | | VdS)afFinds and returns all imports within the provided code stream. - **input_stream**: The stream of code with imports that need to be sorted. - **config**: The config object to use when sorting imports. - **file_path**: The disk location where the code string was pulled from. - **unique**: If True, only the first instance of an import is returned. - **top_only**: If True, only return imports that occur before the first function or class. - **_seen**: An optional set of imports already seen. Generally meant only for internal use. - ****config_kwargs**: Any config modifications. rA)rArBrNTrSrr<)rJr importssetrr; statementr:r+ attributer9r8splitadd) rMrArBrrrrEidentified_importsseenidentified_importkeys r>r r sJ& 4 4F 4m 4 4F!)Vy8 &%%%%%%%%#mSUUUD/ $ $ dIO, , ,#--//CC y* * *&-MM0A0KMMCC y' ' '#*CC y( ( (#*0055a8C  $3d?? HHSMMM# # # # $ $r=c +Ktj|5}td|j||p|j||d|Ed{VddddS#1swxYwYdS)acFinds and returns all imports within the provided source file. - **filename**: The name or Path of the file to look for imports in. - **extension**: The file extension that contains imports. Defaults to filename extension or py. - **config**: The config object to use when sorting imports. - **file_path**: The disk location where the code string was pulled from. - **unique**: If True, only the first instance of an import is returned. - **top_only**: If True, only return imports that occur before the first function or class. - ****config_kwargs**: Any config modifications. rNr<)r!r*rLr r}rI)rvrArBrrrErs r>rr=s$ h   ;) $+3;#3                               s%AAApathsc +Ktddi|rtndtfdtjt t |ggDEd{VdS)ajFinds and returns all imports within the provided source paths. - **paths**: A collection of paths to recursively look for imports within. - **extension**: The file extension that contains imports. Defaults to filename extension or py. - **config**: The config object to use when sorting imports. - **file_path**: The disk location where the code string was pulled from. - **unique**: If True, only the first instance of an import is returned. - **top_only**: If True, only return imports that occur before the first function or class. - ****config_kwargs**: Any config modifications. rANc3@K|]}t|VdS))rrArrN)r).0 file_namerArrrs r> z(find_imports_in_paths..osT   !&(RV         r=r<)rJrrrfindmapr])rrArBrrrErs ` `` @r>rrZs$ 4 4F 4m 4 4F(.8suuuDD       #ZCRHH    r=rIc |r|tur d|vr d|vr||d<|r$|turtdtdi|}|S)N settings_path settings_fileziYou can either specify custom configuration options using kwargs or passing in a Config object. Not Both!r<)r. ValueErrorr/)rIrArEs r>rJrJxs{ ..  = 0 0 = 0 0)- o&)  ' '8  ((-(( Mr=)B__all__ contextlibrrenumrr!r itertoolsrpathlibrtypingrrrrrrrwarningsrisortrrprr exceptionsr"r#r$r%formatr&r'r(r)r*placer+r r,r settingsr-r.r/rr]boolr rrrrrcontextmanagerrrr Importrr rrrJr<r=r>rs   DDDDDDDDDDDDDDDDDD!!!!!!!!!! eddddddddd))))))AAAAAA??????????8 $# $ %* ! ! ! }!  ! ~ !  ! T6\" ! !  ! ! ! ! L&+## $  T6\"}   ~    F $# $ %*bbbb}b  b ~ b  bT6\"bbb bbbbN&+## $ @@@T6\"@}@  @ ~ @  @@ @@@@J&+# $# ) ) CI) T6\")  ) ~ )  ) } ) )  ) ) ) ) XN4NDNNNN !(6*:!!!! %T *:RZ[aRb $# $%*!#GGCIG}G G~ G  G  GT6\"GG V GG GGGGX$ $%*   ~ $ / "     ho:$ $%* $ '$'$'$ '$~'$ $ / " '$  '$ CH  '$'$ho'$'$'$'$X$ $%*   CI  ~  $ / "      ho    >$ $%*  E#t)$ % ~ $ / "     ho> . 4.)/SV r=