ó
çiõ\c           @   su   d  d l  Z  d  d l Z d d l m Z d  d l m Z e d „ Z d d „ Z	 d „  Z
 d „  Z d d d	 „ Z d S(
   iÿÿÿÿNi   (   t
   UsageError(   t   failc         C   s'   y |  j  ƒ  SWn | k
 r" t SXd  S(   N(   t   checkt   False(   t   patht   ignore(    (    s7   lib/python2.7/site-packages/_pytest/config/findpaths.pyt   exists
   s    c   
      C   s‰  d d l  m } d d d g } g  |  D]! } t | ƒ j d ƒ s& | ^ q& }  |  sh t j j ƒ  g }  n  x|  D]} t j j | ƒ } x÷ | j d t ƒ D]ã } xÚ | D]Ò } | j	 | ƒ } t
 | ƒ r§ t j j | ƒ }	 | d k rd |	 j k r| | |	 d f Sd	 |	 j k r]| d k rL| d k	 rLt | j d
 | ƒ d t ƒn  | | |	 d	 f S| d k ry| | i  f Sq§ q§ Wqš Wqo Wd S(   sÑ   
    Search the list of arguments for a valid ini-file for pytest,
    and return a tuple of (rootdir, inifile, cfg-dict).

    note: config is optional and used only to issue warnings explicitly (#2891).
    iÿÿÿÿ(   t   CFG_PYTEST_SECTIONs
   pytest.inis   tox.inis	   setup.cfgt   -t   reverses   tool:pytestt   pytestt   filenamet   pytraceN(   NNN(   t   _pytest.deprecatedR   t   strt
   startswitht   pyR   t   localt   partst   Truet   joinR   t	   iniconfigt	   IniConfigt   sectionst   NoneR   t   formatR   (
   t   argst   configR   t   inibasenamest   xt   argt   baset   inibasenamet   pR   (    (    s7   lib/python2.7/site-packages/_pytest/config/findpaths.pyt   getcfg   s0    .
c         C   sØ   d  } x’ |  D]Š } | j ƒ  s% q n  | d  k r: | } q | j | ƒ s | | k r[ q q | j | ƒ rs | } q | j | ƒ } | d  k	 r | } q q W| d  k r¹ t j j ƒ  } n | j ƒ  rÔ | j ƒ  } n  | S(   N(	   R   R   t   reltot   commonR   R   R   t   isfilet   dirpath(   t   pathst   common_ancestorR   t   shared(    (    s7   lib/python2.7/site-packages/_pytest/config/findpaths.pyt   get_common_ancestor8   s$    		c            s]   d „  ‰ d „  ‰  d „  } ‡  ‡ f d †  |  Dƒ } g  | D] } | j  ƒ  r; | | ƒ ^ q; S(   Nc         S   s   t  |  ƒ j d ƒ S(   NR   (   R   R   (   R   (    (    s7   lib/python2.7/site-packages/_pytest/config/findpaths.pyt	   is_optionP   s    c         S   s   t  |  ƒ j d ƒ d S(   Ns   ::i    (   R   t   split(   R   (    (    s7   lib/python2.7/site-packages/_pytest/config/findpaths.pyt   get_file_part_from_node_idS   s    c         S   s#   |  j  ƒ  r |  St j j |  j ƒ S(   N(   t   isdirR   R   R   t   dirname(   R   (    (    s7   lib/python2.7/site-packages/_pytest/config/findpaths.pyt   get_dir_from_pathV   s    c         3   s3   |  ]) } ˆ | ƒ s t  j j ˆ  | ƒ ƒ Vq d  S(   N(   R   R   R   (   t   .0R   (   R-   R+   (    s7   lib/python2.7/site-packages/_pytest/config/findpaths.pys	   <genexpr>]   s   (   R   (   R   R0   t   possible_pathsR   (    (   R-   R+   s7   lib/python2.7/site-packages/_pytest/config/findpaths.pyt   get_dirs_from_argsO   s    			
c         C   s„  t  | ƒ } |  rÿ t j j |  ƒ } t |  ƒ j d ƒ } | rK d d g n d g } xŠ | D]‚ } yb | | }	 | rÁ | d k rÁ | d  k	 rÁ d d l m }
 t	 |
 j
 d t |  ƒ ƒ d t ƒn  PWq[ t k
 rÜ d  }	 q[ Xq[ W| d  k r&t | ƒ } q&n't | ƒ } t | g d | ƒ\ } }  }	 | d  k r&| d  k r&xâ | j d	 t ƒ D]% } | j d
 ƒ j ƒ  rT| } PqTqTW| | g k rªt | d | ƒ\ } }  }	 n  | d  k r&| d  k	 rÎ| j } n t j j ƒ  } t | | g ƒ } t j j t | ƒ ƒ d d k } | r#| } q#q&n  | rqt j j t j j | ƒ ƒ } | j ƒ  sqt d j
 | ƒ ƒ ‚ qqn  | |  |	 p€i  f S(   Ns   .cfgs   tool:pytestR
   iÿÿÿÿ(   R   R   R   R   R	   s   setup.pyi   t   /s8   Directory '{}' not found. Check your '--rootdir' option.(   R3   R   R   R   R   t   endswithR   R   R   R   R   R   t   KeyErrorR*   R"   R   R   R   R   t   invocation_dirR   R   t   ost
   splitdrivet
   expandvarsR.   R    (   t   inifileR   t   rootdir_cmd_argR   t   dirsR   t   is_cfg_fileR   t   sectiont   inicfgR   t   rootdirt   ancestort   possible_rootdirt   cwdt
   is_fs_root(    (    s7   lib/python2.7/site-packages/_pytest/config/findpaths.pyt   determine_setupe   sR    
""(   R8   R   t
   exceptionsR    t   _pytest.outcomesR   t   EnvironmentErrorR   R   R"   R*   R3   RF   (    (    (    s7   lib/python2.7/site-packages/_pytest/config/findpaths.pyt   <module>   s   '		