a
    a5                  	   @   s  d Z ddl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
mZ ddlmZ ddlmZmZ dd	lmZ d
ZefeeedddZeddefeeeeef dddZeee
eeef  dddZeee
eeef  dddZeee
eeef  dddZd(eee
e	e  eedf e
eeef  dddZeedddZeedd d!Zeee ed"d#d$Zeeed%d&d'ZdS ))zIContains all logic related to placing an import within a certain section.    N)fnmatch)	lru_cache)Path)	FrozenSetIterableOptionalTuple)sections)DEFAULT_CONFIGConfig)exists_case_sensitiveZLOCALFOLDER)nameconfigreturnc                 C   s   t | |d S )z8Returns the section placement for the given module name.r   )module_with_reasonr   r    r   *lib/python3.9/site-packages/isort/place.pymodule   s    r   i  )maxsizec                 C   s2   t | |p0t| |p0t| |p0t| |p0|jdfS )zPReturns the section placement for the given module name alongside the reasoning.z.Default option in Config or universal default.)_forced_separate_local_known_pattern	_src_pathZdefault_sectionr   r   r   r   r      s    
r   c                 C   sR   |j D ]F}|}|ds d| }t| |s8t| d| r|d| df  S qd S )N*z%s*.zMatched forced_separate (z) config value.)forced_separateendswithr   )r   r   r   Z	path_globr   r   r   r       s    

r   c                 C   s   |  drtdfS d S )Nr   zModule name started with a dot.)
startswithLOCALr   r   r   r   r   -   s    
r   c                    sp   |  d  fddtt ddD }|D ]>}|jD ]2\}}||jv r6||r6|d| f    S q6q,d S )Nr   c                 3   s    | ]}d   d| V  qdS )r   N)join).0Zfirst_kpartsr   r   	<genexpr>6       z!_known_pattern.<locals>.<genexpr>r   z!Matched configured known pattern )splitrangelenZknown_patternsr	   match)r   r   Zmodule_names_to_checkZmodule_name_to_checkpatternZ	placementr   r"   r   r   4   s    
r   r   .)r   r   	src_pathsprefixr   c           
      C   s   |d u r|j }| dd^}}||f }d|}|D ]}||  }	|sd|	 sd|j|krd| }	|r||jv s|jrt|	|j	rt
|d ||	f|  S t|	st|	st||r6tjd| df  S q6d S )Nr      r   z*Found in one of the configured src_paths: )r,   r'   r    resolveis_dirr   Znamespace_packagesZ auto_identify_namespace_packages_is_namespace_packageZsupported_extensionsr   
_is_module_is_package_src_path_is_moduler	   Z
FIRSTPARTY)
r   r   r,   r-   Zroot_module_nameZnested_moduleZ
new_prefix	namespacesrc_pathZmodule_pathr   r   r   r   ?   s2    


r   )pathr   c                    s<   t t dp:t fddtjjD p:t t d S )Nz.pyc                 3   s    | ]}t t |V  qd S N)r   strwith_suffix)r!   Z
ext_suffixr7   r   r   r$   e   s   z_is_module.<locals>.<genexpr>__init__.py)r   r9   r:   any	importlib	machineryEXTENSION_SUFFIXESr;   r   r;   r   r2   b   s    r2   c                 C   s   t t| o|  S r8   )r   r9   r0   r;   r   r   r   r3   m   s    r3   )r7   src_extensionsr   c                    s   t | sdS | d }| s< fdd|  D }|rdS nd|dJ}|d}d|vrd|vrd	|vrd
|vrW d    dS W d    n1 s0    Y  dS )NFr<   c                    s.   g | ]&}|j d  v s&|j dv r|qS )r   )z	setup.cfgzpyproject.toml)suffixlstripr   lower)r!   filepathrA   r   r   
<listcomp>w   s   z)_is_namespace_package.<locals>.<listcomp>rbi   s7   __import__('pkg_resources').declare_namespace(__name__)s7   __import__("pkg_resources").declare_namespace(__name__)s@   __path__ = __import__('pkgutil').extend_path(__path__, __name__)s@   __path__ = __import__("pkgutil").extend_path(__path__, __name__)T)r3   existsiterdiropenread)r7   rA   Z	init_file	filenamesZopen_init_fileZ
file_startr   rF   r   r1   q   s2    

.r1   )r6   module_namer   c                 C   s   || j ko|  ott| S r8   )r   r0   r   r9   )r6   rN   r   r   r   r4      s    r4   )Nr   ) __doc__r>   r   	functoolsr   pathlibr   typingr   r   r   r   Zisortr	   Zisort.settingsr
   r   Zisort.utilsr   r   r9   r   r   r   r   r   r   boolr2   r3   r1   r4   r   r   r   r   <module>   s8      

#