Voice et bot modif

This commit is contained in:
pi 2026-06-16 17:09:34 +00:00
parent 189d56026b
commit 7333a22bcd
10774 changed files with 634644 additions and 933308 deletions

View file

@ -1,13 +1,12 @@
"""Cache Management"""
from __future__ import annotations
"""Cache Management
"""
import hashlib
import json
import logging
import os
from pathlib import Path
from typing import Any
from typing import Any, Dict, List, Optional
from pip._vendor.packaging.tags import Tag, interpreter_name, interpreter_version
from pip._vendor.packaging.utils import canonicalize_name
@ -24,7 +23,7 @@ logger = logging.getLogger(__name__)
ORIGIN_JSON_NAME = "origin.json"
def _hash_dict(d: dict[str, str]) -> str:
def _hash_dict(d: Dict[str, str]) -> str:
"""Return a stable sha224 of a dictionary."""
s = json.dumps(d, sort_keys=True, separators=(",", ":"), ensure_ascii=True)
return hashlib.sha224(s.encode("ascii")).hexdigest()
@ -41,11 +40,11 @@ class Cache:
assert not cache_dir or os.path.isabs(cache_dir)
self.cache_dir = cache_dir or None
def _get_cache_path_parts(self, link: Link) -> list[str]:
def _get_cache_path_parts(self, link: Link) -> List[str]:
"""Get parts of part that must be os.path.joined with cache_dir"""
# We want to generate an url to use as our cache key, we don't want to
# just reuse the URL because it might have other items in the fragment
# just re-use the URL because it might have other items in the fragment
# and we don't care about those.
key_parts = {"url": link.url_without_fragment}
if link.hash_name is not None and link.hash is not None:
@ -74,7 +73,7 @@ class Cache:
return parts
def _get_candidates(self, link: Link, canonical_package_name: str) -> list[Any]:
def _get_candidates(self, link: Link, canonical_package_name: str) -> List[Any]:
can_not_cache = not self.cache_dir or not canonical_package_name or not link
if can_not_cache:
return []
@ -91,8 +90,8 @@ class Cache:
def get(
self,
link: Link,
package_name: str | None,
supported_tags: list[Tag],
package_name: Optional[str],
supported_tags: List[Tag],
) -> Link:
"""Returns a link to a cached item if it exists, otherwise returns the
passed link.
@ -129,8 +128,8 @@ class SimpleWheelCache(Cache):
def get(
self,
link: Link,
package_name: str | None,
supported_tags: list[Tag],
package_name: Optional[str],
supported_tags: List[Tag],
) -> Link:
candidates = []
@ -143,7 +142,7 @@ class SimpleWheelCache(Cache):
wheel = Wheel(wheel_name)
except InvalidWheelFilename:
continue
if wheel.name != canonical_package_name:
if canonicalize_name(wheel.name) != canonical_package_name:
logger.debug(
"Ignoring cached wheel %s for %s as it "
"does not match the expected distribution name %s.",
@ -190,7 +189,7 @@ class CacheEntry:
):
self.link = link
self.persistent = persistent
self.origin: DirectUrl | None = None
self.origin: Optional[DirectUrl] = None
origin_direct_url_path = Path(self.link.file_path).parent / ORIGIN_JSON_NAME
if origin_direct_url_path.exists():
try:
@ -227,8 +226,8 @@ class WheelCache(Cache):
def get(
self,
link: Link,
package_name: str | None,
supported_tags: list[Tag],
package_name: Optional[str],
supported_tags: List[Tag],
) -> Link:
cache_entry = self.get_cache_entry(link, package_name, supported_tags)
if cache_entry is None:
@ -238,9 +237,9 @@ class WheelCache(Cache):
def get_cache_entry(
self,
link: Link,
package_name: str | None,
supported_tags: list[Tag],
) -> CacheEntry | None:
package_name: Optional[str],
supported_tags: List[Tag],
) -> Optional[CacheEntry]:
"""Returns a CacheEntry with a link to a cached item if it exists or
None. The cache entry indicates if the item was found in the persistent
or ephemeral cache.