o
    Ni                     @  s   d Z ddlmZ ddl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 dd
lmZ erBddlmZ eeZg dZG dd dZdS )z1Utility function and classes for Sphinx projects.    )annotationsN)Path)TYPE_CHECKING)__)logging)_StrPath)get_matching_files)path_stabilize)Iterable)z**/_sourcesz.#*z**/.#*z
*.lproj/**c                   @  sF   e Zd ZdZd dd	Zd!ddZ	d"d#ddZd$ddZd%ddZdS )&Projectz;A project is the source code set of the Sphinx document(s).srcdirstr | os.PathLike[str]source_suffixIterable[str]returnNonec                 C  s>   t || _t|| _tt| jd| _t | _i | _	i | _
d S )N )r   r   tupler   nextiter_first_source_suffixsetdocnames_path_to_docname_docname_to_path)selfr   r    r   B/home/ubuntu/.local/lib/python3.10/site-packages/sphinx/project.py__init__   s   


zProject.__init__otherc                 C  s   |j | _ |j| _|j| _dS )z!Take over a result of last build.N)r   r   r   )r   r   r   r   r   restore+   s   zProject.restorer   z**exclude_pathsinclude_pathsset[str]c              	     s    j    j   j  t j|g |tD ]\} | }rv| j v rM fdd j| dD }t	j
td|d| j|dddd qt j| tjrl j | t|}| j|< | j|< qt	j
td	||d
 q j S )zbFind all document files in the source directory and put them in
        :attr:`docnames`.
        c                   s   g | ]
}t | jqS r   )strrelative_tor   ).0fr   r   r   
<listcomp>B   s    z$Project.discover.<locals>.<listcomp>z.*zDmultiple files found for the document "%s": %s
Use %r for the build.z, T)absolute)oncezIgnored unreadable document %r.)location)r   clearr   r   r   r   EXCLUDE_PATHSpath2docglobloggerwarningr   joindoc2pathosaccessR_OKaddr   )r   r"   r#   filenamedocnamefilespathr   r)   r   discover1   sD   







zProject.discoverr:   
str | Nonec                 C  s   z| j | W S  tyJ   t|}| r0tt || j}W d   n1 s+w   Y  | j	D ]}|j
|rFt||   Y S q3Y dS w )zReturn the docname for the filename if the file is a document.

        *filename* should be absolute or relative to the source directory.
        N)r   KeyErrorr   is_absolute
contextlibsuppress
ValueErrorr&   r   r   nameendswithr	   removesuffix)r   r:   r=   suffixr   r   r   r0   ^   s   
zProject.path2docr;   r%   r+   boolr   c                 C  sJ   z| j | }W n ty   t|| j }Y nw |r!t| j| S t|S )zReturn the filename for the document name.

        If *absolute* is True, return as an absolute path.
        Else, return as a relative path to the source directory.
        )r   r@   r   r   r   r   )r   r;   r+   r:   r   r   r   r5   r   s   zProject.doc2pathN)r   r   r   r   r   r   )r   r   r   r   )r   r!   )r"   r   r#   r   r   r$   )r:   r   r   r?   )r;   r%   r+   rI   r   r   )	__name__
__module____qualname____doc__r   r    r>   r0   r5   r   r   r   r   r      s    


-r   )rM   
__future__r   rB   r6   pathlibr   typingr   sphinx.localer   sphinx.utilr   sphinx.util._pathlibr   sphinx.util.matchingr   sphinx.util.osutilr	   collections.abcr
   	getLoggerrJ   r2   r/   r   r   r   r   r   <module>   s     
