B
    A!p\Œ  ã               @   sf  d Z ddlZddlm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 ddlZddl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mZ ddlmZmZ dd„ Z dd„ Z!dd„ Z"dd„ Z#dd„ Z$d:dd„Z%dd„ Z&dd„ Z'dddd d!gifd"d#d$d%d&d'd(d)d*ifd+d,d-d.d/d0d1d2d3œZ(d4Z)d5Z*G d6d7„ d7eƒZ+d8d9„ Z,dS );z imports checkers for Python codeé    N)Ú	sysconfig)Úare_exclusiveÚ
decorators)Úget_module_partÚis_standard_module)ÚIAstroidChecker)Úget_global_option)ÚEmptyReportError)ÚBaseChecker)Úcheck_messagesÚnode_ignores_exceptionÚis_from_fallback_block)Ú
get_cyclesÚ
DotBackend)ÚVerbatimTextÚ	Paragraphc                s$   |   d¡‰ ‡ fdd„ttˆ ƒƒD ƒS )z×Split the names of the given module into subparts

    For example,
        _qualified_names('pylint.checkers.ImportsChecker')
    returns
        ['pylint', 'pylint.checkers', 'pylint.checkers.ImportsChecker']
    Ú.c                s"   g | ]}d   ˆ d|d … ¡‘qS )r   r   é   )Újoin)Ú.0Úi)Únames© ú6lib/python3.7/site-packages/pylint/checkers/imports.pyú
<listcomp>A   s    z$_qualified_names.<locals>.<listcomp>)ÚsplitÚrangeÚlen)Úmodnamer   )r   r   Ú_qualified_names8   s    
r   c             C   s:   t | tjƒr6| jr6|  ¡ }t |tjƒr6|j|| jd}|S )a   Get a prepared module name from the given import node

    In the case of relative imports, this will return the
    absolute qualified module name, which might be useful
    for debugging. Otherwise, the initial module name
    is returned unchanged.
    )Úlevel)Ú
isinstanceÚastroidÚ
ImportFromr    ÚrootÚModuleZrelative_to_absolute_name)Ú
importnoder   r$   r   r   r   Ú_get_import_nameD   s    r'   c       
         sü   |rd||f n|‰ d}d}xÈ|j D ]¾}|| kr2q$| ¡ |  ¡ krP|j| jkrPq$t|tjƒr|t‡ fdd„|jD ƒƒrâd}P q$t|tjƒr$||j	kr$xH|jD ]>\}}	ˆ d|j
|f krºd}P |dkrš||krš|sš|	sšd}P qšW |r$P q$W |røt|| ƒsø|S dS )zIreturn the node where [base.]<name> is imported or None if not found
    z%s.%sNFc             3   s   | ]}ˆ |d  kV  qdS )r   Nr   )r   Ziname)Úfullnamer   r   ú	<genexpr>c   s    z$_get_first_import.<locals>.<genexpr>TÚ*)ZbodyÚscopeÚ
fromlinenor!   r"   ÚImportÚanyr   r#   r    r   r   )
ÚnodeÚcontextÚnameÚbaser    ÚaliasÚfirstÚfoundÚimported_nameZimported_aliasr   )r(   r   Ú_get_first_importV   s8    
r7   c             C   s(   xt |ƒD ]}||kr
dS q
W t| tƒS )NT)r   r   ÚImportError)r/   r   Zignored_modulesZ	submoduler   r   r   Ú_ignore_import_failurez   s    r9   c             C   sZ   i }xP| D ]H\}}|df}x&|  d¡D ]}|d  |i g g¡}q&W |d  |7  < q
W |S )z‡get a list of 2-uple (module, list_of_files_which_import_this_module),
    it will return a dictionary to represent this as a tree
    r   r   r   r   )r   Ú
