o
    qo™iŸ  ã                   @   sP   d Z ddlmZ ddlmZ ddlmZ G dd„ dejƒZdedefd	d
„Z	dS )ak  Routines for nice string representations of cfg values.

Some types (e.g. numpy arrays, jax dtypes, TensorFlow, etc) are often referred
unambiguously by a name that differs from their qualified path. This library
exposes the pretty-printing functionality that powers the codegen features to
other string representations, such as graphviz or string serialization.
é    )ÚAny)Úlegacy_codegen)Úspecial_value_codegenc                   @   s"   e Zd ZdZdedefdd„ZdS )ÚLazyImportManagera  Import manager for GraphViz & string formatting.

  We create an instance of the codegen's import manager on every method call,
  which effectively will alias imports like 'jax.numpy' to 'jnp', but will not
  create new import aliases when two modules of the same name are referenced.
  Úmodule_nameÚreturnc                 C   s   t  ¡ }t  |¡}| |¡S )zCReturns the usable name generated from an ephemeral import manager.)r   Ú	NamespaceÚImportManagerÚadd_by_name)Úselfr   Ú	namespaceÚimport_manager© r   ú\/home/ubuntu/.local/lib/python3.10/site-packages/fiddle/_src/codegen/formatting_utilities.pyr
   &   s   

zLazyImportManager.add_by_nameN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr
   r   r   r   r   r      s    r   Úvaluer   c                 C   s   t t | tƒ ¡ƒS )z?Returns the nicest eval-able string representation for `value`.)Úreprr   Útransform_py_valuer   )r   r   r   r   Úpretty_print-   s   ÿr   N)
r   Útypingr   Úfiddle._src.codegenr   r   ÚImportManagerApir   r   r   r   r   r   r   Ú<module>   s   