This commit is contained in:
Damian Shaw 2023-11-29 21:42:56 +08:00 committed by GitHub
commit 9159512bf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

1
news/12322.bugfix.rst Normal file
View File

@ -0,0 +1 @@
Improve performance ~17% when installing many wheels offline

View File

@ -2,6 +2,7 @@ import os
import string
import urllib.parse
import urllib.request
from functools import lru_cache
from typing import Optional
from .compat import WINDOWS
@ -13,13 +14,22 @@ def get_url_scheme(url: str) -> Optional[str]:
return url.split(":", 1)[0].lower()
@lru_cache(maxsize=None)
def _normalized_abs_path_to_url(abs_path: str) -> str:
"""
Convert a normalized absolute path to a file: URL.
"""
url = urllib.parse.urljoin("file:", urllib.request.pathname2url(abs_path))
return url
def path_to_url(path: str) -> str:
"""
Convert a path to a file: URL. The path will be made absolute and have
quoted path parts.
"""
path = os.path.normpath(os.path.abspath(path))
url = urllib.parse.urljoin("file:", urllib.request.pathname2url(path))
url = _normalized_abs_path_to_url(path)
return url