setdefault)Zmod_files_listZ	tree_defsÚmodÚfilesr/   Úprefixr   r   r   Ú_make_tree_defs…   s    r>   c       	      C   sÆ   g }|   ¡ }x®tt|dd„ dƒD ]–\}\}\}}|s<d}ndd t|ƒ¡ }|dkrn| d||f ¡ d	}n6| d
|||f ¡ |t|ƒd krœd| }nd| }|r"| t||ƒ¡ q"W d |¡S )z2return a string which represents imports as a treec             S   s   | d S )Nr   r   )Úxr   r   r   Ú<lambda>–   s    z!_repr_tree_defs.<locals>.<lambda>)ÚkeyÚ z(%s)ú,Nz%s %sz  z	%s\-%s %sr   z%s  z%s| Ú
)ÚitemsÚ	enumerateÚsortedr   Úappendr   Ú_repr_tree_defs)	ÚdataZ
indent_strÚlinesZnodesr   r;   Úsubr<   Zsub_indent_strr   r   r   rI   ’   s     &
rI   c             C   s¸   i }t | dd… dd}| d¡ xRt| ¡ ƒD ]B\}}d||< | |¡ x&|D ]}||krPd||< | |¡ qPW q0W x2t| ¡ ƒD ]"\}}x|D ]}| ||¡ q’W q„W | | ¡ dS )z0write dependencies as a dot (graphviz) file
    NéüÿÿÿZLR)ZrankdirzURL="." node[shape="box"]r   )r   ÚemitrG   rE   Z	emit_nodeZ	emit_edgeZgenerate)ÚfilenameÚdep_infoZdoneZprinterr   ÚdependenciesZ
depmodnamer   r   r   Ú_dependencies_graph©   s    



