-
Notifications
You must be signed in to change notification settings - Fork 481
pipx list json format #660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'll add tests for this if everybody think the approach is good. |
Looks like everybody is busy 😉 @cs01, does this seem like a basically good idea? Any thoughts? |
Sorry. Yes this looks good. Thanks for adding this. I have been thinking about it for a long time but never did it. You made it happen though 👍 |
This is awesome! ♥ Unfortunately there's a little issue still: initially, when nothing is installed, |
Dang it :( . OK, need to fix that...thanks for reporting! |
This is great! I took a rough pass at defining a JSON Schema for this metadata (note the hypothetical URL for the Such a schema could be hosted on the Pipx website, and/or provided with the Pipx application itself. You could use it internally for your test suite, as well as to allow other tools to develop against or reuse the Pipx JSON format with confidence. Also for the TOML and YAML lovers out there, you can convert between formats with: pipx list --json | python -c 'import sys,json,yaml; yaml.dump(json.load(sys.stdin), sys.stdout)' > pipx.toml
python -c 'import sys,json,yaml; print(json.dumps(yaml.safe_load(sys.stdin), indent=2))' < pipx.toml
pipx list --json | python -c 'import sys,json,toml; toml.dump(json.load(sys.stdin), sys.stdout)' > pipx.toml
python -c 'import sys,json,toml; print(json.dumps(toml.load(sys.stdin), indent=2))' < pipx.toml You can even add it to a Makefile if you wanted: pipx.json:
pipx list --json > $@
pipx.toml: pipx.json
python -c 'import sys,json,toml; toml.dump(json.load(sys.stdin), sys.stdout)' < $^ > $@
pipx.yaml: pipx.json
python -c 'import sys,json,yaml; yaml.dump(json.load(sys.stdin), sys.stdout)' < $^ > $@
# Other targets can now depend on pipx.json, pipx.toml, and/or pipx.yaml Note that there could be problems round-tripping with TOML, since the JSON format is a bit more complicated than what you'd usually write in a TOML file. |
docs/changelog.md
Summary of changes
The main purpose of this is to address the following issues: #627 , #390 , #109 . It adds a
--json
switch topipx list
which directspipx list
to output rich information about all the venvs in json format. The output is suitable to be directed to a file, e.g.pipx list --json > pipx.json
.The implementation basically dumps the contents of every venv's pipx_metadata.json file into an object that is then dumped into the output. As such, there is probably more information than is strictly necessary to reinstall these packages.
The json produced follows the following structure:
Here is an example of a sample pipx listing, both with
--json
and without, for pipx-installedpycowsay
, andblack
with injectedpylint
:Additionally I factored out the code that checks for venv problems into
venv_health_check()
.Test plan
Tested by running