o
    bS                     @   s   d Z ddlmZmZmZm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mZ ddlmZmZmZmZmZ deZe
dZdd	 ZG d
d deZdd Zdd ZG dd dejZ dddZ!dddZ"e#dkrze"  dS dS )a    Tool for sorting imports alphabetically, and automatically separated into sections.

Copyright (C) 2013  Timothy Edmund Crosley

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

    )absolute_importdivisionprint_functionunicode_literalsN)SortImports__version__)DEFAULT_SECTIONS	WrapModesdefault	from_pathshould_skipa  
/#######################################################################\

     `sMMy`
     .yyyy-                                                      `
    ##soos##                                                    ./o.
          `     ``..-..`         ``...`.``         `   ```` ``-ssso```
     .s:-y-   .+osssssso/.     ./ossss+:so+:`    :+o-`/osso:+sssssssso/
     .s::y-   osss+.``.``     -ssss+-.`-ossso`   ssssso/::..::+ssss:::.
     .s::y-   /ssss+//:-.`   `ssss+     `ssss+   sssso`       :ssss`
     .s::y-   `-/+oossssso/  `ssss/      sssso   ssss/        :ssss`
     .y-/y-       ````:ssss`  ossso.    :ssss:   ssss/        :ssss.
     `/so:`    `-//::/osss+   `+ssss+-/ossso:    /sso-        `osssso/.
       \/      `-/oooo++/-      .:/++:/++/-`      ..           `://++/.


         isort your Python imports for you so you don't have to

                            VERSION {0}

\########################################################################/
s   ^#!.*\bpython[23w]?\bc                 C   s   t j| \}}|dv rdS |dv rdS | drdS zt| d}|d}W d    n1 s1w   Y  W n
 tyA   Y dS w tt	|S )N)z.pyz.pyiT)z.pexF~rbd   )
ospathsplitextendswithopenreadlineIOErrorbool
shebang_rematch)r   _rootextfpline r   I/var/www/secure340b-portal/env/lib/python3.10/site-packages/isort/main.pyis_python_file<   s    
r    c                   @   s   e Zd Zdd ZdS )SortAttemptc                 C   s   || _ || _d S N)incorrectly_sortedskipped)selfr#   r$   r   r   r   __init__Q   s   
zSortAttempt.__init__N)__name__
__module____qualname__r&   r   r   r   r   r!   P   s    r!   c              
   K   sX   zt | fi |}t|j|jW S  ty+ } ztd| | W Y d }~d S d }~ww )N,WARNING: Unable to parse file {0} due to {1})r   r!   r#   r$   r   printformat)	file_name	argumentsresulter   r   r   sort_importsV   s   r1   c                 c   s    d|v rt t|d |d |d< | D ]W}tj|rjtj|dddD ]B\}}}t |D ]}t|||rA|| |	| q/|D ]#}tj
||}	t|	rgtj|	|}
t|
||rd|| qD|	V  qDq&q|V  qdS )z6Iterate over all Python source files defined in paths.not_skipskipT)topdownfollowlinksN)listset
differencer   r   isdirwalkr   appendremovejoinr    relpath)pathsconfigr$   r   dirpathdirnames	filenamesdirnamefilenamefilepathZrelative_filer   r   r   iter_source_code_   s.   

rG   c                   @   s8   e Zd ZdZdZg Zdd Zdd Zdd Zd	d
 Z	dS )ISortCommandzoThe :class:`ISortCommand` class is used by setuptools to perform
    imports checks on registered modules.
    z-Run isort on modules registered in setuptoolsc                 C   s*   t  }| D ]
\}}t| || qd S r"   )r
   copyitemssetattr)r%   Zdefault_settingskeyvaluer   r   r   initialize_options   s   zISortCommand.initialize_optionsc                 C   s2   i | _ tt }| D ]	\}}|| j |< qdS )zGet options from config files.N)r.   r   r   getcwdrJ   )r%   Zcomputed_settingsrL   rM   r   r   r   finalize_options   s
   zISortCommand.finalize_optionsc                 c   s    | j jr4| j jp
i }| j jD ]$}|}||v r|| }nd|v r*|d tjj | }|dtjjV  q| j jrD| j jD ]}d| V  q<dV  dS )zFind distribution packages. .z%s.pyzsetup.pyN)distributionpackagespackage_dirr   r   sepreplace
py_modules)r%   Zpackage_dirspackageZpkg_dirrE   r   r   r   distribution_files   s   

