B t `Zã@sšdZddlZddlZddlZddlmZddlmZmZm Z m Z e  e ¡Z y ejjZWnek rrdd„ZYnXGdd„deƒZd d d „Zd d „ZdS)a:Implements an importer that looks only in specific path (ignoring sys.path), and uses a per-path cache in addition to sys.modules. This is necessary because test modules in different directories frequently have the same names, which means that the first loaded would mask the rest when using the builtin importer. éN)ÚConfig)Ú find_moduleÚ load_moduleÚ acquire_lockÚ release_lockcCs(tj tj |¡¡tj tj |¡¡kS)N)ÚosÚpathÚnormcaseÚrealpath)ÚsrcÚdst©r ú1/tmp/pip-unpacked-wheel-cjhnoqsi/nose/importer.pyÚ _samefilesrc@s:eZdZdZd dd„Zdd„Zdd„Zd d „Zd d „ZdS)ÚImporterz³An importer class that does only path-specific imports. That is, the given module is not searched for on sys.path, but only at the path or in the directory specified. NcCs|dkrtƒ}||_dS)N)rÚconfig)Úselfrr r rÚ__init__szImporter.__init__cCsdtj tj |¡¡ tj¡}| d¡}|ddkr:| ¡|dt|ƒ …}tj |¡}|  ||¡S)zÌImport a dotted-name package whose tail is at path. In other words, given foo.bar and path/to/foo/bar.py, import foo from path/to/foo then bar from path/to/foo/bar, returning bar. Ú.éÿÿÿÿz __init__.pyN) rrÚnormpathÚabspathÚsplitÚsepÚpopÚlenÚjoinÚ importFromDir)rrÚfqnameÚ path_partsZ name_partsZdir_pathr r rÚimportFromPath"s   zImporter.importFromPathc Csttj tj |¡¡}t d||¡|dkr4tj|S|jj rHt ||jƒ|g}|  d¡}d}d}}}x|D]ü} |dkr‚| }n d|| f}zžt ƒt d| ||¡t | |ƒ\}} } tj |¡} | dk rt d|| ¡| | | ¡sþ|jjrt| d dƒr| }ntj|=t||| | ƒ}nt||| | ƒ}Wd|r<| ¡tƒX|rVt|| |ƒt|d ƒrh|j}|}qpW|S) zˆImport a module *only* from path, ignoring sys.path and reloading if the version in sys.modules is not the one we want. zImport %s from %sÚ__main__rÚNz%s.%szfind module part %s (%s) in %szsys.modules has %s as %sÚ__path__)rrrrÚlogÚdebugÚsysÚmodulesrZaddPathsÚadd_pathrrrÚgetÚ sameModuleZfirstPackageWinsÚgetattrrÚcloserÚsetattrÚhasattrr#) rÚdirrrÚpartsZ part_fqnameÚmodÚparentÚfhÚpartÚfilenameÚdescÚoldr r rr1sL             zImporter.importFromDircCs tj |¡r|Stj |¡SdS)N)rrÚisdirÚdirname)rr5r r rÚ_dirname_if_filejs zImporter._dirname_if_filecCsŠg}t|dƒr0xB|jD]}| | |¡¡qWn"t|dƒrN| | |j¡¡ndS| |¡}x(|D] }t d||¡t||ƒrbdSqbWdS)Nr#Ú__file__Fz&module already loaded? mod: %s new: %sT)r.r#Úappendr:r;r$r%r)rr1r5Z mod_pathsrÚnew_pathZmod_pathr r rr*ss      zImporter.sameModule)N) Ú__name__Ú __module__Ú __qualname__Ú__doc__rr rr:r*r r r rrs  9 rcCsÐt d|¡|sgSg}tj |¡}|rRtj tj |d¡¡rR| t||ƒ¡n.|t jkr€t d|¡t j  d|¡|  |¡|rÌ|j rÌx@|j D]6}tj ||¡}tj  |¡r’t j  d|¡|  |¡q’W|S)zlEnsure that the path, or the root of the current package (if path is in a package), is in sys.path. z Add path %sz __init__.pyzinsert %s into sys.pathr)r$r%rrr9ÚexistsrÚextendr(r&Úinsertr<ZsrcDirsr8)rrÚaddedr2r9Údirpathr r rr(ˆs&       r(cCs(t d|¡|tjkr$tj |¡dS)NzRemove path %s)r$r%r&rÚremove)rr r rÚ remove_path¤s rH)N)rAÚloggingrr&Z nose.configrÚimprrrrÚ getLoggerr>r$rÚsamefilerÚAttributeErrorÚobjectrr(rHr r r rÚs   p