rR   c             C   s$   t | |ƒ | td|| f ƒ¡ dS )z`generate a dependencies graph and add some information about it in the
    report's section
    z&%simports graph has been written to %sN)rR   rH   r   )rO   rP   ÚsectZgtyper   r   r   Ú_make_graph¼   s    
rT   zUnable to import %szimport-errorz4Used when pylint has been unable to import a module.Z	old_names)ZF0401zimport-error)z2Attempted relative import beyond top-level packagezrelative-beyond-top-levelzSUsed when a relative import tries to access too many levels in the current package.)zCyclic import (%s)zcyclic-importzBUsed when a cyclic import between two or more modules is detected.)zWildcard import %szwildcard-importz-Used when `from module import *` is detected.)zUses of a deprecated module %rzdeprecated-modulez/Used a module marked as deprecated is imported.z Relative import %r, should be %rzrelative-importzBUsed when an import relative to the package directory is detected.Z
maxversion)é   r   )zReimport %r (imported line %s)Ú
reimportedz0Used when a module is reimported multiple times.)zModule import itselfzimport-selfz'Used when a module is importing itself.)z:__future__ import is not the first non docstring statementzmisplaced-futurezgPython 2.5 and greater require __future__ import to be the first non docstring statement in the module.)z!Multiple imports on one line (%s)zmultiple-importszBUsed when import statement importing multiple modules is detected.)z%s should be placed before %szwrong-import-orderzuUsed when PEP8 import order is not respected (standard imports first, then third-party libraries, then local imports))z'Imports from package %s are not groupedzungrouped-importsz-Used when imports are not grouped by packages)z5Import "%s" should be placed at the top of the modulezwrong-import-positionz$Used when code and imports are mixed)z-Import alias does not rename original packagezuseless-import-aliaszsUsed when an import alias is same as original package.e.g using import numpy as numpy instead of import numpy as np)ZE0401ZE0402ZR0401ZW0401ZW0402ZW0403ZW0404ZW0406ZW0410ZC0410ZC0411ZC0412ZC0413ZC0414r   )Zenchantc               @   sü  e Zd ZdZeZdZeZdZ	e
jdk r,dZndZdedd	d
dœfddddddœfddddddœfddddddœfdedd	ddœfdedd	ddœfddddddœfddddddœffZd[d!d"„Zed#d$„ ƒZd%d&„ Zd'd(„ Zd)d*„ ZeeŽ d+d,„ ƒZeeŽ d-d.„ ƒZeeŽ d/d0„ ƒZd1d2„ Ze Z Z Z Z Z Z  Z!Z"d3d4„ Z#e# Z$ Z%Z&d5d6„ Z'd7d8„ Z(d9d:„ Z)d;d<„ Z*ed=d>„ ƒZ+d?d@„ Z,dAdB„ Z-dCdD„ Z.dEdF„ Z/dGdH„ Z0dIdJ„ Z1d\dKdL„Z2dMdN„ Z3dOdP„ Z4dQdR„ Z5e6j7dSdT„ ƒZ8e6j7dUdV„ ƒZ9dWdX„ Z:dYdZ„ Z;d S )]ÚImportsCheckerz‹checks for
    * external modules dependencies
    * relative / wildcard imports
    * cyclic imports
    * uses of deprecated modules
    Úimportséþÿÿÿ)rU   é   )Úoptparse)r[   ztkinter.tixzdeprecated-modulesZcsvz	<modules>zBDeprecated modules which should not be used, separated by a comma.)ÚdefaultÚtypeÚmetavarÚhelpzimport-graphrB   Ústringz
<file.dot>zyCreate a graph of every (i.e. internal and external) dependencies in the given file (report RP0402 must not be disabled).zext-import-graphz_Create a graph of external dependencies in the given file (report RP0402 must not be disabled).zint-import-graphz_Create a graph of internal dependencies in the given file (report RP0402 must not be disabled).zknown-standard-libraryzYForce import order to recognize a module as part of the standard compatibility libraries.zknown-third-partyzJForce import order to recognize a module as part of a third party library.zanalyse-fallback-blocksFZynz<y_or_n>zåAnalyse import fallback blocks. This can be used to support both Python 2 and 3 compatible code, which means that the block might have code that exists only in one or another interpreter, leading to false positives when analysed.zallow-wildcard-with-allz8Allow wildcard imports from modules that define __all__.Nc             C   sR   t  | |¡ d | _d | _g | _d | _i | _dd| jfdd| jff| _	|  
¡ | _d S )NZRP0401zExternal dependenciesZRP0402zModules dependencies graph)r
   Ú__init__ÚstatsÚimport_graphÚ_imports_stackÚ_first_non_import_nodeÚ_module_pkgÚ_report_external_dependenciesÚ_report_dependencies_graphZreportsÚ_compute_site_packagesZ_site_packages)ÚselfÚlinterr   r   r   ra   ‚  s    
zImportsChecker.__init__c           	   C   s¢   dd„ } t ƒ }ttdd ƒ}x6td |tjfƒD ]"}tj|d}| |ƒ}| |¡ q,W tj	 
d¡ržx>td |tjfƒD ]*}tj	 |dddt ¡  d	¡}| |¡ qpW |S )
Nc             S   s   t j t j | ¡¡S )N)ÚosÚpathÚnormcaseÚabspath)rm   r   r   r   Ú_normalized_path’  s    z?ImportsChecker._compute_site_packages.<locals>._normalized_pathÚreal_prefix)r=   z/etc/debian_versionZlocalÚlibZpythonzdist-packages)ÚsetÚgetattrÚsysÚfilterr=   r   Zget_python_libÚaddrl   rm   Úisfiler   Zget_python_version)rp   Úpathsrq   r=   rm   Z	libpythonr   r   r   ri     s"    
z%ImportsChecker._compute_site_packagesc             C   sX   | j ji d | j jg d | j j| _t t¡| _i | _t t¡| _t	| dg d| _
dS )z3called before visiting project (i.e set of modules))rQ   )Zcycleszignored-modules)r\   N)rk   Z	add_statsrb   ÚcollectionsÚdefaultdictrs   rc   rf   Ú_excluded_edgesr   Ú_ignored_modules)rj   r   r   r   Úopen©  s    
zImportsChecker.openc             C   s2   t  | j¡}x |D ]}||  | j| ¡ qW |S )N)ÚcopyÚdeepcopyrc   Údifference_updater|   )rj   Zfiltered_graphr/   r   r   r   Ú#_import_graph_without_ignored_edges³  s    
z2ImportsChecker._import_graph_without_ignored_edgesc             C   sJ   | j  d¡rF|  ¡ }t|ƒ}x(t||dD ]}| jdd |¡d q*W dS )z3called before visiting project (i.e set of modules)zcyclic-import)Úverticesz -> )ÚargsN)rk   Úis_message_enabledr‚   Úlistr   Úadd_messager   )rj   Úgraphrƒ   Úcycler   r   r   Úclose¹  s
    zImportsChecker.closec             C   sÔ   |   |¡ |  |¡ | ¡ }dd„ |jD ƒ}t|ƒdkrN| jdd |¡|d x€|D ]x}|  ||¡ |  ||¡}t	|j
tjƒrˆ|  |¡ t	| ¡ tjƒr¤|  ||¡ |dkr®qT|  ||||¡ |  ||j¡ qTW dS )z*triggered when an import statement is seenc             S   s   g | ]\}}|‘qS r   r   )r   r1   Ú_r   r   r   r   È  s    z/ImportsChecker.visit_import.<locals>.<listcomp>é   zmultiple-importsz, )r„   r/   N)Ú_check_reimportÚ_check_import_as_renamer$   r   r   r‡   r   Ú_check_deprecated_moduleÚ_get_imported_moduler!   Úparentr"   r%   Ú_check_positionr+   Ú_record_importÚ_check_relative_importÚ_add_imported_moduler1   )rj   r/   Úmodnoder   r1   Úimported_moduler   r   r   Úvisit_importÁ  s"    



zImportsChecker.visit_importc             C   sø   |j }|  ||¡}|  |¡ |  |¡ |  ||¡ |  ||¡ |  |¡ | j|||jd t	|j
tjƒrr|  |¡ t	| ¡ tjƒrŽ|  ||¡ |dkršdS | ¡ }|  ||||¡ x@|jD ]6\}}|dkrâ|  |d|j|f ¡ qº|  ||j¡ qºW dS )z'triggered when a from statement is seen)Úbasenamer    Nr*   z%s.%s)r   r   rŽ   Ú_check_misplaced_futurer   Ú_check_wildcard_importsÚ_check_same_line_importsr   r    r!   r‘   r"   r%   r’   r+   r“   r$   r”   r   r•   r1   )rj   r/   r™   r—   r–   r1   r‹   r   r   r   Úvisit_importfromÛ  s(    



zImportsChecker.visit_importfromc             C   s˜   |   |¡\}}}tƒ }d }xl|| | D ]\\}}| j d|j¡sBq(| d¡\}	}
}
|rv||	krv|	|krv| jd||	d |	}| |	¡ q(W g | _d | _	d S )Nzungrouped-importsr   )r/   r„   )
Ú_check_imports_orderrs   rk   r…   r,   Ú	partitionr‡   rw   rd   re   )rj   r/   Ústd_importsZext_importsZloc_importsZmetZcurrent_packageÚimport_nodeZimport_nameÚpackager‹   r   r   r   Úleave_moduleø  s    
zImportsChecker.leave_modulec                sž   | j  dˆ j¡sd S | jrd S tˆ jtjƒs0d S tjtj	g}‡ fdd„|D ƒ}|rlt
ˆ  tjtjf¡ƒrld S tˆ tjƒr”dd„ ˆ jD ƒ}t|ƒr”d S ˆ | _d S )Nzwrong-import-positionc                s   g | ]}t ˆ |ƒr|‘qS r   )r!   )r   Zallowed)r/   r   r   r     s    z@ImportsChecker.compute_first_non_import_node.<locals>.<listcomp>c             S   s0   g | ](}t |tjƒo*|j d ¡o*|j d ¡‘qS )Ú__)r!   r"   Z
AssignNamer1   Ú
startswithÚendswith)r   Útargetr   r   r   r   %  s   )rk   r…   r,   re   r!   r‘   r"   r%   Ú	TryExceptÚ
TryFinallyr.   Únodes_of_classr-   r#   ZAssignZtargetsÚall)rj   r/   Znested_allowedZis_nested_allowedZvalid_targetsr   )r/   r   Úcompute_first_non_import_node  s"    
z,ImportsChecker.compute_first_non_import_nodec             C   sŒ   | j  d|j¡sd S | jrd S t|j ¡ tjƒs4d S |}xt|jtjƒsP|j}q:W t|tj	tj
tjfƒr‚t| tjtjf¡ƒr‚d S || _d S )Nzwrong-import-position)rk   r…   r,   re   r!   r‘   r+   r"   r%   ZIfr©   r¨   r.   rª   r-   r#   )rj   r/   r$   r   r   r   Úvisit_functiondef8  s    
z ImportsChecker.visit_functiondefc             C   sF   |j }|dkrB| ¡ }|r>t|tjƒr0|j dks>| jd|d d S d S )NZ
__future__zmisplaced-future)r/   )r   Zprevious_siblingr!   r"   r#   r‡   )rj   r/   r™   Úprevr   r   r   rš   P  s    
z&ImportsChecker._check_misplaced_futurec             C   sR   dd„ |j D ƒ}t |¡}x2| ¡ D ]&\}}|dkr$| jd|||jfd q$W d S )Nc             s   s   | ]\}}|V  qd S )Nr   )r   r1   r‹   r   r   r   r)   `  s    z:ImportsChecker._check_same_line_imports.<locals>.<genexpr>r   rV   )r/   r„   )r   rz   ÚCounterrE   r‡   r,   )rj   r/   r   Zcounterr1   Úcountr   r   r   rœ   ^  s
    
