a
    d=ic 5                     @   s   d Z ddlmZ ddlmZ G dd dedZG dd deZG d	d
 d
eZG dd deZG dd deZ	G dd de
ZdS )zTensorBoard Plugin abstract base class.

Every plugin in TensorBoard must extend and implement the abstract
methods of this base class.
    )ABCMeta)abstractmethodc                   @   sD   e Zd ZdZdZdd Zedd Zedd Zd	d
 Z	dd Z
dS )TBPlugina  TensorBoard plugin interface.

    Every plugin must extend from this class.

    Subclasses should have a trivial constructor that takes a TBContext
    argument. Any operation that might throw an exception should either be
    done lazily or made safe with a TBLoader subclass, so the plugin won't
    negatively impact the rest of TensorBoard.

    Fields:
      plugin_name: The plugin_name will also be a prefix in the http
        handlers, e.g. `data/plugins/$PLUGIN_NAME/$HANDLER` The plugin
        name must be unique for each registered plugin, or a ValueError
        will be thrown when the application is constructed. The plugin
        name must only contain characters among [A-Za-z0-9_.-], and must
        be nonempty, or a ValueError will similarly be thrown.
    Nc                 C   s   dS )zInitializes this plugin.

        The default implementation does nothing. Subclasses are encouraged
        to override this and save any necessary fields from the `context`.

        Args:
          context: A `base_plugin.TBContext` object.
        N selfcontextr   r   p/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/tensorboard/plugins/base_plugin.py__init__/   s    	zTBPlugin.__init__c                 C   s
   t  dS )aa  Returns a set of WSGI applications that the plugin implements.

        Each application gets registered with the tensorboard app and is served
        under a prefix path that includes the name of the plugin.

        Returns:
          A dict mapping route paths to WSGI applications. Each route path
          should include a leading slash.
        NNotImplementedErrorr   r   r   r	   get_plugin_apps:   s    zTBPlugin.get_plugin_appsc                 C   s
   t  dS )a"  Determines whether this plugin is active.

        A plugin may not be active for instance if it lacks relevant data. If a
        plugin is inactive, the frontend may avoid issuing requests to its routes.

        Returns:
          A boolean value. Whether this plugin is active.
        Nr   r   r   r   r	   	is_activeG   s    
zTBPlugin.is_activec                 C   s   t  S )a?  Defines how the plugin will be displayed on the frontend.

        The base implementation returns a default value. Subclasses
        should override this and specify either an `es_module_path` or
        (for legacy plugins) an `element_name`, and are encouraged to
        set any other relevant attributes.
        )FrontendMetadatar   r   r   r	   frontend_metadataS   s    zTBPlugin.frontend_metadatac                 C   s   | j fS )a.  Experimental. Lists plugins whose summary data this plugin reads.

        Returns:
          A collection of strings representing plugin names (as read
          from `SummaryMetadata.plugin_data.plugin_name`) from which
          this plugin may read data. Defaults to `(self.plugin_name,)`.
        )plugin_namer   r   r   r	   data_plugin_names]   s    zTBPlugin.data_plugin_names)__name__
__module____qualname____doc__r   r
   r   r   r   r   r   r   r   r   r	   r      s   


r   )	metaclassc                   @   s   e Zd ZdZdddddddddZedd Zedd	 Zed
d Zedd Z	edd Z
edd Zdd Zdd Zdd ZdS )r   zMetadata required to render a plugin on the frontend.

    Each argument to the constructor is publicly accessible under a
    field of the same name. See constructor docs for further details.
    N)disable_reloadelement_namees_module_path
