Do not include @ when no ref is specified (#5845)

* Do not include @ when no ref is specified
* Handle the @ref from the vcs_url if its in the Pipfile vcs url.
* Also handle an extra ref in the url of the lock file
* Handle case where vcs in Pipfile is just a string
This commit is contained in:
Matt Davis
2023-08-21 21:45:41 -04:00
committed by GitHub
parent 5f405a10a8
commit 48bf4bb9c8
3 changed files with 22 additions and 4 deletions
+1
View File
@@ -0,0 +1 @@
Fix some edge cases around vcs dependencies without a ref, and older Pipfile/lockfile formats.
+14 -3
View File
@@ -959,18 +959,29 @@ def expansive_install_req_from_line(
def install_req_from_pipfile(name, pipfile):
_pipfile = {}
vcs = None
if hasattr(pipfile, "keys"):
_pipfile = dict(pipfile).copy()
else:
vcs = next(iter([vcs for vcs in VCS_LIST if pipfile.startswith(f"{vcs}+")]), None)
if vcs is not None:
_pipfile[vcs] = pipfile
extras = _pipfile.get("extras", [])
extras_str = ""
if extras:
extras_str = f"[{','.join(extras)}]"
vcs = next(iter([vcs for vcs in VCS_LIST if vcs in _pipfile]), None)
if not vcs:
vcs = next(iter([vcs for vcs in VCS_LIST if vcs in _pipfile]), None)
if vcs:
_pipfile["vcs"] = vcs
req_str = f"{_pipfile[vcs]}{_pipfile.get('ref', '')}{extras_str}"
vcs_url = _pipfile[vcs]
fallback_ref = ""
if "@" in vcs_url:
vcs_url_parts = vcs_url.rsplit("@", 1)
vcs_url = vcs_url_parts[0]
fallback_ref = vcs_url_parts[1]
req_str = f"{vcs_url}{_pipfile.get('ref', fallback_ref)}{extras_str}"
if not req_str.startswith(f"{vcs}+"):
req_str = f"{vcs}+{req_str}"
if f"{vcs}+file://" in req_str:
+7 -1
View File
@@ -156,6 +156,12 @@ def requirement_from_lockfile(
if vcs in package_info:
url = package_info[vcs]
ref = package_info.get("ref", "")
if "@" in url:
url_parts = url.rsplit("@", 1)
url = url_parts[0]
if not ref:
ref = url_parts[1]
extras = (
"[{}]".format(",".join(package_info.get("extras", [])))
if "extras" in package_info
@@ -163,7 +169,7 @@ def requirement_from_lockfile(
)
include_vcs = "" if f"{vcs}+" in url else f"{vcs}+"
egg_fragment = "" if "#egg=" in url else f"#egg={package_name}"
ref_str = "" if f"@{ref}" in url else f"@{ref}"
ref_str = "" if not ref or f"@{ref}" in url else f"@{ref}"
if is_editable_path(url) or "file://" in url:
pip_line = f"-e {include_vcs}{url}{ref_str}{egg_fragment}{extras}"
else: