U
    \Shh                     @  s   d Z ddl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 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.    )annotationsN)glob)Iterable)__)logging)get_matching_files)SEPpath_stabilizerelpathz**/_sourcesz.#*z**/.#*z
*.lproj/**c                   @  sj   e Zd ZdZddddddZd ddd	d
ZdddddddZdddddZdddddddZdS )Projectz;A project is the source code set of the Sphinx document(s).strzdict[str, str]None)srcdirsource_suffixreturnc                 C  s   || _ || _t | _d S )N)r   r   setdocnames)selfr   r    r   A/root/rtd-docs/venv/lib/python3.8/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**zIterable[str]zset[str])exclude_pathsinclude_pathsr   c                   s   t   _t 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 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>2   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.discoverz
str | None)r-   r   c                 C  sP   | | jrt|| j}| jD ],}||rt|}|dt|    S q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bool)r.   basedirr   c                 C  sf   | ttjj}tj| j|}| jD ]}tj|| r& qNq&t	| jd }|rZ|| 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.   r7   basenamer5   r   r   r   r)   L   s    
zProject.doc2pathN)r   r   )T)	__name__
__module____qualname____doc__r   r   r1   r#   r)   r   r   r   r   r      s   
  r   )r@   
__future__r   r$   r   typingr   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   
