B
    d^                 @   s   d Z ddl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 ddlmZ ddlmZmZmZ eeZd	d
ddgZG dd dZdS )z1Utility function and classes for Sphinx projects.    N)glob)DictIterableOptionalSet)__)logging)get_matching_files)SEPpath_stabilizerelpathz**/_sourcesz.#*z**/.#*z
*.lproj/**c               @   s   e Zd ZdZeeeef ddddZd ddddZdee ee e	e dddZ
eee dddZdeeedddZdS )Projectz;A project is the source code set of the Sphinx document(s).N)srcdirsource_suffixreturnc             C   s   || _ || _t | _d S )N)r   r   setdocnames)selfr   r    r   [/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/sphinx/project.py__init__   s    zProject.__init__)otherr   c             C   s   |j | _ dS )z!Take over a result of last build.N)r   )r   r   r   r   r   restore   s    zProject.restorer   z**)exclude_pathsinclude_pathsr   c                s   t   _xt j||t D ]} |}|r| jkrtj j|d } fddt	|D }t
jtd|| |dd qttj j|tjr j| qt
jtd|d qW  jS )	zbFind all document files in the source directory and put them in
        :attr:`docnames`.
        z.*c                s   g | ]}t | jqS r   )r   r   ).0f)r   r   r   
<listcomp>0   s    z$Project.discover.<locals>.<listcomp>zDmultiple files found for the document "%s": %r
Use %r for the build.T)oncezdocument not readable. Ignored.)location)r   r   r	   r   EXCLUDE_PATHSpath2docospathjoinr   loggerwarningr   doc2pathaccessR_OKadd)r   r   r   filenamedocnamepatternfilesr   )r   r   discover!   s     


zProject.discover)r,   r   c             C   sP   | | jrt|| j}x2| jD ](}||r t|}|dt|  S q W dS )zReturn the docname for the filename if the file is a document.

        *filename* should be absolute or relative to the source directory.
        N)
startswithr   r   r   endswithr   len)r   r,   suffixr   r   r   r"   ;   s    
zProject.path2docT)r-   basedirr   c             C   sh   | ttjj}tj| j|}x.| jD ]}tj|| r(P q(W t	| jd }|r\|| S || S dS )zReturn the filename for the document name.

        If *basedir* is True, return as an absolute path.
        Else, return as a relative path to the source directory.
        r   N)
replacer
   r#   r$   sepr%   r   r   isfilelist)r   r-   r5   basenamer4   r   r   r   r(   J   s    zProject.doc2path)r   r   )T)__name__
__module____qualname____doc__strr   r   r   r   r   r0   r   r"   boolr(   r   r   r   r   r      s   
  r   )r>   r#   r   typingr   r   r   r   Zsphinx.localer   Zsphinx.utilr   Zsphinx.util.matchingr	   Zsphinx.util.osutilr
   r   r   	getLoggerr;   r&   r!   r   r   r   r   r   <module>   s   
