
    ~+h                        d Z ddlmZ ddlmZ ddlmZ ddlmZmZ ddl	m
Z
mZmZ dZ e       Z	  G d d	 ej                    e
d
 dd                  Zej$                  Z G d de      Z G d de      Z G d de      Zy)a  The auto-rebuild system is an optional part of webassets that can be used
during development, and can also be quite convenient on small sites that don't
have the performance requirements where a rebuild-check on every request is
fatal.

This module contains classes that help determine whether a rebuild is required
for a bundle. This is more complicated than simply comparing the timestamps of
the source and output files.

First, certain filters, in particular CSS compilers like SASS, allow bundle
source files to reference additional files which the user may not have listed
in the bundle definition. The bundles support an additional ``depends``
argument that can list files that should be watched for modification.

Second, if the bundle definition itself changes, i.e., source files being added
or removed, or the list of applied filters modified, the bundle needs to be
rebuilt also. Since there is no single fixed place where bundles are defined,
simply watching the timestamp of that bundle definition file is not good enough.

To solve the latter problem, we employ an environment-specific cache of bundle
definitions.

Note that there is no ``HashUpdater``. This doesn't make sense for two reasons.
First, for a live system, it isn't fast enough. Second, for prebuilding assets,
the cache is a superior solution for getting essentially the same speed
increase as using the hash to reliably determine which bundles to skip.
    )six)map)zip)BundleError
BuildError)RegistryMetaclassis_url	hash_func)get_updater
SKIP_CACHETimestampUpdaterAlwaysUpdaterc                       e Zd ZdZd Zd Zy)BaseUpdaterzBase updater class.

    Child classes that define an ``id`` attribute are accessible via their
    string id in the configuration.

    A single instance can be used with different environments.
    c                     t               )z_Returns ``True`` if the given bundle needs to be rebuilt,
        ``False`` otherwise.
        )NotImplementedErrorselfbundlectxs      D/var/www/html/venv/lib/python3.12/site-packages/webassets/updater.pyneeds_rebuildzBaseUpdater.needs_rebuild>   s     "##    c                      y)zGThis will be called once a bundle has been successfully built.
        N r   s      r   
build_donezBaseUpdater.build_doneD   s    r   N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   3   s    $r   r   c                      t         S N)r   r   r   r   <lambda>r#   4   s    + r   r   zan updater implementation)clazz	attributedescc                   "    e Zd ZdZd Zd Zd Zy)BundleDefUpdaterztSupports the bundle definition cache update check that child
    classes are usually going to want to use also.
    c                     |j                   syd|j                  f}dt        |      z  }|j                   j                  |      }|||k7  S yNFbdefz%s)cacheoutputr
   get)r   r   r   	cache_keycurrent_hashcached_hashs         r   check_bundle_definitionz(BundleDefUpdater.check_bundle_definitionQ   sS    yy V]]+	i//iimmI.
 ",..r   c                 &    | j                  ||      S r"   )r2   r   s      r   r   zBundleDefUpdater.needs_rebuildf   s    ++FC88r   c                     |j                   syd|j                  f}dt        |      z  }|j                   j                  ||       y r*   )r,   r-   r
   set)r   r   r   r/   cache_values        r   r   zBundleDefUpdater.build_donei   s;    yyV]]+	Yv..		i-r   N)r   r   r   r    r2   r   r   r   r   r   r(   r(   L   s    *9.r   r(   c                   4     e Zd ZdZddZ fdZ fdZ xZS )r   	timestampc           	      6   ddl m} ddlm} |s$	 j	                  |      }	 |j                  |      }ddlm} fd	dfj                  t        ffD ]j  \  }}	 ||      D ]Z  }
t        |
|      r#| j!                  |
 |||
      |      }|s,|c c S t#        |
      r>	 |j                  |
      }||kD  sV|	c c S  l y
# t
        $ r* |j                  t        d|j                  d      Y yw xY w# t        $ r Y yw xY w# t        $ r	 |	cY c c S w xY w)N   )Bundler   )TimestampVersionz0 uses a version placeholder, and you are using "z[" versions. To use automatic building in this configuration, you need to define a manifest.T)wrapc                 <    t        d j                  |             S )Nc                     | d   S )Nr:   r   )ss    r   r#   zETimestampUpdater.check_timestamps.<locals>.<lambda>.<locals>.<lambda>   s
    QqT r   )r   resolve_contents)er   s    r   r#   z3TimestampUpdater.check_timestamps.<locals>.<lambda>   s    s>6+B+B1+EF r   F)r   r;   webassets.versionr<   resolve_outputr   manifestr   versionsget_timestampOSErrorwebassets.bundler=   resolve_dependsr   
isinstancecheck_timestampsr	   )r   r   r   
o_modifiedr;   r<   resolved_outputr=   iteratorresultitemnested_result
s_modifieds    `           r   rL   z!TimestampUpdater.check_timestampsu   sG   "6"("7"7"<"-;;OL
 	*FM##Z0!
 	*Hf ! *dF+$($9$9$S$Q[$\M$,,*%5%C%CD%I
 &
2#)M*		*& [   <<'$ 17FH H
 $  ( # &  &&s4   C C7  D0C43C47	DDDDc                 T    t         t        |   ||      xs | j                  ||      S r"   )superr   r   rL   r   r   r   	__class__s      r   r   zTimestampUpdater.needs_rebuild   s/    "D7D /!!&#.	/r   c                 <    d |_         t        t        |   ||       y r"   )_resolved_dependsrU   r   r   rV   s      r   r   zTimestampUpdater.build_done   s     $( 0=r   r"   )r   r   r   idrL   r   r   __classcell__)rW   s   @r   r   r   q   s    	B4l/
> >r   r   c                       e Zd ZdZd Zy)r   alwaysc                      y)NTr   r   s      r   r   zAlwaysUpdater.needs_rebuild   s    r   N)r   r   r   rZ   r   r   r   r   r   r      s    	Br   r   N)r    	webassetsr   webassets.six.movesr   r   webassets.exceptionsr   r   webassets.utilsr   r	   r
   __all__objectr   with_metaclassr   resolver   r(   r   r   r   r   r   <module>rg      s   8  # # 8 @ @1 X
$#$$%6
	$&& ' , !!".{ ".JF>' F>RK r   