a
    a4                     @   s  U d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
 ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZmZ dd	l m!Z!m"Z" dd
l#m$Z$m%Z%m&Z&m'Z'm(Z( ddl)m)Z) ddl*m+Z, ddl*m-Z-m.Z.m/Z/m0Z0m1Z1 ddl2m3Z3 ddl2m4Z5 er>ee6d< nddl7m8Z8 e9dZ:e;ddhZ<e;ddhe<Z=e;dhZ>dZ?ee@df e6d< dZAeBe6d< dZCee@df e6d< eDdd  eEeD ZFee@df e6d!< d"ZGee@df e6d#< e;h d$ZHee@ e6d%< d&d'd(d(d)d"ZIee@ee@df f e6d*< d+ZJee@df e6d,< d-ZKd.ZLe0d/e.d0e-d1e1d2e/d3iZMee@e@f e6d4< d5ZNd6ZOd7d7d7d7d7d7d8d8d8d8d8d8d9ZPe!d7d:G d;d< d<ZQi eReQ d=d>iZSG d?d@ d@eQZTe@eee@gef ee f dAdBdCZUe@ee@ dDdEdFZVe@ee@ ee@ dGdHdIZWe
 e@ee@ee@ef f dJdKdLZXe
 e@ee@ ee@ef dMdNdOZYe@eZdDdPdQZ[eT Z\dS )RzPisort/settings.py.

Defines how the default settings for isort should be loaded
    N)	lru_cachePath)TYPE_CHECKINGAnyCallableDict	FrozenSetIterableListOptionalPatternSetTupleTypeUnion)warn   )sortingstdlibs)	dataclassfield)FormattingPluginDoesNotExistInvalidSettingsPathProfileDoesNotExistSortingFunctionDoesNotExistUnsupportedSettings)profiles)DEFAULT)
