Skip to content

Commit

Permalink
Better handling of local file install edge cases; handle local file e…
Browse files Browse the repository at this point in the history
…xtras (#5919)

* Better handling of local file install edge cases; handle local file extras
* more logical fix that handles more edge cases, including editable or not.
* Handle extras for file installs
  • Loading branch information
matteius committed Sep 7, 2023
1 parent 5df6d9c commit 91743a6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/5919.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Better handling of local file install edge cases; handle local file extras.
32 changes: 30 additions & 2 deletions pipenv/utils/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,33 @@ def expansive_install_req_from_line(
)


def _file_path_from_pipfile(path_obj, pipfile_entry):
"""Creates an installable file path from a pipfile entry.
Handles local and remote paths, files and directories;
supports extras and editable specification.
Outputs a pip installable line.
"""
parsed_url = urlparse(str(path_obj))
if parsed_url.scheme in ["http", "https", "ftp", "file"]:
req_str = str(path_obj)
elif path_obj.is_absolute():
req_str = str(path_obj.as_posix())
else:
req_str = f"./{str(path_obj.as_posix())}"

if pipfile_entry.get("extras"):
req_str = f"{req_str}[{','.join(pipfile_entry['extras'])}]"
if pipfile_entry.get("editable", False):
req_str = f"-e {req_str}"

return req_str


def install_req_from_pipfile(name, pipfile):
"""Creates an InstallRequirement from a name and a pipfile entry.
Handles VCS, local & remote paths, and regular named requirements.
"file" and "path" entries are treated the same.
"""
_pipfile = {}
vcs = None
if hasattr(pipfile, "keys"):
Expand Down Expand Up @@ -1028,9 +1054,11 @@ def install_req_from_pipfile(name, pipfile):
else:
req_str = f"{name}{extras_str}@ {req_str}{subdirectory}"
elif "path" in _pipfile:
req_str = str(Path(_pipfile["path"]).as_posix())
path_obj = Path(_pipfile["path"])
req_str = _file_path_from_pipfile(path_obj, _pipfile)
elif "file" in _pipfile:
req_str = str(Path(_pipfile["file"]).as_posix())
path_obj = Path(_pipfile["file"])
req_str = _file_path_from_pipfile(path_obj, _pipfile)
else:
# We ensure version contains an operator. Default to equals (==)
_pipfile["version"] = version = get_version(pipfile)
Expand Down

0 comments on commit 91743a6

Please sign in to comment.