
    h,                         S r SSKrSSKrSSKrSSKrSSKJr  SSKJ	r	J
r
Jr  SSKJrJr  Sr\R                   " \5      rS rS rS	 rS
 rS rS r0 / 4S jr0 / 4S jrS rS rS rS rg)a  
Customizations for and integration with the Sphinx_ documentation generator.

The :mod:`humanfriendly.sphinx` module uses the `Sphinx extension API`_ to
customize the process of generating Sphinx based Python documentation. To
explore the functionality this module offers its best to start reading
from the :func:`setup()` function.

.. _Sphinx: http://www.sphinx-doc.org/
.. _Sphinx extension API: http://sphinx-doc.org/extdev/appapi.html
    N)get_aliases)compactdedentformat)USAGE_MARKERrender_usage)deprecation_note_callbackenable_deprecation_notesenable_man_roleenable_pypi_roleenable_special_methodsenable_usage_formattingloggerman_role	pypi_rolesetupspecial_methods_callbackusage_message_callbackc                 (   [        U[        R                  5      (       a  U(       a  [        UR                  5      nU(       a  [        SR                  U5      5      /nUR                  S5        Sn[        U5      S:X  a  Sn	OSn	UR                  U[        U	5      -   5        UR                  5        H?  u  p*UR                  [        SX5      5        UR                  [        SUS	-  U
5      5        MA     [        US
R                  U5      5        gggg)a2  
Automatically document aliases defined using :func:`~humanfriendly.deprecation.define_aliases()`.

Refer to :func:`enable_deprecation_notes()` to enable the use of this
function (you probably don't want to call :func:`deprecation_note_callback()`
directly).

This function implements a callback for ``autodoc-process-docstring`` that
reformats module docstrings to append an overview of aliases defined by the
module.

The parameters expected by this function are those defined for Sphinx event
callback functions (i.e. I'm not going to document them here :-).

z.. note:: Deprecated namesz      a+  
                    The following alias exists to preserve backwards compatibility,
                    however a :exc:`~exceptions.DeprecationWarning` is triggered
                    when it is accessed, because this alias will be removed
                    in a future release.
                a2  
                    The following aliases exist to preserve backwards compatibility,
                    however a :exc:`~exceptions.DeprecationWarning` is triggered
                    when they are accessed, because these aliases will be
                    removed in a future release.
                z%s.. data:: %sz%sAlias for :obj:`%s`.   z

N)
isinstancetypes
ModuleTyper   __name__r   joinappendlenr   itemsr   update_lines)appwhatnameobjoptionslinesaliasesblocksindentexplanationtargets              N/var/www/fran/franai/venv/lib/python3.13/site-packages/humanfriendly/sphinx.pyr	   r	   4   s     #u''((Ucll+ TYYu-./F MM67F7|q  MM&7;#778 'f%5vDEf%=vz6RS !0 F 34;  .3(    c                 0    U R                  S[        5        g)a3  
Enable documenting backwards compatibility aliases using the autodoc_ extension.

:param app: The Sphinx application object.

This function connects the :func:`deprecation_note_callback()` function to
``autodoc-process-docstring`` events.

.. _autodoc: http://www.sphinx-doc.org/en/stable/ext/autodoc.html
autodoc-process-docstringN)connectr	   r"   s    r-   r
   r
   e   s     KK+-FGr.   c                 0    U R                  S[        5        g)z
Enable the ``:man:`` role for linking to Debian Linux manual pages.

:param app: The Sphinx application object.

This function registers the :func:`man_role()` function to handle the
``:man:`` role.
manN)add_roler   r2   s    r-   r   r   s   s     LL!r.   c                 0    U R                  S[        5        g)z
Enable the ``:pypi:`` role for linking to the Python Package Index.

:param app: The Sphinx application object.

This function registers the :func:`pypi_role()` function to handle the
``:pypi:`` role.
pypiN)r5   r   r2   s    r-   r   r      s     LL#r.   c                 0    U R                  S[        5        g)a  
Enable documenting "special methods" using the autodoc_ extension.

:param app: The Sphinx application object.

This function connects the :func:`special_methods_callback()` function to
``autodoc-skip-member`` events.

.. _autodoc: http://www.sphinx-doc.org/en/stable/ext/autodoc.html
zautodoc-skip-memberN)r1   r   r2   s    r-   r   r      s     KK%'?@r.   c                 0    U R                  S[        5        g)a9  
Reformat human friendly usage messages to reStructuredText_.

:param app: The Sphinx application object (as given to ``setup()``).

This function connects the :func:`usage_message_callback()` function to
``autodoc-process-docstring`` events.

.. _reStructuredText: https://en.wikipedia.org/wiki/ReStructuredText
r0   N)r1   r   r2   s    r-   r   r      s     KK+-CDr.   c                     SU-  n[         R                  R                  " U[         R                  R	                  U5      4SU0UD6nU// 4$ )a  
Convert a Linux manual topic to a hyperlink.

Using the ``:man:`` role is very simple, here's an example:

.. code-block:: rst

    See the :man:`python` documentation.

This results in the following:

  See the :man:`python` documentation.

As the example shows you can use the role inline, embedded in sentences of
text. In the generated documentation the ``:man:`` text is omitted and a
hyperlink pointing to the Debian Linux manual pages is emitted.
zhttps://manpages.debian.org/%srefuridocutilsnodes	referenceutilsunescape)	rolerawtexttextlinenoinlinerr&   contentman_urlr?   s	            r-   r   r      sK    $ /5G(((..2I2I$2OkX_kcjkI;?r.   c                     SU-  n[         R                  R                  " U[         R                  R	                  U5      4SU0UD6nU// 4$ )a  
Generate hyperlinks to the Python Package Index.

Using the ``:pypi:`` role is very simple, here's an example:

.. code-block:: rst

    See the :pypi:`humanfriendly` package.

This results in the following:

  See the :pypi:`humanfriendly` package.

As the example shows you can use the role inline, embedded in sentences of
text. In the generated documentation the ``:pypi:`` text is omitted and a
hyperlink pointing to the Python Package Index is emitted.
zhttps://pypi.org/project/%s/r;   r<   )	rB   rC   rD   rE   rF   r&   rG   pypi_urlr?   s	            r-   r   r      sK    $ .4H(((..2I2I$2OlX`ldklI;?r.   c                     SSK Jn  [        U 5        [        U 5        [	        U 5        [        U 5        [        U 5        [        SSUS9$ )a:  
Enable all of the provided Sphinx_ customizations.

:param app: The Sphinx application object.

The :func:`setup()` function makes it easy to enable all of the Sphinx
customizations provided by the :mod:`humanfriendly.sphinx` module with the
least amount of code. All you need to do is to add the module name to the
``extensions`` variable in your ``conf.py`` file:

.. code-block:: python

   # Sphinx extension module names.
   extensions = [
       'sphinx.ext.autodoc',
       'sphinx.ext.doctest',
       'sphinx.ext.intersphinx',
       'humanfriendly.sphinx',
   ]

When Sphinx sees the :mod:`humanfriendly.sphinx` name it will import the
module and call its :func:`setup()` function. This function will then call
the following:

- :func:`enable_deprecation_notes()`
- :func:`enable_man_role()`
- :func:`enable_pypi_role()`
- :func:`enable_special_methods()`
- :func:`enable_usage_formatting()`

Of course more functionality may be added at a later stage. If you don't
like that idea you may be better of calling the individual functions from
your own ``setup()`` function.
r   )__version__T)parallel_read_safeparallel_write_safeversion)humanfriendlyrL   r
   r   r   r   r   dict)r"   rL   s     r-   r   r      s?    F *S!CS3C 4T;WWr.   c                     [        USS5      (       a0  [        U[        R                  [        R                  45      (       a  gU$ )aZ  
Enable documenting "special methods" using the autodoc_ extension.

Refer to :func:`enable_special_methods()` to enable the use of this
function (you probably don't want to call
:func:`special_methods_callback()` directly).

This function implements a callback for ``autodoc-skip-member`` events to
include documented "special methods" (method names with two leading and two
trailing underscores) in your documentation. The result is similar to the
use of the ``special-members`` flag with one big difference: Special
methods are included but other types of members are ignored. This means
that attributes like ``__weakref__`` will always be ignored (this was my
main annoyance with the ``special-members`` flag).

The parameters expected by this function are those defined for Sphinx event
callback functions (i.e. I'm not going to document them here :-).
__doc__NF)getattrr   r   FunctionType
MethodType)r"   r#   r$   r%   skipr&   s         r-   r   r     s8    & sIt$$C%:L:LeN^N^9_)`)`r.   c                     U (       a  U R                  5         U (       a  M  U R                  UR                  5       5        g)z;Private helper for ``autodoc-process-docstring`` callbacks.N)popextend
splitlines)r'   rD   s     r-   r!   r!     s(    
		 %	LL"#r.   c                     [        U[        R                  5      (       aL  U(       aD  US   R                  [        5      (       a&  [        SR                  U5      5      n[        XV5        gggg)a  
Reformat human friendly usage messages to reStructuredText_.

Refer to :func:`enable_usage_formatting()` to enable the use of this
function (you probably don't want to call :func:`usage_message_callback()`
directly).

This function implements a callback for ``autodoc-process-docstring`` that
reformats module docstrings using :func:`.render_usage()` so that Sphinx
doesn't mangle usage messages that were written to be human readable
instead of machine readable. Only module docstrings whose first line starts
with :data:`.USAGE_MARKER` are reformatted.

The parameters expected by this function are those defined for Sphinx event
callback functions (i.e. I'm not going to document them here :-).
r   r   N)r   r   r   
startswithr   r   r   r!   )r"   r#   r$   r%   r&   r'   rD   s          r-   r   r   #  sV    $ #u''((U8|,,		% 01D%	 - .3(r.   )rS   loggingr   docutils.nodesr=   docutils.utilshumanfriendly.deprecationr   humanfriendly.textr   r   r   humanfriendly.usager   r   __all__	getLoggerr   r   r	   r
   r   r   r   r   r   r   r   r   r!   r    r.   r-   <module>rg      s   
     2 6 6 :  
		8	$.5bH	"	$AE <>r . =? .+X\2$&r.   