FIRSTPARTYFUTURELOCALFOLDERSTDLIB
THIRDPARTY)	WrapModes)from_stringtoml)r&   s   ^#!.*\bpython[23w]?\bZpyxZpxdpyZpyiZpex)zisort:skip_filezisort: skip_file.FILE_SKIP_COMMENTS   MAX_CONFIG_SEARCH_DEPTH).git.hgSTOP_CONFIG_SEARCH_ON_DIRSc                 c   s$   | ]}| d s|ddV  qdS )_r'    N)
startswithreplace).0target r4   -lib/python3.9/site-packages/isort/settings.py	<genexpr>>   s   r6   VALID_PY_TARGETS)z
.isort.cfgzpyproject.tomlz	setup.cfgztox.ini.editorconfigCONFIG_SOURCES>   Z__pypackages__z.bzrz.direnvZ_buildr,   z.toxZbuildz.pants.dZnode_modulesz.eggsz.mypy_cachevenvz.svnzbuck-outZdistz.venvz.noxr+   DEFAULT_SKIP)settingsisort)
tool.isort)r=   
tool:isort)*z*.pyz**.pyz*.{py}CONFIG_SECTIONS)r=   r?   r>   FALLBACK_CONFIG_SECTIONSZimport_heading_known_ZSTANDARD_LIBRARYZFUTURE_LIBRARYZFIRST_PARTYZTHIRD_PARTYZLOCAL_FOLDERKNOWN_SECTION_MAPPINGZruntime)Znot_skipZkeep_direct_and_as_importsTF)yZyestZon1truennofoff0false)frozenc                   @   s  e Zd ZU dZdZeed< e Ze	e ed< e
Ze	e ed< e Ze	e ed< e Ze	e ed< e Ze	e ed< d	Zeed
< dZeed< dZeed< dZeed< eZeedf ed< d	Zeed< edZe	e ed< e Ze	e ed< e Ze	e ed< e Ze	e ed< e Ze	e ed< e Ze	e ed< ee dZ!e"ee	e f ed< e#j$Z%e#ed< dZ&eedf ed< d Z'eed!< d"Z(eed#< d	Z)eed$< d	Z*eed%< e Z+e	e ed&< e Z,e	e ed'< e Z-e	e ed(< d	Z.eed)< d	Z/eed*< d	Z0eed+< dZ1eedf ed,< e2Z3eed-< ee dZ4e"eef ed.< d	Z5eed/< d	Z6eed0< d1Z7eed2< d	Z8eed3< d4Z9eed5< d6Z:eed7< dZ;eed8< d	Z<eed9< d	Z=eed:< d	Z>eed;< d	Z?eed<< d	Z@eed=< d	ZAeed>< d	ZBeed?< d	ZCeed@< d	ZDeedA< dZEeedB< d	ZFeedC< d	ZGeedD< d	ZHeedE< d	ZIeedF< e ZJe	e edG< d	ZKeedH< d	ZLeedI< d	ZMeedJ< dZNee"eeOf df edK< dZPeedL< dZQeedM< d	ZReedN< dZSeedO< dZTeedP< d	ZUeedQ< dZVeeWdf edR< d	ZXeedS< d	ZYeedT< d	ZZeedU< d	Z[eedV< dZ\eedW< dXZ]e^e_eee`gef  edY< d	ZaeedZ< e Zbe	e ed[< d	Zceed\< edZee	e ed]< efZge	e ed^< e Zhe	e ed_< e Zie	e ed`< e Zje	e eda< d	Zkeedb< d	Zleedc< d	Zmeedd< d	Zneede< d1Zoeedf< e Zpe	e edg< d1Zqeedh< d1Zreedi< d	Zseedj< d	Zteedk< d	Zueedl< d	Zveedm< d	Zweedn< e"eef Zxee dZye"eWezeW f edo< dpZ{eedq< drZ|eeds< dtZ}eedu< dXdvdwdxZ~edvdydzZdXS ){_ConfigzDefines the data schema and defaults used for isort configuration.

    NOTE: known lists, such as known_standard_library, are intentionally not complete as they are
    dynamically determined later on.
    3
py_versionforce_to_topskipextend_skip	skip_globextend_skip_globFskip_gitignoreO   line_lengthr   wrap_lengthr/   line_ending.sectionsno_sections)Z
__future__known_future_libraryknown_third_partyknown_first_partyknown_local_folderknown_standard_libraryextra_standard_library)default_factoryknown_othermulti_line_outputr4   forced_separatez    indentz  #comment_prefixlength_sortlength_sort_straightlength_sort_sectionsadd_importsremove_importsappend_onlyreverse_relativeforce_single_linesingle_line_exclusionsdefault_sectionimport_headingsbalanced_wrappinguse_parenthesesTorder_by_typeatomiclines_after_importsr   lines_between_sectionslines_between_typescombine_as_importscombine_starinclude_trailing_comma
from_firstverbosequiet
force_adds'force_alphabetical_sort_within_sectionsforce_alphabetical_sortforce_grid_wrapforce_sort_within_sectionslexicographicalgroup_by_packageignore_whitespaceno_lines_beforeno_inline_sortignore_commentscase_sensitivesourcesvirtual_env	conda_envensure_newline_before_comments	directoryprofile
honor_noqa	src_pathsold_findersremove_redundant_aliasesfloat_to_topfilter_files	formatterNformatting_functioncolor_outputtreat_comments_as_codetreat_all_comments_as_codesupported_extensionsblocked_extensions	constantsclasses	variablesdedup_headingsonly_sectionsonly_modifiedcombine_straight_imports auto_identify_namespace_packagesnamespace_packagesfollow_linksindented_import_headings#honor_case_in_force_sorted_sections&sort_relative_in_force_sorted_sectionsoverwrite_in_placereverse_sort
star_first
git_ignorez{error}: {message}format_errorz{success}: {message}format_successnatural
sort_orderreturnc                 C   sP  | j }|dkrjtjjdkr,tjjdkr,d}n>tjjdkrVtjjdksPtjjdkrVd}ntjj tjj }|tvrtd	| d
t |dkrt| dd|  | j	st| dt
tt| j j | jtjkrtj}t| d| | jr$t| dd t| dd t| dd t| dd | j| jkrLtd| j d| j dd S )Nauto      2      	   rQ   zThe python version z} is not supported. You can set a python version with the -py or --python-version flag. The following versions are supported: allrR   r'   rc   rg   r   Tr^   r}   r   r   z<wrap_length must be set lower than or equal to line_length: z > .)rR   sysversion_infomajorminorr7   
ValueErrorobject__setattr__rc   	frozensetgetattrr   Zstdlibrg   r$   ZVERTICAL_GRID_GROUPED_NO_COMMAZVERTICAL_GRID_GROUPEDr   r[   rZ   )selfrR   Zvertical_grid_groupedr4   r4   r5   __post_init__   sN    

