|
| 1 | +from __future__ import annotations |
| 2 | + |
1 | 3 | import logging |
2 | 4 | import os |
3 | 5 | import shutil |
4 | 6 | import time |
5 | 7 | import urllib.parse |
6 | 8 | from pathlib import Path |
| 9 | +from typing import Iterator |
7 | 10 |
|
8 | 11 | import humanize |
9 | 12 | from fsspec import register_implementation |
|
20 | 23 | PLACEHOLDER_FILE = "file" |
21 | 24 |
|
22 | 25 |
|
23 | | -def touch_access_time(path, access_time: "float | None" = None, strict=True): |
| 26 | +def touch_access_time(path, access_time: float | None = None, strict=True): |
24 | 27 | """Update access time of file. |
25 | 28 |
|
26 | 29 | Returns the new access time. |
@@ -220,15 +223,15 @@ class CachePruner: |
220 | 223 |
|
221 | 224 | meta_path = "data.txt" |
222 | 225 |
|
223 | | - def __init__(self, cache_dir: "str | Path"): |
| 226 | + def __init__(self, cache_dir: str | Path): |
224 | 227 | self.cache_dir = Path(cache_dir) |
225 | 228 |
|
226 | | - def versions(self) -> "iter[Path]": |
| 229 | + def versions(self) -> Iterator[Path]: |
227 | 230 | for p_version in self.cache_dir.glob("*/*"): |
228 | 231 | if p_version.is_dir() and (p_version / self.meta_path).exists(): |
229 | 232 | yield p_version |
230 | 233 |
|
231 | | - def should_prune_version(self, days, path: "str | Path"): |
| 234 | + def should_prune_version(self, days, path: str | Path): |
232 | 235 | path = Path(path) |
233 | 236 |
|
234 | 237 | expiry_time_sec = days * 60 * 60 * 24 |
@@ -258,7 +261,7 @@ def prune(self, days=30): |
258 | 261 | _log.info("Skipping cache deletion") |
259 | 262 |
|
260 | 263 |
|
261 | | -def delete_version(path: "str | Path"): |
| 264 | +def delete_version(path: str | Path): |
262 | 265 | path = Path(path) |
263 | 266 | shutil.rmtree(str(path.absolute())) |
264 | 267 |
|
|
0 commit comments