pipx icon indicating copy to clipboard operation
pipx copied to clipboard

Support provisioning of pipx-managed sites from the output of `pipx list --json`.

Open gvoysey opened this issue 4 years ago • 4 comments
trafficstars

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.

gvoysey avatar May 14 '21 14:05 gvoysey

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.

itsayellow avatar May 15 '21 04:05 itsayellow

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.

gvoysey avatar May 15 '21 13:05 gvoysey

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

indigoviolet avatar Jan 29 '22 03:01 indigoviolet

Seems like a useful feature if anyone wants to put together a PR.

cs01 avatar Feb 16 '22 14:02 cs01

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>

boholder avatar Mar 10 '24 03:03 boholder

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?

huxuan avatar Mar 18 '24 07:03 huxuan

Feel free to open a new PR 😊

gaborbernat avatar Mar 18 '24 15:03 gaborbernat