question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Evolving the pip list json output

See original GitHub issue

Currently, pip list --format=json produces a json array.

I think it could be valuable for pip list to output additional information, such as an environment object with PEP 608 environment markers, etc. Such a change would require the pip list output to evolve in a backward incompatible way, in this case because of the current array output that would need to be converted to an object.

It is to be noted that such back-ward incompatible changes will probably be very infrequent, since we’ll presumably only want to add new information to the output. An example of backward compatible change is https://github.com/pypa/pip/pull/11097 which adds a metadata property to the list items.

How should such backward-incompatible changes be addressed ?

  • with a new format option such as --format=json+v2 ?
  • with a new commend such as pip inspect ?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
uranusjrcommented, Jul 4, 2022

I don’t like json+v2 since it implies we’ll lose the prettier json key forever. Perhaps --use-feature=list-json-2022 is a better way to transition?

Introduing pip inspect is a good idea if it can have more use cases, but I can’t think of any right now.

0reactions
pfmoorecommented, Jul 9, 2022

I hope we reach that goal one day too.

Actually, it occurred to me that we may even be able to do this right now. I put together a very simple proof of concept and it seems to work. If you put the following script alongside a “lib” directory with pip installed into it (pip install pip --target lib) but with the bin and pip*.dist-info directory removed (so the bundled pip isn’t visible in pip list) then it can be run from any Python interpreter to effectively act as a copy of pip in that environment.

#!/usr/bin/env python

import runpy
import sys
import os

lib = os.path.join(os.path.dirname(__file__), "lib")
sys.path.insert(0, lib)

runpy.run_module("pip", run_name="__main__")

I don’t think it would take much to turn this into a viable “standalone pip” application (I’d mostly just want to set up an executable wrapper for Windows). I’ve done some very basic testing - this would need a lot more real-world testing to make sure there aren’t any problem edge cases, but it basically seems to work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pip inspect JSON output specification
The pip inspect command produces a detailed JSON report of the Python environment, including installed distributions.
Read more >
JSON output sorting in Python - Stack Overflow
Try OrderedDict from the standard library collections : >>> import json >>> from collections import OrderedDict >>> values ...
Read more >
Pandas - Convert JSON to CSV - Spark by {Examples}
Install Pandas. If you don't have pandas on your system, install python pandas by using the pip command. skip this step. If you...
Read more >
django-admin and manage.py
Run django-admin help --commands to display a list of all available commands. ... For example, to output the data as a compressed JSON...
Read more >
json2html - PyPI
Convert now accepts unicode and bytestrings for the keyword argument “json”. Output now should always appear in the same order as input. Now...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found