Packaging: Use pip list --format=json for better parsing#1543
Merged
Conversation
According to [the docs](https://pip.pypa.io/en/stable/cli/pip_list/#cmdoption-format), pip list supports a JSON format for output, which is better suited for computer parsing without having to worry about rendering edge cases or building custom parsing logic.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the built-in package refresh flow to use pip list --format=json and switches parsing from custom text parsing to JSON parsing, aiming for more reliable machine-readable output.
Changes:
- Update package listing commands to request JSON output (
--format=json) and parse it via a new JSON parser. - Replace the previous text-based pip list parser with
parsePipListJson()(JSON-based). - Update and expand unit tests to cover JSON parsing plus a couple of edge cases.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/managers/builtin/utils.ts | Switches package refresh to pip list --format=json and uses the JSON parser (also adds uv args for JSON). |
| src/managers/builtin/pipListUtils.ts | Replaces text parsing with JSON parsing (parsePipListJson). |
| src/test/managers/builtin/pipListUtils.unit.test.ts | Updates unit tests to validate JSON parsing and adds edge-case tests. |
| src/test/managers/builtin/piplist1.actual.txt | Removes legacy text output fixture. |
| src/test/managers/builtin/piplist2.actual.txt | Removes legacy text output fixture. |
| src/test/managers/builtin/piplist3.actual.txt | Removes legacy text output fixture. |
Comments suppressed due to low confidence (1)
src/managers/builtin/utils.ts:208
runPython()currently concatenates stdout + stderr into the returned string (see helpers.ts), butpip list --format=jsonneeds the returned data to be valid JSON. Any pip notices/warnings written to stderr (common on success) will corrupt the JSON and makeparsePipListJson()return[], silently hiding packages. Consider changing this call to use a helper that returns stdout only (while still logging stderr), or adjustrunPython()to optionally not append stderr for JSON-producing commands.
try {
return await runPython(
environment.execInfo.run.executable,
['-m', 'pip', 'list', '--format=json'],
undefined,
log,
undefined,
PIP_LIST_TIMEOUT_MS,
);
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
eleanorjboyd
approved these changes
May 27, 2026
roblourens
approved these changes
May 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
According to the docs, pip list supports a JSON format for output, which is better suited for computer parsing without having to worry about rendering edge cases or building custom parsing logic.