z_Config.__post_init__c                 C   s   t | S N)idr   r4   r4   r5   __hash__  s    z_Config.__hash__)__name__
__module____qualname____doc__rR   str__annotations__r   rS   r	   r;   rT   rU   rV   rW   rX   boolrZ   intr[   r\   SECTION_DEFAULTSr]   r   r^   r_   r`   ra   rb   rc   rd   r   dictrf   r   r$   ZGRIDrg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   r#   rt   ru   rv   rw   rx   ry   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   SUPPORTED_EXTENSIONSr   BLOCKED_EXTENSIONSr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zimport_dependenciesr   r   r   r   r   r   r   r4   r4   r4   r5   rP      s   
)rP   sourcedefaultsc                       s   e Zd Zdeeee ed fddZeedddZ	eee
 d	d
dZe
edddZeeeee ef  dddZeeedf dddZeee dddZeee dddZeedee f dddZeee dddZ  ZS )Configr/   N)settings_filesettings_pathconfigconfig_overridesc           %         sF  d | _ d | _d | _d | _d | _|rt| }|| |d dd|d< |	d |	d |	d |	d |	d t
 jf i | d S |d	d
}tg}|rt|ttj|t}tj|}	|s|std| d nB|r tj|st|tj|}t|\}	}ni }t }	|d|dd}
i }|
r|
tvrdd l}|dD ]}t|j|   qf|
tvrt!|
t|
  }|
 d|d< |"| |r|"| |rt#|d< |"| i |||}d|v rFt$|d }|% rdt&| }n"|'d'd}|( dkr>d}||d< i }i }t)|* D ]8\}}|+t,r@|dvr@|t-t,d  ( }|. }|	| |t/v rdt/| (  }||v r|std| d| d| d nt0|||< nHt0|||< ||ddvr@|s@td | d!| d"|dt1 d# |+t2rht$|||t-t2d  ( < t|d }|d u rqZt3||||< qZ|ddD ]P}|t1v rq|( |vrd$4|5 }td%| d&|(  d'| d( qd)|vr(|dd rtj|d nt |d)< t6|d)|	7 }|8 rJ|n|j9}d*|vrl|d+ |f|d*< n^t: }|d*dD ]>}d,t$|v r|;|n|| g}|D ]}|<| qq~t)||d*< d-|v rdd l}|d.D ](}|j|d- kr|  |d/<  qqt=|d- |	dd  |	d0d  |	d1d  d2d3 |D }|r|D ]} |	|  qX|std4d$4| d5 |r||d6< |r|D ]}!|	t2 |!  q||d7< i }"t:|5 >t?t@d8i 5 D ]6}#tA|D ]&}$|#|$v r|$|# |$d d9|"|#< qq|"r(tB|"t
 jf d0t)|i| d S ):NrR   r'   r/   _known_patterns_section_comments_skips_skip_globs_sorting_functionr   Fz&A custom settings file was specified: z but no configuration was found inside. This can happen when [settings] is used as the config header instead of [isort]. See: https://pycqa.github.io/isort/docs/configuration/config_files/#custom_config_files for more information.r   r   zisort.profilesz profiler   ri    '"tab	)rc   r_   r`   ra   rb   rC   zCan't set both z and z% in the same config file.
Default to zN if unsure.

See: https://pycqa.github.io/isort/#custom-sections-and-ordering.r]   r4   `z` setting is defined, but z. is not included in `sections` config option: zD.

