@@ -77,6 +77,7 @@ def prepare_cache_tags(i):
7777 cached_tags .append (x )
7878
7979 explicit_cached_tags = cached_tags .copy ()
80+ explicit_cached_tags .append ("-tmp" )
8081
8182 # explicit variations
8283 if len (i ['explicit_variation_tags' ]) > 0 :
@@ -161,12 +162,15 @@ def search_cache(i, explicit_cached_tags):
161162 i ['logger' ].debug (
162163 i ['recursion_spaces' ] +
163164 ' - Pruning cache list outputs with the following tags: {}' .format (explicit_cached_tags ))
164-
165165 cache_list = i ['cache_list' ]
166+
167+ n_tags = [p [1 :] for p in explicit_cached_tags if p .startswith ("-" )]
168+ p_tags = [p for p in explicit_cached_tags if not p .startswith ("-" )]
169+
166170 pruned_cache_list = [
167171 item
168172 for item in cache_list
169- if set (explicit_cached_tags ) <= set (item .meta .get ('tags' , []))
173+ if set (p_tags ) <= set (item .meta .get ('tags' , [])) and set ( n_tags ). isdisjoint ( set ( item . meta . get ( 'tags' , []) ))
170174 ]
171175
172176 return pruned_cache_list
@@ -214,9 +218,19 @@ def validate_cached_scripts(i, found_cached_scripts):
214218 '''
215219 valid = []
216220 if len (found_cached_scripts ) > 0 :
221+
222+ # We can consider doing quiet here if noise is too much
223+ # import logging
224+ # logger = i['logger']
225+ # logger_level_saved = logger.level
226+ # logger.setLevel(logging.ERROR)
227+ # saved_quiet = i['env'].get('MLC_QUIET', False)
228+ # i['env']['MLC_QUIET'] = True
217229 for cached_script in found_cached_scripts :
218230 if is_cached_entry_valid (i , cached_script ):
219231 valid .append (cached_script )
232+ # logger.setLevel(logger_level_saved)
233+ # i['env']['MLC_QUIET'] = saved_quiet
220234
221235 return valid
222236
@@ -417,9 +431,7 @@ def find_cached_script(i):
417431 i , explicit_cached_tags , found_cached_scripts )
418432 found_cached_scripts = validate_cached_scripts (i , found_cached_scripts )
419433
420- search_tags = '-tmp'
421- if len (explicit_cached_tags ) > 0 :
422- search_tags += ',' + ',' .join (explicit_cached_tags )
434+ search_tags = ',' .join (explicit_cached_tags )
423435
424436 return {'return' : 0 , 'cached_tags' : cached_tags ,
425437 'search_tags' : search_tags , 'found_cached_scripts' : found_cached_scripts }
@@ -430,40 +442,52 @@ def find_cached_script(i):
430442
431443def fix_cache_paths (cached_path , env ):
432444
433- current_cache_path = cached_path
445+ current_cache_path = os . path . normpath ( cached_path )
434446
435447 new_env = env # just a reference
436448
449+ def normalize_and_replace_path (path_str ):
450+ """Helper to normalize and replace cache paths in a string."""
451+ # Normalize the path to use the current OS separators
452+ normalized = os .path .normpath (path_str )
453+
454+ # Check if path contains local/cache or local\cache pattern
455+ path_parts = normalized .split (os .sep )
456+
457+ try :
458+ local_idx = path_parts .index ("local" )
459+ if local_idx + \
460+ 1 < len (path_parts ) and path_parts [local_idx + 1 ] == "cache" :
461+ # Extract the loaded cache path (up to and including "cache")
462+ loaded_cache_path = os .sep .join (path_parts [:local_idx + 2 ])
463+ loaded_cache_path_norm = os .path .normpath (loaded_cache_path )
464+
465+ if loaded_cache_path_norm != current_cache_path and os .path .exists (
466+ current_cache_path ):
467+ # Replace old cache path with current cache path
468+ return normalized .replace (
469+ loaded_cache_path_norm , current_cache_path )
470+ except (ValueError , IndexError ):
471+ # "local" not in path or malformed path
472+ pass
473+
474+ return normalized
475+
437476 for key , val in new_env .items ():
438- # Check for a path separator in a string and determine the
439- # separator
440- if isinstance (val , str ) and any (sep in val for sep in [
441- "/local/cache/" , "\\ local\\ cache\\ " ]):
442- sep = "/" if "/local/cache/" in val else "\\ "
443-
444- path_split = val .split (sep )
445- repo_entry_index = path_split .index ("local" )
446- loaded_cache_path = sep .join (
447- path_split [0 :repo_entry_index + 2 ])
448- if loaded_cache_path != current_cache_path and os .path .exists (
449- current_cache_path ):
450- new_env [key ] = val .replace (
451- loaded_cache_path , current_cache_path ).replace (sep , "/" )
477+ if isinstance (val , str ):
478+ # Check if path contains cache directory pattern
479+ normalized_val = val .replace ('\\ ' , os .sep ).replace ('/' , os .sep )
480+ if os .sep .join (['local' , 'cache' ]) in normalized_val :
481+ new_env [key ] = normalize_and_replace_path (val )
452482
453483 elif isinstance (val , list ):
454484 for i , val2 in enumerate (val ):
455- if isinstance (val2 , str ) and any (sep in val2 for sep in [
456- "/local/cache/" , "\\ local\\ cache\\ " ]):
457- sep = "/" if "/local/cache/" in val2 else "\\ "
458-
459- path_split = val2 .split (sep )
460- repo_entry_index = path_split .index ("local" )
461- loaded_cache_path = sep .join (
462- path_split [0 :repo_entry_index + 2 ])
463- if loaded_cache_path != current_cache_path and os .path .exists (
464- current_cache_path ):
465- new_env [key ][i ] = val2 .replace (
466- loaded_cache_path , current_cache_path ).replace (sep , "/" )
485+ if isinstance (val2 , str ):
486+ # Check if path contains cache directory pattern
487+ normalized_val2 = val2 .replace (
488+ '\\ ' , os .sep ).replace ('/' , os .sep )
489+ if os .sep .join (['local' , 'cache' ]) in normalized_val2 :
490+ new_env [key ][i ] = normalize_and_replace_path (val2 )
467491
468492 return {'return' : 0 , 'new_env' : new_env }
469493
0 commit comments