z'ImportsChecker._check_same_line_importsc             C   s   | j r| jd|| ¡ d dS )z‡Check `node` import or importfrom node position is correct

        Send a message  if `node` comes before another instruction
        zwrong-import-position)r/   r„   N)re   r‡   Ú	as_string)rj   r/   r   r   r   r’   f  s    zImportsChecker._check_positionc             C   st   t |tjƒr|j}n|r|jnd}|s>|jd d  d¡d }t |tjƒr`|jpRddkr`d| }| j 	||f¡ dS )z&Record the package `node` imports fromNr   r   r   )
r!   r"   r#   r   r1   r   r   r    rd   rH   )rj   r/   ÚimportedmodnodeZimportednamer   r   r   r“   p  s    zImportsChecker._record_importc                s$   dd„ |D ƒ}t ‡ fdd„|D ƒƒS )Nc             S   s   g | ]\}}|‘qS r   r   )r   r¡   r‹   r   r   r   r   ‡  s    z6ImportsChecker._is_fallback_import.<locals>.<listcomp>c             3   s   | ]}t  |ˆ ¡V  qd S )N)r"   r   )r   r¡   )r/   r   r   r)   ˆ  s    z5ImportsChecker._is_fallback_import.<locals>.<genexpr>)r.   )r/   rX   r   )r/   r   Ú_is_fallback_import…  s    z"ImportsChecker._is_fallback_importc             C   s8  g }g }g }g }g }g }g }g }	t jd| jj| jjd}
xò| jD ]æ\}}| d¡rjd| d¡d  }n| d¡d }t|j	t
jƒ }| j d|j¡ }|
 |¡}||f}|dkr| |¡ |pÊ|pÊ|	}|  ||¡rÚqB|r*|s*| jd|d| ¡  d	|d d  ¡  fd
 qB|dkrŒ| |¡ | |¡ |sH|sH| |¡ |pP|	}|r*|s*| jd|d| ¡  d	|d d  ¡  fd
 qB|dkrþ| |¡ | |¡ |sÀ|sÀ| |¡ |	}|r*|s*| jd|d| ¡  d	|d d  ¡  fd
 qB|dkrB| ||f¡ |sB|sB|	 ||f¡ qBW |||fS )z„Checks imports of module `node` are grouped by category

        Imports must follow this order: standard, 3rd party, local
        rB   )Zfile_contentsÚknown_third_partyÚknown_standard_libraryr   r   r   zwrong-import-order)ZFUTUREZSTDLIBzstandard import "%s"z"%s")r/   r„   Z
