pipenv
pipenv copied to clipboard
Fix local file sub-dependencies not being recorded in lockfile
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:
- For local directories, we should use
path(with a relative path) instead offile(with a URL) - The version and index entries should be removed for file/path dependencies
- The editable flag should be preserved
Solution
This fix:
- Differentiates between local directories (use
path) and archive files (usefile) for file:// URLs usingreq.link.is_existing_dir() - Converts file:// URLs to relative paths for local directories using
ensure_path_is_relative() - Removes
versionandindexentries for file/path dependencies - Preserves the
editableflag 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