remove_domtab_nameis_ng_componentc                C   sL   |du rdn|| _ || _|| _|du r*dn|| _|| _|du rBdn|| _dS )a2  Creates a `FrontendMetadata` value.

        The argument list is sorted and may be extended in the future;
        therefore, callers must pass only named arguments to this
        constructor.

        Args:
          disable_reload: Whether to disable the reload button and
              auto-reload timer. A `bool`; defaults to `False`.
          element_name: For legacy plugins, name of the custom element
              defining the plugin frontend: e.g., `"tf-scalar-dashboard"`.
              A `str` or `None` (for iframed plugins). Mutually exclusive
              with `es_module_path`.
          es_module_path: ES module to use as an entry point to this plugin.
              A `str` that is a key in the result of `get_plugin_apps()`, or
              `None` for legacy plugins bundled with TensorBoard as part of
              `webfiles.zip`. Mutually exclusive with legacy `element_name`
          remove_dom: Whether to remove the plugin DOM when switching to a
              different plugin, to trigger the Polymer 'detached' event.
              A `bool`; defaults to `False`.
          tab_name: Name to show in the menu item for this dashboard within
              the navigation bar. May differ from the plugin name: for
              instance, the tab name should not use underscores to separate
              words. Should be a `str` or `None` (the default; indicates to
              use the plugin name as the tab name).
          is_ng_component: Set to `True` only for built-in Angular plugins.
              In this case, the `plugin_name` property of the Plugin, which is
              mapped to the `id` property in JavaScript's `UiPluginMetadata` type,
              is used to select the Angular component. A `True` value is mutually
              exclusive with `element_name` and `es_module_path`.
        NF)_disable_reload_element_name_es_module_path_remove_dom	_tab_name_is_ng_component)r   r   r   r   r   r   r   r   r   r	   r
   o   s    *zFrontendMetadata.__init__c                 C   s   | j S N)r   r   r   r   r	   r      s    zFrontendMetadata.disable_reloadc                 C   s   | j S r%   )r    r   r   r   r	   r      s    zFrontendMetadata.element_namec                 C   s   | j S r%   )r$   r   r   r   r	   r      s    z FrontendMetadata.is_ng_componentc                 C   s   | j S r%   )r!   r   r   r   r	   r      s    zFrontendMetadata.es_module_pathc                 C   s   | j S r%   )r"   r   r   r   r	   r      s    zFrontendMetadata.remove_domc                 C   s   | j S r%   )r#   r   r   r   r	   r      s    zFrontendMetadata.tab_namec                 C   sr   t |tsdS | j|jkrdS | j|jkr.dS | j|jkr>dS | j|jkrNdS | j|jkr^dS | j|jkrndS dS )NFT)