THIRDPARTYzthird party import "%s"Z
FIRSTPARTYzfirst party import "%s"ZLOCALFOLDER)ÚisortZSortImportsÚconfigr´   rµ   rd   r¥   r   r!   r‘   r"   r%   rk   r…   r,   Zplace_modulerH   r³   r‡   r±   )rj   Z_module_noder    Zthird_party_importsZfirst_party_importsZexternal_importsZlocal_importsZthird_party_not_ignoredZfirst_party_not_ignoredZlocal_not_ignoredZ	isort_objr/   r   r¢   ÚnestedZignore_for_import_orderZimport_categoryZnode_and_package_importZwrong_importr   r   r   rž   Š  s~    















z#ImportsChecker._check_imports_orderc          
   C   sô   y
|  |¡S  tjk
r@   t||| jƒr.d S | jd|d Y n° tjk
r† } z(d |t|j	ƒ¡}| jd|j
|d W d d }~X Y nj tjk
rî   | j d¡s¦d S t||| jƒr¸d S | jjsÌt|ƒrÌd S t||ƒ}| jdt|ƒ|d Y nX d S )Nzrelative-beyond-top-level)r/   z+Cannot import {!r} due to syntax error {!r}zsyntax-error)Úliner„   zimport-error)r„   r/   )Zdo_import_moduler"   ZTooManyLevelsErrorr9   r}   r‡   ZAstroidSyntaxErrorÚformatÚstrÚerrorÚlinenoZAstroidBuildingExceptionrk   r…   r·   Zanalyse_fallback_blocksr   r'   Úrepr)rj   r&   r   ÚexcÚmessageZdotted_modnamer   r   r   r   Þ  s(    
"