See: https://pycqa.github.io/isort/#custom-sections-and-ordering.z, z`sections` setting includes z, but no known_zE is defined. The following known_SECTION config options are defined: r   r   r   srcr@   r   zisort.formattersr   r   Zruntime_src_pathsc                 S   s   g | ]}|t v r|qS r4   )DEPRECATED_SETTINGS)r2   optionr4   r4   r5   
<listcomp>  s   z#Config.__init__.<locals>.<listcomp>z,W0503: Deprecated config options were used: za.Please see the 5.0.0 upgrade guide: https://pycqa.github.io/isort/docs/upgrade_guides/5.0.0.htmlrf   ru   Z__dataclass_fields__)valuer   )Cr   r   r   r   r   varscopyupdater1   popsuper__init__get_DEFAULT_SETTINGS_get_config_datarA   ospathbasenamerB   dirnamer   existsr   abspath_find_configgetcwdr   pkg_resourcesiter_entry_points
setdefaultnameloadr   appendRUNTIME_SOURCEr   isdigitr   striplowertupleitemsr0   KNOWN_PREFIXlenupperrD   r   r   IMPORT_HEADING_PREFIXtypejoinkeysr   resolveis_dirparentsetglobaddr   
differencer   rP   reversedr   )%r   r   r   r   r   Zconfig_varsr   r   Zconfig_settingsZproject_rootZprofile_namer   r  ZpluginZcombined_configri   rf   ru   keyr   Zimport_headingZmaps_to_sectionZsection_nameZdefault_valuesectionZconfig_keysZ	path_rootr   Zsrc_pathZ
full_pathsr   Zdeprecated_options_usedZdeprecated_optionZimport_heading_keyZunsupported_config_errorsr   r   	__class__r4   r5   r   #  s8   





















 


zConfig.__init__)	file_namer   c                 C   s   t j|\}}|d}|| jv r(dS || jv r6dS |drDdS ztt |j	r^W dS W n t
yr   Y n0 z8t|d}|d}W d    n1 s0    Y  W n t
y   Y dS 0 tt|S d S )Nr   TF~rbd   )r   r   splitextlstripr   r   endswithstatS_ISFIFOst_modeOSErroropenreadliner   _SHEBANG_REmatch)r   r%  _rootextfpliner4   r4   r5   is_supported_filetype  s&    




