From 325846b26a034fad34b71339b13ad5ab987f7b38 Mon Sep 17 00:00:00 2001 From: Parag Ekbote Date: Thu, 26 Mar 2026 06:08:19 +0000 Subject: [PATCH 1/3] update path handling of cache to fix smash config crash. --- src/pruna/config/smash_config.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pruna/config/smash_config.py b/src/pruna/config/smash_config.py index 00a9865a..28755685 100644 --- a/src/pruna/config/smash_config.py +++ b/src/pruna/config/smash_config.py @@ -84,7 +84,7 @@ def __init__( self.cache_dir_prefix = Path(cache_dir_prefix) if not self.cache_dir_prefix.exists(): self.cache_dir_prefix.mkdir(parents=True, exist_ok=True) - self.cache_dir = Path(tempfile.mkdtemp(dir=cache_dir_prefix)) + self.cache_dir = Path(tempfile.mkdtemp(dir=self.cache_dir_prefix)) self.save_fns: list[str] = [] self.load_fns: list[str] = [] @@ -217,8 +217,12 @@ def __eq__(self, other: Any) -> bool: def cleanup_cache_dir(self) -> None: """Clean up the cache directory.""" - if self.cache_dir.exists(): - shutil.rmtree(self.cache_dir) + try: + if hasattr(self, "cache_dir") and self.cache_dir is not None: + if isinstance(self.cache_dir, Path) and self.cache_dir.exists(): + shutil.rmtree(self.cache_dir, ignore_errors=True) + except Exception: + pass def reset_cache_dir(self) -> None: """Reset the cache directory.""" From 4020fcef4fc50dda7753293326adf62f81c30e36 Mon Sep 17 00:00:00 2001 From: Parag Ekbote Date: Thu, 26 Mar 2026 06:35:27 +0000 Subject: [PATCH 2/3] update to fix linting errors. --- src/pruna/config/smash_config.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pruna/config/smash_config.py b/src/pruna/config/smash_config.py index 28755685..26608606 100644 --- a/src/pruna/config/smash_config.py +++ b/src/pruna/config/smash_config.py @@ -218,9 +218,13 @@ def __eq__(self, other: Any) -> bool: def cleanup_cache_dir(self) -> None: """Clean up the cache directory.""" try: - if hasattr(self, "cache_dir") and self.cache_dir is not None: - if isinstance(self.cache_dir, Path) and self.cache_dir.exists(): - shutil.rmtree(self.cache_dir, ignore_errors=True) + if ( + hasattr(self, "cache_dir") + and self.cache_dir is not None + and isinstance(self.cache_dir, Path) + and self.cache_dir.exists() + ): + shutil.rmtree(self.cache_dir, ignore_errors=True) except Exception: pass From 09933a2c6fe5586588746ab2790b328c43421bd2 Mon Sep 17 00:00:00 2001 From: Parag Ekbote Date: Wed, 1 Apr 2026 14:08:02 +0000 Subject: [PATCH 3/3] update to make self.cache_dir handle more types and more robust --- src/pruna/config/smash_config.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/pruna/config/smash_config.py b/src/pruna/config/smash_config.py index 26608606..0acc1e12 100644 --- a/src/pruna/config/smash_config.py +++ b/src/pruna/config/smash_config.py @@ -217,16 +217,14 @@ def __eq__(self, other: Any) -> bool: def cleanup_cache_dir(self) -> None: """Clean up the cache directory.""" - try: - if ( - hasattr(self, "cache_dir") - and self.cache_dir is not None - and isinstance(self.cache_dir, Path) - and self.cache_dir.exists() - ): - shutil.rmtree(self.cache_dir, ignore_errors=True) - except Exception: - pass + if hasattr(self, "cache_dir") and self.cache_dir is not None: + cache_path = Path(self.cache_dir) + + if not isinstance(cache_path, Path): + raise TypeError(f"cache_dir must be path-like, got {type(self.cache_dir)}") + + if cache_path.exists() and cache_path.is_dir(): + shutil.rmtree(cache_path, ignore_errors=True) def reset_cache_dir(self) -> None: """Reset the cache directory."""