z#ImportsChecker._get_imported_modulec             C   sj   | j  d¡sdS |jdkrdS ||kr*dS | ¡ s>t|ddƒrBdS |j|krf| jd||jf|d dS dS )zpcheck relative import. node is either an Import or From node, modname
        the imported module name.
        zrelative-importNFr    )r„   r/   )rk   r…   ÚfileZabsolute_import_activatedrt   r1   r‡   )rj   r–   r&   r²   Zimportedasnamer   r   r   r”   ù  s    

z%ImportsChecker._check_relative_importc             C   sô   |  ¡ j}|  ¡ j}tj tj |¡¡d }yt||ƒ}W n tk
rN   Y nX ||krh| j	d|d nˆt
|ƒsð|dkr˜|| jkr˜| dd¡d | j|< | jd  |tƒ ¡}||kr¾| |¡ | j|  |¡ | jjd|jd	sð| j|  |¡ d
S )z7notify an imported module, used to analyze dependenciesr   zimport-self)r/   ra   r   r   rQ   zcyclic-import)r¹   N)r$   rÁ   r1   rl   rm   Úsplitextr™   r   r8   r‡   r   rf   Úrsplitrb   r:   rs   rw   rc   rk   r…   r½   r|   )rj   r/   ZimportedmodnameZmodule_fileZcontext_namer2   Zimportedmodnamesr   r   r   r•     s&    




z#ImportsChecker._add_imported_modulec             C   s<   x6| j jD ]*}||ks$| |d ¡r
| jd||d q
W dS )z!check if the module is deprecatedr   zdeprecated-module)r/   r„   N)r·   Údeprecated_modulesr¥   r‡   )rj   r/   Zmod_pathÚmod_namer   r   r   r   2  s    z'ImportsChecker._check_deprecated_modulec             C   sh   |j }x\|D ]T}t|ƒsd S |d }| d¡}|d }|d }||krt|ƒdkr| jd|d qW d S )Nr   r   éÿÿÿÿr   zuseless-import-alias)r/   )r   r«   rÃ   r   r‡   )rj   r/   r   r1   Z	real_nameZsplitted_packagesr6   r   r   r   rŽ   8  s    

