pipx
pipx copied to clipboard
Support provisioning of pipx-managed sites from the output of `pipx list --json`.
How would this feature be useful?
With the completion of #660 , the possibility now exists to re-create one or more pipx-managed environments based on the output of pipx list --json.
This would be useful for backup or versioning across one or more machines. For instance, I could use the output of pipx list --json from workstation A to quickly provision workstation B or laptop C with a same/very similar set of tools.
Describe the solution you'd like
I don't have firm opinions on the API here, but i would kind of naively expect pipx install-all my-pipx-list.json, which creates the new subcommand install-all, with name parity with existing -all sub-command equivalents.
Tricky points I can think of:
- what if workstation B has a different version of one or more of the top-level packages in the exported list? who wins?
- what if there are interpreter version incompatibilities in a top-level package or one or more (potentially pinned) deps or injected packages?
- what about packages installed from local tarballs, etc?
Describe alternatives you've considered
JSON is supposed to be human readable, right? :) I could certainly hack something together with zsh and jq that walks the tree and installs root + injected, but it seems natural enough to absorb this into pipx itself.
Thanks for adding the issue.
When I thought of this in the past, I thought that the easiest implementation would just be for pipx to go in sequence of the json list of packages and just blindly try to install each package as the json specs are written. Then if there were any problems it could just show the appropriate error and keep going.
Thus, for example, if there is a package installed from a local path and that local path doesn't exist on the target system, that package would just fail to install.
A "finesse-requiring" thing I can think of is, if a user specifies a non-default python interpreter, we'd have to find it. But that could be done by simply noting the major and minor python version and requiring the executable python<major>.<minor> to be on the path for it to successfully install.
I thought that the easiest implementation would just be for pipx to go in sequence of the json list of packages and just blindly try to install each package as the json specs are written. Then if there were any problems it could just show the appropriate error and keep going.
This is :100: by me! For completeness, i guess, i thought i'd argue against myself for a minute and list some snags that I could see coming up.
This would be great to include in pipx. Here's a simple implementation in shell that I'm using in the meantime:
# pipx list --json > ~/.pipx.json
set -ux
if [[ -e ~/.pipx.json ]]; then
for p in $(cat ~/.pipx.json | jq -r '.venvs[].metadata.main_package.package_or_url'); do
pipx install $p
done
fi
Seems like a useful feature if anyone wants to put together a PR.
Just coming from searching, so... it seems like the new command for the purpose is this one?
pipx reinstall-all --python <the Python executable file>
Hi @gaborbernat, I am interested in resolving this issue (because I need this feature in other projects). There was a pull request https://github.com/pypa/pipx/pull/874 but closed as stalled. Is there anything else we should pay attention to?
Feel free to open a new PR 😊