Factor out editable parsing into a function
@@ -28,7 +28,6 @@ from pip._internal.req.req_install import InstallRequirement
from pip._internal.utils.filetypes import ARCHIVE_EXTENSIONS
from pip._internal.utils.misc import is_installable_dir, path_to_url, splitext
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
-from pip._internal.utils.urls import url_to_path
from pip._internal.vcs import is_url, vcs
from pip._internal.wheel import Wheel
@@ -179,6 +178,23 @@ def deduce_helpful_msg(req):
return msg
+def parse_req_from_editable(editable_req):
+ # type: (str) -> RequirementParts
+ name, url, extras_override = parse_editable(editable_req)
+
+ if name is not None:
+ try:
+ req = Requirement(name)
+ except InvalidRequirement:
+ raise InstallationError("Invalid requirement: '%s'" % name)
+ else:
+ req = None
+
+ link = Link(url)
+
+ return RequirementParts(req, link, None, extras_override)
+
+
# ---- The actual constructors follow ----
@@ -192,23 +208,8 @@ def install_req_from_editable(
constraint=False # type: bool
):
# type: (...) -> InstallRequirement
- name, url, extras_override = parse_editable(editable_req)
- if url.startswith('file:'):
- source_dir = url_to_path(url)
- else:
- source_dir = None
-
- if name is not None:
- try:
- req = Requirement(name)
- except InvalidRequirement:
- raise InstallationError("Invalid requirement: '%s'" % name)
- else:
- req = None
-
- link = Link(url)
- parts = RequirementParts(req, link, None, extras_override)
+ parts = parse_req_from_editable(editable_req)
source_dir = parts.link.file_path if parts.link.scheme == 'file' else None