z&ImportsChecker._check_import_as_renamec          	   C   sš   | j  d¡sdS | ¡ }| ¡ }||fg}||k	r@| |df¡ xT|D ]L\}}xB|jD ]8\}	}
t|||	|||
ƒ}|dk	rV| jd||	|jfd qVW qFW dS )z8check if the import is necessary (i.e. not already done)rV   N)r/   r„   )	rk   r…   Úframer$   rH   r   r7   r‡   r,   )rj   r/   r™   r    rÇ   r$   ZcontextsZknown_contextZknown_levelr1   r3   r4   r   r   r   r   I  s    
zImportsChecker._check_reimportc             C   s4   t |  ¡  ¡ ƒ}|stƒ ‚t|ƒ}| t|ƒ¡ dS )z4return a verbatim layout for displaying dependenciesN)r>   Ú_external_dependencies_inforE   r	   rI   rH   r   )rj   rS   r‹   Ú_dummyrP   Ztree_strr   r   r   rg   ^  s
    z,ImportsChecker._report_external_dependenciesc             C   s†   | j d }|r&| jjs,| jjs,| jjs,tƒ ‚| jj}|rFt|||dƒ | jj}|rdt||  ¡ |dƒ | jj}|r‚t||  ¡ |dƒ dS )z+write dependencies as a dot (graphviz) filerQ   rB   z	external z	internal N)	rb   r·   rc   Zext_import_graphZint_import_graphr	   rT   rÈ   Ú_internal_dependencies_info)rj   rS   r‹   rÉ   rP   rO   r   r   r   rh   f  s    
z)ImportsChecker._report_dependencies_graphc             C   sn   t  t¡}x^| jd  ¡ D ]L\}}xB|D ]:}| j ||¡}| |¡}|rL|sT|s(|s(||  |¡ q(W qW |S )z2build the internal or the external depedency graphrQ   )	rz   r{   rs   rb   rE   rf   Úgetr¥   rw   )rj   Úinternalrˆ   ZimporteeÚ	importersÚimporterr¢   Z	is_insider   r   r   Ú_filter_dependencies_graphy  s    


z)ImportsChecker._filter_dependencies_graphc             C   s   | j ddS )zXreturn cached external dependencies information or build and
        cache them
        F)rÌ   )rÏ   )rj   r   r   r   rÈ   „  s    z*ImportsChecker._external_dependencies_infoc             C   s   | j ddS )zXreturn cached internal dependencies information or build and
        cache them
        T)rÌ   )rÏ   )rj   r   r   r   rÊ   ‹  s    z*ImportsChecker._internal_dependencies_infoc             C   sN   |  ¡ jrd S |  |¡}x0|jD ]&\}}|dkr |s | jd|j|d q W d S )Nr*   zwildcard-import)r„   r/   )r$   r¢   Ú_wildcard_import_is_allowedr   r‡   r   )rj   r/   r—   Zwildcard_import_is_allowedr1   r‹   r   r   r   r›   ’  s    

z&ImportsChecker._check_wildcard_importsc             C   s   | j jo|d k	od|jkS )NÚ__all__)r·   Zallow_wildcard_with_allÚlocals)rj   r—   r   r   r   rÐ   œ  s    z*ImportsChecker._wildcard_import_is_allowed)N)NN)<Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Z__implements__r1   ÚMSGSZmsgsZpriorityru   Úversion_inforÄ   ÚDEFAULT_STANDARD_LIBRARYÚDEFAULT_KNOWN_THIRD_PARTYZoptionsra   Ústaticmethodri   r~   r‚   rŠ   r   r˜   r   r£   r¬   Zvisit_tryfinallyZvisit_tryexceptZvisit_assignattrZvisit_assignZvisit_ifexpZvisit_comprehensionZ
visit_exprZvisit_ifr­   Zvisit_classdefZ	visit_forZvisit_whilerš   rœ   r’   r“   r³   rž   r   r”   r•   r   rŽ   r   rg   rh   rÏ   r   ÚcachedrÈ   rÊ   r›   rÐ   r   r   r   r   rW     sž   


( 
T!

rW   c             C   s   |   t| ƒ¡ dS )z.required method to auto register this checker N)Zregister_checkerrW   )rk   r   r   r   Úregister¤  s    rÝ   )N)-rÖ   rz   Z	distutilsr   rl   ru   r   r"   r   r   Zastroid.modutilsr   r   r¶   Zpylint.interfacesr   Zpylint.utilsr   Zpylint.exceptionsr	   Zpylint.checkersr
   Zpylint.checkers.utilsr   r   r   Zpylint.graphr   r   Zpylint.reporters.ureports.nodesr   r   r   r'   r7   r9   r>   rI   rR   rT   r×   rÙ   rÚ   rW   rÝ   r   r   r   r   Ú<module>   sj   $

     