Skip to content

Commit

Permalink
Do not include @ when no ref is specified (#5845)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
matteius authored Aug 22, 2023
1 parent 5f405a1 commit 48bf4bb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/5843.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix some edge cases around vcs dependencies without a ref, and older Pipfile/lockfile formats.
17 changes: 14 additions & 3 deletions pipenv/utils/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion pipenv/utils/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,20 @@ 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
else ""
)
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:
Expand Down

0 comments on commit 48bf4bb

Please sign in to comment.