
    ^j                    n    d Z ddlmZ ddlZddlZ	 ddlZ G d dej                        Zy# e$ r Y yw xY w)u  Griffe extension: expose runtime-modified docstrings to mkdocstrings.

.. note::
    **Beta feature** — the public API of this module (class name, hook method
    signatures) may change in a minor release while it stabilises.

``@deprecated(update_docstring=True)`` writes the deprecation notice into
``fn.__doc__`` at decoration time.  Griffe — the engine used by mkdocstrings —
reads docstrings from the source AST, so it never sees that runtime change.

This extension bridges the gap: after Griffe has visited a module it imports
the module at runtime and replaces every AST docstring whose callable carries
a ``__deprecated__`` attribute (set by pyDeprecate) with the live ``__doc__``.

Usage in ``mkdocs.yml``::

    plugins:
      - mkdocstrings:
          handlers:
            python:
              options:
                extensions:
                  - deprecate.docstring.griffe_ext:RuntimeDocstrings

Requirements:
    ``griffe`` is a dependency of ``mkdocstrings[python]`` and will always be
    present in an MkDocs environment that uses mkdocstrings.  Importing this
    module without ``griffe`` installed is safe — ``RuntimeDocstrings`` simply
    will not be defined.

    )annotationsNc                  D    e Zd ZdZddZedd       Zd	dZed
d       Zy)RuntimeDocstringszCUpdate Griffe docstrings to reflect decorator-modified ``__doc__``.c                   | j                  |      }|y|j                  j                         D ]3  \  }}t        |t        j
                        s!| j                  |||       5 y)a!  Run after a module is fully loaded by Griffe.

            For each function or method in *mod* that carries a ``__deprecated__`` attribute (set by pyDeprecate),
            replace the Griffe docstring with the runtime value so that mkdocstrings renders the injected notice.

            N)_import_modulemembersitems
isinstancegriffeObject_update_obj)selfmodloaderkwargsruntime_modnameobjs          i/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/deprecate/docstring/griffe_ext.py	on_modulezRuntimeDocstrings.on_module/   s]     --c2K" [[..0 =	cc6==1$$S+t<=    c                   	 t        j                  | j                        S # t        t        f$ r Y nw xY wt        | dd      }|yddl}|j                  |      }t        | j                  j                  d            dz
  }|j                  dk(  r|dz  }t        |j                  |         }|t        j                  v}|r t        j                  j                  d|       	 t        j                  | j                        |r t        j                  j                  |       S S # t        t        f$ r% Y |r t        j                  j                  |       yyw xY w# |r t        j                  j                  |       w w xY w)ut  Import *mod* at runtime, adding its package root to sys.path if needed.

            griffe loads modules via its own search_paths which are not on sys.path, so a plain
            ``importlib.import_module(mod.name)`` will fail for modules that live outside the installed packages (e.g. a
            local ``demo.py``). We derive the package root from ``mod.filepath`` — walking up one level per dotted name
            component so that both single-file modules (``demo``) and package sub-modules (``pkg.submod``) resolve
            correctly — and temporarily add it to sys.path so the import can succeed.

            filepathNr   .   z__init__.py)	importlibimport_moduler   ImportErrorModuleNotFoundErrorgetattrpathlibPathlensplitstrparentssyspathinsertremove)r   r   r!   pdepth
source_diraddeds          r   r   z RuntimeDocstrings._import_module>   sE    ..sxx88!45  sJ5H X&As+,q0Evv&
QYYu-.Jchh.E:.0 ..sxx8 HHOOJ/   !45 HHOOJ/  HHOOJ/ s0   ! 33#D$ $E3E EE $E?c                x   t        ||d       }|y t        |t        j                        r| j	                  ||       y t        |t        j
                        rc| j	                  ||       |j                  j                         D ]3  \  }}t        |t        j                        s!| j                  |||       5 y y )N)
r    r
   r   Function_replace_docstringClassr   r	   r   r   )r   r   parentr   runtime_objmember_namemembers          r   r   zRuntimeDocstrings._update_objo   s    !&$5K"#v/''[9C.''[9+.;;+<+<+> K'K!&&--8((kJK /r   c                    t        |dd      syt        |dd      }|sy| j                  y|| j                  _        | j                  j                  j	                  dd       y)zDOverwrite the Griffe docstring when the runtime ``__doc__`` differs.__deprecated__N__doc__parsed)r    	docstringvalue__dict__pop)
griffe_objr4   runtime_docs      r   r1   z$RuntimeDocstrings._replace_docstring|   sc     ;(8$?!+y$?K##+)4J  &
   ))--h=r   N)r   griffe.Moduler   zgriffe.GriffeLoaderr   objectreturnNone)r   rA   rC   rB   )r   griffe.Objectr3   rB   r   r%   rC   rD   )r?   rE   r4   rB   rC   rD   )	__name__
__module____qualname__r9   r   staticmethodr   r   r1    r   r   r   r   ,   s9    Q	= 
.	0 
.	0`	K 
	> 
	>r   r   )	r9   
__future__r   r   r'   r   	Extensionr   r   rJ   r   r   <module>rM      sG   @ #  
e>
_>F,, _>	  		s   , 44