
    Qjf%                        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mZ erdd
lmZ  ej&                  e      Zg dZ G d d      Zy)z1Utility function and classes for Sphinx projects.    )annotationsN)glob)TYPE_CHECKING)__)logging)get_matching_files)path_stabilizerelpath)Iterable)z**/_sourcesz.#*z**/.#*z
*.lproj/**c                  F    e Zd ZdZddZd	dZ	 d
	 	 	 	 	 ddZddZddZy)Projectz;A project is the source code set of the Sphinx document(s).c                    || _         t        |      | _        t        t	        | j                        d      | _        t               | _        i | _        i | _	        y )N )
srcdirtuplesource_suffixnextiter_first_source_suffixsetdocnames_path_to_docname_docname_to_path)selfr   r   s      .lib/python3.12/site-packages/sphinx/project.py__init__zProject.__init__   sO     #=1$(d.@.@)A2$F! #&% 1302    c                j    |j                   | _         |j                  | _        |j                  | _        y)z!Take over a result of last build.N)r   r   r   )r   others     r   restorezProject.restore(   s)     % 6 6 % 6 6r   c           
        | j                   j                          | j                  j                          | j                  j                          t	        | j
                  |g |t              D ][  }| j                  |      x}s|| j                   v rt        j                  j                  | j
                  |      dz   }t        |      D cg c]  }t        || j
                         }}t        j                  t        d      ||| j!                  |d      d       t        j"                  t        j                  j                  | j
                  |      t        j$                        r;| j                   j'                  |       || j                  |<   || j                  |<   ;t        j                  t        d      ||       ^ | j                   S c c}w )zbFind all document files in the source directory and put them in
        :attr:`docnames`.
        z.*zDmultiple files found for the document "%s": %r
Use %r for the build.T)absolute)oncezIgnored unreadable document %r.)location)r   clearr   r   r   r   EXCLUDE_PATHSpath2docospathjoinr   r
   loggerwarningr   doc2pathaccessR_OKadd)r   exclude_pathsinclude_pathsfilenamedocnamepatternffiless           r   discoverzProject.discover.   s    	##%##%*KK,m,m,
 	H
 --11w1dmm+ ggll4;;@4GG>B7mLWQ4LELNN4  g=! # 	 YYrww||DKKBBGGLMM%%g.6=D))(35=D))'2NN<=xRY # 1	8 }}) Ms   Gc                   	 | j                   |   S # t        $ r t        j                  j	                  |      rYt        j                  t              5  t        j                  j                  || j                        }ddd       n# 1 sw Y   nxY w| j                  D ]N  }t        j                  j                  |      j                  |      s2t        |      j                  |      c cY S  Y yw xY 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(   r)   isabs
contextlibsuppress
ValueErrorr
   r   r   basenameendswithr	   removesuffix)r   r3   suffixs      r   r'   zProject.path2docV   s    
	((22 
	ww}}X&((4 F!wwxEHF F F ,, I77##H-66v>)(3@@HHI
 
	s5    AC2+B=	C2B	AC2C2.C21C2c                    	 | j                   |   }|r*t        j                  j                  | j                  |      S |S # t        $ r || j                  z   }Y Hw xY w)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   r4   r"   r3   s       r   r-   zProject.doc2pathi   s[    	;,,W5H
 77<<X66  	;!:!::H	;s   ? AAN)r   str | os.PathLike[str]r   Iterable[str]returnNone)r   r   rF   rG   ) )z**)r1   rE   r2   rE   rF   zset[str])r3   rD   rF   z
str | None)r4   strr"   boolrF   rI   )	__name__
__module____qualname____doc__r   r    r8   r'   r-   rH   r   r   r   r      s>    E37 QX&*&@M&	&P&r   r   )rN   
__future__r   r<   r(   r   typingr   sphinx.localer   sphinx.utilr   sphinx.util.matchingr   sphinx.util.osutilr	   r
   collections.abcr   	getLoggerrK   r+   r&   r   rH   r   r   <module>rW      sL    7 "  	      3 6(			8	$>a ar   