zISortCommand.distribution_filesc                 C   s   | j }d}d|d< |  D ]8}ttj|dD ]+}zt|fi |j}|r)d}W q t	yD } zt
d|| W Y d }~qd }~ww q|rOtd d S d S )NFTcheckz*.pyr*      )r.   rZ   globiglobr   r   r=   r   r#   r   r+   r,   sysexit)r%   r.   wrong_sorted_filesr   Zpython_filer#   r0   r   r   r   run   s$   zISortCommand.runN)
r'   r(   r)   __doc__descriptionuser_optionsrN   rP   rZ   rb   r   r   r   r   rH   w   s    rH   c              	   C   s  t jdd}| }|jdddddd |jd	d
dddd |jdddddd |jdddddd |jdddddd |jdddddd |jdd d!dd"d |jd#d$d%d&dd' |jd(d)d*dd+d |jd,d-d.d/dd' |jd0d1d2dd3d |jd4d5d6dd7d |jd8d9d:dd;d |jd<d=dd>d?d |jd@dAdd>dBd |jdCdDdEdFdG |jdHdIdJdKtdLdMdN |jdOdPddQdRd |jdSdTdUdVtdW |jdXdYdZd[tdW |jd\d]d^dd_d |jd`dadbdctdW |jdddedftdg |jdhdidjtdg |jdkdldmdndG |jdodpdqdrdd' |jdsdtduttttdvdw |jdxdydzdd{d |jd|d}d~ddd' |jdddddd' |jdddddd |jdddddd |jdddddd |jdddddd |jdddd |jdddddd |jdddddd |jdddddd |jdddddd' |jddddtt	 dG |jdddddd' |jdddddd |jdddddG |jdddddd' |jdddddd |jdddddd |jdddddƍ |jdddddd |jddddG |jddddG |jdddt
ddՍ |jddddctdW |jdddddG |jdddddd |jdddddd |jddddd |jddddd |jdddd dd t||  D }d2|v r^d|d< |ddrid|d< |S )NzSort Python import definitions alphabetically within logical sections. Run with no arguments to run interactively. Run with `-` as the first argument to read from stdin. Otherwise provide a list of files to sort.)rd   z-az--add-importZadd_importsr;   zYAdds the specified import line to all files, automatically determining correct placement.)destactionhelpz-acz--atomicZatomic
store_truezMEnsures the output doesn't save if the resulting file contains syntax errors.z-afz--force-addsZ
force_addsz6Forces import adds even if the original file is empty.z-bz	--builtinZknown_standard_libraryzOForce sortImports to recognize a module as part of the python standard library.z-cz--check-onlyr[   zrChecks the file for unsorted / unformatted imports and prints them to the command line without modifying the file.)rg   rf   rh   z-caz--combine-asZcombine_as_importsz%Combines as imports on the same line.z-csz--combine-starZcombine_starzWEnsures that if a star import is present, nothing else is imported from that namespace.z-dz--stdoutz6Force resulting output to stdout, instead of in-place.write_to_stdout)rh   rf   rg   z-dfz--diffZ	show_diffz\Prints a diff of all the changes isort would make to a file, instead of changing it in placez-dsz--no-sectionsz,Put all imports into the same section bucketZno_sectionsz-dtz--dont-order-by-typeZdont_order_by_typez?Only order imports alphabetically, do not attempt type orderingz-ez
--balancedZbalanced_wrappingzEBalances wrapping to produce the most consistent line length possiblez-fz--futureZknown_future_libraryzVForce sortImports to recognize a module as part of the future compatibility libraries.z-fasz--force-alphabetical-sortZforce_alphabetical_sortz2Force all imports to be sorted as a single sectionz-fassz)--force-alphabetical-sort-within-sectionsz>Force all imports to be sorted alphabetically within a sectionz-ffz--from-firstZ
from_firstzXSwitches the typical ordering preference, showing from imports first then straight ones.)rf   rh   z-fgwz--force-grid-wrap?   Zforce_grid_wrapzYForce number of from imports (defaults to 2) to be grid wrapped regardless of line length)nargsconsttyperf   rh   z-fssz--force-sort-within-sectionsZforce_sort_within_sectionsz@Force imports to be sorted by module, independent of import_typez-iz--indentz:String to place for indents defaults to "    " (4 spaces).indent)rh   rf   ro   z-jz--jobsz'Number of files to process in parallel.jobsz-kz--keep-direct-and-asZkeep_direct_and_as_importszMTurns off default behavior that removes direct imports when as imports exist.z-lz--lineszO[Deprecated] The max length of an import line (used for wrapping long imports).line_lengthz-laiz--lines-after-importsZlines_after_imports)rf   ro   z-lbtz--lines-between-typesZlines_between_typesz-lez--line-endingZline_endingzXForces line endings to the specified value. If not set, values will be guessed per-file.z-lsz--length-sortz$Sort imports by their string length.Zlength_sortz-mz--multi-lineZmulti_line_outputzMulti line output (0-grid, 1-vertical, 2-hanging, 3-vert-hanging, 4-vert-grid, 5-vert-grid-grouped, 6-vert-grid-grouped-no-comma).)rf   ro   choicesrh   z-nisz--no-inline-sortZno_inline_sortzULeaves `from` imports with multiple imports 'as-is' (e.g. `from foo import a, c ,b`).z-nlbz--no-lines-beforez?Sections which should not be split with previous by empty linesZno_lines_beforez-nsz--dont-skipz/Files that sort imports should never skip over.r2   z-oz--thirdpartyZknown_third_partyzOForce sortImports to recognize a module as being part of a third party library.z-otz--order-by-typeZorder_by_typez3Order imports by type in addition to alphabeticallyz-pz	--projectZknown_first_partyzTForce sortImports to recognize a module as being part of the current python project.z-qz--quietquietz4Shows extra quiet output, only errors are outputted.z-rambiguous_r_flag)rf   rg   z-rmz--remove-importZremove_importsz,Removes the specified import from all files.z-rrz--reverse-relativeZreverse_relativez"Reverse order of relative imports.z-rcz--recursive	recursivez:Recursively look for Python files of which to sort importsz-sz--skipzFiles that sort imports should skip over. If you want to skip multiple files you should specify twice: --skip file1 --skip file2.r3   z-sdz--section-defaultdefault_sectionzFSets the default section for imports (by default FIRSTPARTY) options: z-sgz--skip-globz)Files that sort imports should skip over.Z	skip_globz-slz--force-single-line-importsZforce_single_linez3Forces all from imports to appear on their own linez-spz--settings-pathsettings_pathzTExplicitly set the settings path instead of auto determining based on file location.z-tz--topz?Force specific imports to the top of their appropriate section.Zforce_to_topz-tcz--trailing-commaZinclude_trailing_commazIIncludes a trailing comma on multi line imports that include parentheses.z-upz--use-parenthesesZuse_parentheseszIUse parenthesis for line continuation on length limit instead of slashes.z-vz	--versionshow_version)rg   rf   z-vbz	--verboseverbosezSShows verbose output, such as when files are skipped or when a check is successful.z--virtual-envvirtual_envzKVirtual environment to use for determining whether a package is third-partyz--conda-envZ	conda_envzIConda environment to use for determining whether a package is third-partyz-vnz--version-numberversionz8Returns just the current version number without the logo)rg   r|   rh   z-wz--line-widthzBThe max length of an import line (used for wrapping long imports).z-wlz--wrap-lengthZwrap_lengthzTSpecifies how long lines that are wrapped should be, if not set line_length is used.z-wsz--ignore-whitespaceignore_whitespacezMTells isort to ignore whitespace differences when --check-only is being used.z-yz--applyapplyz7Tells isort to apply changes recursively without askingz--unsafeunsafezjTells isort to look for files in standard library directories, etc. where it may not be safe to operate inz--case-sensitivecase_sensitivez7Tells isort to include casing when sorting module namesfiles*z?One or more Python source files that need their imports sorted.)rm   rh   c                 S   s   i | ]	\}}|r||qS r   r   ).0rL   rM   r   r   r   
<dictcomp>-  s    zparse_args.<locals>.<dictcomp>FZsafety_excludes)argparseArgumentParseradd_mutually_exclusive_groupadd_argumentintstrrangelenr	   r   r   vars
parse_argsrJ   pop)argvparserZinline_args_groupr.   r   r   r   r      s\  




















