From 967607db1dc981fafdc352bcadaf7b34ceaf7520 Mon Sep 17 00:00:00 2001 From: Damian Shaw Date: Fri, 6 Oct 2023 12:35:32 -0400 Subject: [PATCH 1/5] Cache call to path_to_url --- src/pip/_internal/utils/urls.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pip/_internal/utils/urls.py b/src/pip/_internal/utils/urls.py index 6ba2e04f350..08a536b78f0 100644 --- a/src/pip/_internal/utils/urls.py +++ b/src/pip/_internal/utils/urls.py @@ -2,6 +2,7 @@ import string import urllib.parse import urllib.request +from functools import lru_cache from typing import Optional from .compat import WINDOWS @@ -13,6 +14,7 @@ def get_url_scheme(url: str) -> Optional[str]: return url.split(":", 1)[0].lower() +@lru_cache(maxsize=None) def path_to_url(path: str) -> str: """ Convert a path to a file: URL. The path will be made absolute and have From d1db13f060587c71cdd5bda81186ea57f32a2bf4 Mon Sep 17 00:00:00 2001 From: Damian Shaw Date: Fri, 6 Oct 2023 12:44:30 -0400 Subject: [PATCH 2/5] Add news entry --- news/12322.bugfix.rest | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/12322.bugfix.rest diff --git a/news/12322.bugfix.rest b/news/12322.bugfix.rest new file mode 100644 index 00000000000..e315a9279ad --- /dev/null +++ b/news/12322.bugfix.rest @@ -0,0 +1 @@ +Improve performance ~20% when installing many wheels offline \ No newline at end of file From 7beea44e2d5b4de7b9430cea310eb12b4d647d61 Mon Sep 17 00:00:00 2001 From: Damian Shaw Date: Fri, 6 Oct 2023 13:00:38 -0400 Subject: [PATCH 3/5] Can only cache after making absolute --- src/pip/_internal/utils/urls.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pip/_internal/utils/urls.py b/src/pip/_internal/utils/urls.py index 08a536b78f0..0cbe8ea96e9 100644 --- a/src/pip/_internal/utils/urls.py +++ b/src/pip/_internal/utils/urls.py @@ -15,13 +15,21 @@ def get_url_scheme(url: str) -> Optional[str]: @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 From 8466261b94a6c8a758daf64b640b4dde5a49d61f Mon Sep 17 00:00:00 2001 From: Damian Shaw Date: Fri, 6 Oct 2023 13:14:17 -0400 Subject: [PATCH 4/5] Fix news entry --- news/12322.bugfix.rest | 1 - news/12322.bugfix.rst | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 news/12322.bugfix.rest create mode 100644 news/12322.bugfix.rst diff --git a/news/12322.bugfix.rest b/news/12322.bugfix.rest deleted file mode 100644 index e315a9279ad..00000000000 --- a/news/12322.bugfix.rest +++ /dev/null @@ -1 +0,0 @@ -Improve performance ~20% when installing many wheels offline \ No newline at end of file diff --git a/news/12322.bugfix.rst b/news/12322.bugfix.rst new file mode 100644 index 00000000000..bb2e69da7f3 --- /dev/null +++ b/news/12322.bugfix.rst @@ -0,0 +1 @@ +Improve performance ~17% when installing many wheels offline \ No newline at end of file From 560478fd72a6a2d47ab8fe1d04eb9fac41b5ed3a Mon Sep 17 00:00:00 2001 From: Damian Shaw Date: Fri, 6 Oct 2023 13:16:55 -0400 Subject: [PATCH 5/5] End of line on news --- news/12322.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/12322.bugfix.rst b/news/12322.bugfix.rst index bb2e69da7f3..928df878978 100644 --- a/news/12322.bugfix.rst +++ b/news/12322.bugfix.rst @@ -1 +1 @@ -Improve performance ~17% when installing many wheels offline \ No newline at end of file +Improve performance ~17% when installing many wheels offline