Add uv line magic
This adds the ability to install packages using %uv install [pkgs] line magic.
I'm not sure this is worth it, what you are doing is basically transforming the %uv in !uv,
the case for pip/conda is that beginners tend to not differentiate CLI and Python prompt, and so we want to catch that and detect it.
I would suggest to make it as a package and if there is more interest and advantages over !uv we can bring it in, but I will need some convincing.
I think the motivation here is that !uv install will usually do the wrong thing and install into a python environment other than the one running the current kernel. (In the same way that !pip install and !conda install will also do the wrong thing.) From this classic post from Jake VDP
in Jupyter, the shell environment and the Python executable are disconnected.
(I'm sure you know this much better than I do, I just want to include some motivation that is missing from the PR description.)
I can see the counter-argument here: should the ipython project be responsible for including magics for every python package/environment management module? That's definitely a question for the ipython maintainers. I don't know what the adoption rates for uv are, but our team has been really impressed with the speed and functionality. And it seems like uv is quickly getting traction.
I think the motivation here is that
!uv installwill usually do the wrong thing and install into a python environment other than the one running the current kernel.
Yes, but for pip I do take special care of actually calling sys.executable -m pip, while here you are using shutil.which, and if uv is not in current env, it will get the potentially system global, so this is identical to !uv, I guess least maybe do sys.executable -m uv (I think it should work, but I haven't use uv enough, especially the multi-env).
Unless I misunderstand how shutil.which works, or missed something else in the PR. (Which is honestly quite likely I'm just getting out of a few days sick and still brainfoggy).
Thank you for the feedback! I will work on updating the PR to use sys.executable -m uv. I knew you could install uv with pip but I did not realize python -m uv would work.
I'm still not 100% convinced it is needed, but let's try it.
Thanks.
Err, this requires uv to have been installed to the Python env, which is not the usual uv installation method. Usually it is installed directly or with cargo, their executable autodetects a .venv presence, and there is no Python package in-env.
With a normal uv installation, if you try to use this magic, you'll currently get something like:
>>> %uv install urllib3
/tmp/example/.venv/bin/python: No module named uv
Note: you may need to restart the kernel to use updated packages.
A more correct approach would be to make the magic use uv pip install --python <sys.executable> ...