r   c                    s  t |   drtt d S  drtd td d d< d v rR d }tj|r5tj	|n	tj
tj	| d< tj d sRtd d  d	 v rs d	 }tj	| d	< tj d	 sstd
 d	   dg }|dgkrztjj}W n ty   tj}Y nw td|dd  d S |sdg}d d<  ddsd d< t ddptj	|d pt  }|  d}g } ddrt|||}d}|d s|ddrtt  d}	|	r
dd l}
|
|	}|tjtfi  |}n	 fdd|D }|D ]}|sq|j} ddr+|r+d}|jr3|d7 }q|r=td |t|7 }|rh ddsj|d r_|D ]
}td| qTtd| d S d S d S )Nry   ru   zxERROR: Deprecated -r flag set. This flag has been replaced with -rm to remove ambiguity between it and -rc for recursiver\   FZ
check_skiprx   z.WARNING: settings_path dir does not exist: {0}r{   z,WARNING: virtual_env dir does not exist: {0}r   -T)file_rj   rR   rv   r~   Zask_to_applyrQ   r   rz   Z	show_logorq   c                 3   s     | ]}t |fi  V  qd S r"   )r1   )r   r-   r.   r   r   	<genexpr>m  s    zmain.<locals>.<genexpr>r[   rt   zbWARNING: {0} was skipped as it's listed in 'skip' setting or matches a glob in 'skip_glob' settingzSkipped {0} filesr   )r   getr+   INTROr_   r`   r   r   r9   abspathrD   r,   r   stdinbufferAttributeErrorr   r   rO   rI   updaterG   multiprocessingZPoolimap	functoolspartialr1   r#   r$   r   )r   spvenvZ
file_namesr   r@   ra   r$   Znum_skippedrq   r   executorZattempt_iteratorZsort_attemptr#   Zwas_skippedr   r   r   main5  s   


0

,




r   __main__r"   )$rc   
__future__r   r   r   r   r   r   r]   r   rer_   
setuptoolsZisortr   r   Zisort.settingsr   r	   r
   r   r   r,   r   compiler   r    objectr!   r1   rG   CommandrH   r   r   r'   r   r   r   r   <module>   s4    
	
7 
O