isinstancer   r   r    r!   r"   r#   )r   otherr   r   r	   __eq__   s    
zFrontendMetadata.__eq__c                 C   s    t | j| j| j| j| j| jfS r%   )hashr   r    r!   r"   r#   r$   r   r   r   r	   __hash__   s    zFrontendMetadata.__hash__c              
   C   s>   dd d| j d| j d| j d| j d| j d| j f S )	NzFrontendMetadata(%s)z, zdisable_reload=%rzelement_name=%rzes_module_path=%rzremove_dom=%rztab_name=%rzis_ng_component=%r)joinr   r    r!   r"   r#   r$   r   r   r   r	   __repr__   s    zFrontendMetadata.__repr__)r   r   r   r   r
   propertyr   r   r   r   r   r   r(   r*   r,   r   r   r   r	   r   h   s.   	4





r   c                	   @   s,   e Zd ZdZdddddddddddZdS )	TBContexta  Magic container of information passed from TensorBoard core to plugins.

    A TBContext instance is passed to the constructor of a TBPlugin class. Plugins
    are strongly encouraged to assume that any of these fields can be None. In
    cases when a field is considered mandatory by a plugin, it can either crash
    with ValueError, or silently choose to disable itself by returning False from
    its is_active method.

    All fields in this object are thread safe.
    Nassets_zip_providerdata_providerflagslogdirmultiplexerplugin_name_to_instancesampling_hintswindow_titlec          	      C   s4   || _ || _|| _|| _|| _|| _|| _|| _dS )a  Instantiates magic container.

        The argument list is sorted and may be extended in the future; therefore,
        callers must pass only named arguments to this constructor.

        Args:
          assets_zip_provider: A function that returns a newly opened file handle
              for a zip file containing all static assets. The file names inside the
              zip file are considered absolute paths on the web server. The file
              handle this function returns must be closed. It is assumed that you
              will pass this file handle to zipfile.ZipFile. This zip file should
              also have been created by the tensorboard_zip_file build rule.
          data_provider: Instance of `tensorboard.data.provider.DataProvider`. May
            be `None` if `flags.generic_data` is set to `"false"`.
          flags: An object of the runtime flags provided to TensorBoard to their
              values.
          logdir: The string logging directory TensorBoard was started with.
          multiplexer: An EventMultiplexer with underlying TB data. Plugins should
              copy this data over to the database when the db fields are set.
          plugin_name_to_instance: A mapping between plugin name to instance.
              Plugins may use this property to access other plugins. The context
              object is passed to plugins during their construction, so a given
              plugin may be absent from this mapping until it is registered. Plugin
              logic should handle cases in which a plugin is absent from this
              mapping, lest a KeyError is raised.
          sampling_hints: Map from plugin name to `int` or `NoneType`, where
              the value represents the user-specified downsampling limit as
              given to the `--samples_per_plugin` flag, or `None` if none was
              explicitly given for this plugin.
          window_title: A string specifying the window title.
        Nr/   )	r   r0   r1   r2   r3   r4   r5   r6   r7   r   r   r	   r
      s    +zTBContext.__init__)r   r   r   r   r
   r   r   r   r	   r.      s   r.   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	TBLoadera  TBPlugin factory base class.

    Plugins can override this class to customize how a plugin is loaded at
    startup. This might entail adding command-line arguments, checking if
    optional dependencies are installed, and potentially also specializing
    the plugin class at runtime.

    When plugins use optional dependencies, the loader needs to be
    specified in its own module. That way it's guaranteed to be
    importable, even if the `TBPlugin` itself can't be imported.

    Subclasses must have trivial constructors.
    c                 C   s   dS )a  Adds plugin-specific CLI flags to parser.

        The default behavior is to do nothing.

        When overriding this method, it's recommended that plugins call the
        `parser.add_argument_group(plugin_name)` method for readability. No
        flags should be specified that would cause `parse_args([])` to fail.

        Args:
          parser: The argument parsing object, which may be mutated.
        Nr   )r   parserr   r   r	   define_flags5  s    zTBLoader.define_flagsc                 C   s   dS )a  Allows flag values to be corrected or validated after parsing.

        Args:
          flags: The parsed argparse.Namespace object.

        Raises:
          base_plugin.FlagsError: If a flag is invalid or a required
              flag is not passed.
        Nr   )r   r2   r   r   r	   	fix_flagsC  s    
zTBLoader.fix_flagsc                 C   s   dS )a7  Loads a TBPlugin instance during the setup phase.

        Args:
          context: The TBContext instance.

        Returns:
          A plugin instance or None if it could not be loaded. Loaders that return
          None are skipped.

        :type context: TBContext
        :rtype: TBPlugin | None
        Nr   r   r   r   r	   loadO  s    zTBLoader.loadN)r   r   r   r   r:   r;   r<   r   r   r   r	   r8   &  s   r8   c                   @   s    e Zd ZdZdd Zdd ZdS )BasicLoaderz3Simple TBLoader that's sufficient for most plugins.c                 C   s
   || _ dS )z^Creates simple plugin instance maker.

        :param plugin_class: :class:`TBPlugin`
        Nplugin_class)r   r?   r   r   r	   r
   b  s    zBasicLoader.__init__c                 C   s
   |  |S r%   r>   r   r   r   r	   r<   i  s    zBasicLoader.loadN)r   r   r   r   r
   r<   r   r   r   r	   r=   _  s   r=   c                   @   s   e Zd ZdZdS )
FlagsErrorz?Raised when a command line flag is not specified or is invalid.N)r   r   r   r   r   r   r   r	   r@   m  s   r@   N)r   abcr   r   r   objectr   r.   r8   r=   
ValueErrorr@   r   r   r   r	   <module>   s   N}A9