pipenv icon indicating copy to clipboard operation
pipenv copied to clipboard

Fix local file sub-dependencies not being recorded in lockfile

Open matteius opened this issue 4 weeks ago • 0 comments

Summary

Fixes #6119

Problem

When a package (A) installed from a local path depends on another package (B) also installed from a local path, the sub-dependency (B) was not being properly recorded in Pipfile.lock. The lockfile entry for B would be empty ({}) instead of containing the file/path information.

Expected Result:

"namespace-library": {
    "editable": true,
    "file": "../namespace-library-file"
},
"namespace-utils": {
    "editable": true,
    "file": "../namespace-utils"
}

Actual Result (before fix):

"namespace-library": {
    "editable": true,
    "file": "../namespace-library-file"
},
"namespace-utils": {}

Root Cause

The format_requirement_for_lockfile() function in pipenv/utils/locking.py was setting entry["file"] = req.link.url for all file:// URLs. However:

  1. For local directories, we should use path (with a relative path) instead of file (with a URL)
  2. The version and index entries should be removed for file/path dependencies
  3. The editable flag should be preserved

Solution

This fix:

  • Differentiates between local directories (use path) and archive files (use file) for file:// URLs using req.link.is_existing_dir()
  • Converts file:// URLs to relative paths for local directories using ensure_path_is_relative()
  • Removes version and index entries for file/path dependencies
  • Preserves the editable flag if set on the requirement

Testing

To test this fix, you can use the reproduction repository from the issue:

git clone https://github.com/AlexandreArpin/pipenv-repro
cd pipenv-repro/my-app-file-dep
pipenv lock
cat Pipfile.lock  # namespace-utils should now have path info

Pull Request opened by Augment Code with guidance from the PR author

matteius avatar Dec 10 '25 23:12 matteius