,zConfig.is_supported_filetype)folderr   c                 C   s  ddi}zt jdd|ddgd|d}W n t jy<   Y d S 0 t|  }g }tj|d	d
D ]:\}}}d|v r||d |D ]}	|	tj
||	 qq`dt|ddg}
z2t jdg|
ddddd|d|d}W n t jy   Y d S 0 dd |ddD | j|< |S )NLANGzC.UTF-8gitz-Cz	rev-parsez--show-toplevelutf-8)encodingenvF)followlinksr+   z-czcore.quotePath=zcheck-ignorez-zz--stdinz
--no-index )r=  r>  inputc                 S   s   h | ]}t |qS r4   r   )r2   rK   r4   r4   r5   	<setcomp>:      z1Config._check_folder_gitignore.<locals>.<setcomp>)
subprocessZcheck_outputZCalledProcessErrorr   rstripr  r   walkremover  r   r  r   splitr   )r   r9  r>  Ztopfolder_result
git_folderfilesrootZ_dirsZ	git_filesZgit_fileZgit_optionsZignoredr4   r4   r5   _check_folder_gitignore  s4    


 zConfig._check_folder_gitignore)	file_pathr   c           	         s  j r0tj | jv r0tj| j }nt|}t|}|dd}|dd dkrh|dd }j	D ]&}t
|t
|ddkrn dS qntj|}|d r|d j	v rdS tj|d }qjD ]&}t||std| |r dS qtj|s*tj|s*tj|s*dS jr|jd	krBdS d|| g}jD ]( t fd
d|D rX  qqXt|jrtfdd|D rdS dS )zSReturns True if the file and/or folder should be skipped based on current settings.\/r   r   :NTr   r+   c                 3   s   | ]} |j v V  qd S r   )parentsr2   r   )r9  r4   r5   r6   e  rC  z$Config.is_skipped.<locals>.<genexpr>c                 3   s   | ]}|j   v V  qd S r   )r   rR  )rI  r   r4   r5   r6   k  rC  F)r   r   r  rQ  r   r   relpathr   r1   skips	posixpathr  rH  
skip_globsfnmatchisfileisdirislinkrX   r	  r   anyrL  r  )	r   rM  r%  Zos_pathZnormalized_pathZ	skip_pathZpositionZsglobZ
file_pathsr4   )r9  rI  r   r5   
is_skipped=  sF    


*

 zConfig.is_skippedr   c                    s    j d ur j S g  _ tgdd  jD  }t|D ]}t|| }t | }t | j	|d}t d| d}t
||} fdd|D }|D ]6}	d|	ddd	d
 d }
 j t|
|f qq4 j S )Nc                 S   s   g | ]}|t kr|qS r4   )r"   )r2   r"  r4   r4   r5   r   v  rC  z)Config.known_patterns.<locals>.<listcomp>r4   Zextra_c                    s    g | ]}  |D ]}|qqS r4   )_parse_known_pattern)r2   known_patternpatternr   r4   r5   r   }  s   ^r@   z.*?z.?$)r   r"   r]   r   rD   r   r  r  r   rf   r  unionr1   r  recompile)r   Zpattern_sectionsZ	placementZknown_placement
config_keyZknown_modulesZextra_modulesZall_modulesknown_patternsr^  Zregexpr4   r   r5   rg  p  s"    

zConfig.known_patterns.c                 C   s0   | j d ur| j S tdd | j D | _ | j S )Nc                 s   s   | ]}d | V  qdS )z# Nr4   )r2   headingr4   r4   r5   r6     rC  z*Config.section_comments.<locals>.<genexpr>)r   r  ru   valuesr   r4   r4   r5   section_comments  s    
zConfig.section_commentsc                 C   s&   | j d ur| j S | j| j| _ | j S r   )r   rT   rc  rU   r   r4   r4   r5   rT    s    
zConfig.skipsc                 C   s&   | j d ur| j S | j| j| _ | j S r   )r   rV   rc  rW   r   r4   r4   r5   rV    s    
zConfig.skip_globsc                 C   s   | j d ur| j S | jdkr$tj| _ nd| jdkr6t| _ nRddg}dd l}|dD ]*}||j |j| jkrP|	 | _  qqPt
| j|| j S )Nr   Znativer   zisort.sort_function)r   r   r   Z	naturallysortedr  r  r  r	  r
  r   )r   Zavailable_sort_ordersr  Zsort_pluginr4   r4   r5   sorting_function  s    




zConfig.sorting_function)r_  r   c                    s@     tjjr6 fddttjj D }n g}|S )zIExpand pattern if identified as a directory and return found sub packagesc              	      s*   g | ]"}t jt jj |r|qS r4   )r   r   rY  r  r   )r2   filenamer_  r   r4   r5   r     s   z/Config._parse_known_pattern.<locals>.<listcomp>)r+  r   r   seplistdirr  r   )r   r_  patternsr4   rn  r5   r]    s    zConfig._parse_known_pattern)r/   r/   N)r   r   r   r   r   rP   r   r   r   r8  r   rL  r\  propertyr   r   r   rg  rj  r	   rT  rV  r   rl  r]  __classcell__r4   r4   r#  r5   r   "  s0       `!3 r   )setting_namer   c                 C   s    t t| d}|tkrt}|S )Nr/   )r  r   r   r$   wrap_mode_from_string)rt  Ztype_converterr4   r4   r5   _get_str_to_type_converter  s    
rv  )r   r   c                 C   s8   t | trdd | D S dd | dddD }|S )Nc                 S   s   g | ]}|  qS r4   r  r2   itemr4   r4   r5   r     rC  z_as_list.<locals>.<listcomp>c                 S   s   g | ]}|  r|  qS r4   rw  rx  r4   r4   r5   r     rC  
,)
isinstancelistr1   rH  )r   Zfilteredr4   r4   r5   _as_list  s    
r~  )cwdri  r   c                    s    fdd|D }|S )Nc                    s:   h | ]2}| tjjs2|tjjr2tj |n|qS r4   )r0   r   r   ro  r+  r  )r2   r   r  r4   r5   rB    s   z_abspaths.<locals>.<setcomp>r4   )r  ri  pathsr4   r  r5   	_abspaths  s    
r  )r   r   c              	   C   s   | }d}|r|t k rtD ]f}tj||}tj|rzt|t| }W n$ tyl   t	d|  i }Y n0 |r||f  S qt
D ]&}tjtj||r|i f  S qtj|d }||krq|}|d7 }q| i fS )Nr   z.Failed to pull configuration information from r   )r*   r9   r   r   r  rX  r   rA   	Exceptionr   r-   rY  rH  )r   Zcurrent_directoryZtriesZconfig_file_nameZpotential_config_fileZconfig_dataZstop_dirZnew_directoryr4   r4   r5   r    s0    

