Browse Source

Lazily import url2pathname.

Jelmer Vernooij 2 years ago
parent
commit
8c92769c9a
2 changed files with 11 additions and 3 deletions
  1. 3 0
      NEWS
  2. 8 3
      dulwich/client.py

+ 3 - 0
NEWS

@@ -1,5 +1,8 @@
 0.20.43	UNRELEASED
 
+ * Lazily import url2pathname.
+   (Jelmer Vernooij)
+
  * Drop caching of full HTTP response. Attempt #2.
    (jelmer Vernooij, Antoine Lambert, #966)
 

+ 8 - 3
dulwich/client.py

@@ -56,7 +56,6 @@ from urllib.parse import (
     urlunsplit,
     urlunparse,
 )
-from urllib.request import url2pathname
 
 
 import dulwich
@@ -117,6 +116,10 @@ from dulwich.refs import (
 from dulwich.repo import Repo
 
 
+# url2pathname is lazily imported
+url2pathname = None
+
+
 logger = logging.getLogger(__name__)
 
 
@@ -2237,8 +2240,7 @@ HttpGitClient = Urllib3HttpGitClient
 
 
 def _win32_url_to_path(parsed) -> str:
-    """
-    Convert a file: URL to a path.
+    """Convert a file: URL to a path.
 
     https://datatracker.ietf.org/doc/html/rfc8089
     """
@@ -2260,6 +2262,9 @@ def _win32_url_to_path(parsed) -> str:
     else:
         raise NotImplementedError("Non-local file URLs are not supported")
 
+    global url2pathname
+    if url2pathname is None:
+        from urllib.request import url2pathname
     return url2pathname(netloc + path)