ó
ĉNXc           @  sP   d  Z  d d l m Z d d l Z d d l Z d d  Z d   Z d   Z d S(   sI  Utility functions for finding modules

Utility functions for finding modules on sys.path.

`find_mod` finds named module on sys.path.

`get_init` helper function that finds __init__ file in a directory.

`find_module` variant of imp.find_module in std_lib that only returns
path to module and not an open file object as well.



i˙˙˙˙(   t   print_functionNc         C  s   |  d k r d Sy t j |  |  \ } } } Wn t k
 rC d SX| d k rT | S| j   t j j |  d d k r~ | Sd Sd S(   s#  imp.find_module variant that only return path of module.
    
    The `imp.find_module` returns a filehandle that we are not interested in.
    Also we ignore any bytecode files that `imp.find_module` finds.

    Parameters
    ----------
    name : str
        name of module to locate
    path : list of str
        list of paths to search for `name`. If path=None then search sys.path

    Returns
    -------
    filename : str
        Return full path of module or None if module is missing or does not have
        .py or .pyw extension
    i   s   .pys   .pycN(   s   .pys   .pyc(   t   Nonet   impt   find_modulet   ImportErrort   closet   ost   patht   splitext(   t   nameR   t   filet   filenamet   _(    (    sR   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/module_paths.pyR   0   s    
c         C  sP   t  j j |  d  } x4 d d g D]& } | | } t  j j |  r" | Sq" Wd S(   sĉ   Get __init__ file path for module directory
    
    Parameters
    ----------
    dirname : str
        Find the __init__ file in directory `dirname`

    Returns
    -------
    init_path : str
        Path to __init__ file
    t   __init__s   .pys   .pywN(   R   R   t   joint   isfile(   t   dirnamet   fbaset   extt   fname(    (    sR   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/module_paths.pyt   get_initR   s
    
c         C  sq   |  j  d  } t | d  } x$ | d D] } t | | g  } q* W| rm t j j |  rm t |  } n  | S(   sÖ  Find module `module_name` on sys.path
    
    Return the path to module `module_name`. If `module_name` refers to
    a module directory then return path to __init__ file. Return full 
    path of module or None if module is missing or does not have .py or .pyw
    extension. We are not interested in running bytecode.
    
    Parameters
    ----------
    module_name : str
    
    Returns
    -------
    modulepath : str
        Path to module `module_name`.
    t   .i    i   (   t   splitR   R   R   t   isdirR   (   t   module_namet   partst   basepatht
   submodname(    (    sR   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/module_paths.pyt   find_modf   s    (	   t   __doc__t
   __future__R    R   R   R   R   R   R   (    (    (    sR   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/module_paths.pyt   <module>   s   "	