r  )rM  r]   r   c              	   C   s  i }t | ddV}| dr`t|}|D ].}|}|dD ]}||i }q>|| q, n| drd}| }	|r| }d|v r|	|	 q| }	qvt
jdd	}|| |D ]}|d
r>|dr>|td
d }
| D ]L}|d
r|dr|
tdd |td
d dv r||| qq||r||| qW d    n1 sp0    Y  |r| |d< | drv|dd }|dd }|dkr|dd }|dkrd|rt|pd |d< n&|dkrd|rt|pd |d< |dd }|rd|dksF| rd|dkrXtdnt||d< d d! | D }| D ] \}}t|}|tkrtt|||< n|tkrtt||||< n|tkrt|tst|}|||< n|trt t!j"#| t|||< n|d"krnz||}W n. t$yb   |%  d#krZd$nd%}Y n0 |||< n0|d&krt&|d'd(||< n||||< q~|S ))Nr<  )r=  z.tomlr   r8   rz  [F)strictz*.{}rz   c                 S   s   |   S r   rw  )textr4   r4   r5   <lambda>"  rC  z"_get_config_data.<locals>.<lambda>r{  r   indent_styler/   indent_sizer   Z	tab_widthspacer      ri   r   r   max_line_lengthrL   infrZ   c                 S   s,   i | ]$\}}|t  v s"|tr||qS r4   )r   r  r0   r  )r2   r!  r   r4   r4   r5   
<dictcomp>>  s   z$_get_config_data.<locals>.<dictcomp>r   rN   r   r   rj   r   r   )'r0  r+  r&   r
  rH  r   r   tellr1  seekconfigparserZConfigParserZ	read_filer0   r  r  mapr  Zhas_sectionr   r  r   r  floatrv  r  r~  r   r   r|  _as_boolr  r  r   r   r  r   r  r   )rM  r]   r<   Zconfig_filer   r"  Zconfig_sectionr!  r7  Zlast_position	extensionrf  r  r  r  r   Zexisting_value_typeresultr4   r4   r5   r      s    






2







 

r   c                 C   s4   zt |   W S  ty.   td|  Y n0 dS )zGiven a string value that represents True or False, returns the Boolean equivalent.
    Heavily inspired from distutils strtobool.
    zinvalid truth value N)_STR_BOOLEAN_MAPPINGr  KeyErrorr   )r   r4   r4   r5   r  _  s    r  )]r   r  rW  r   rU  rd  r,  rD  r   	functoolsr   pathlibr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   warningsr   r/   r   r   Z_futurer   r   
exceptionsr   r   r   r   r   r   r]   r   r   r   r    r!   r"   r#   Z
wrap_modesr$   r%   ru  r   Z	_vendoredr&   re  r2  r   ZCYTHON_EXTENSIONSr   r   r(   r   r*   r   r-   r  dirr7   r9   r;   rA   rB   r  r  rD   r  r   r  rP   r   r   r   rv  r~  r  r  r   r   r  ZDEFAULT_CONFIGr4   r4   r4   r5   <module>   s   <


    &&	
"  ^
