TIL How to migrate a python project to UV
All I need to migrate a legacy Python project to UV is a single uv add
command that magically takes care of all the inevitable import errors in one
swoop. Sure I could step through each one, but instead of wasting time doing
that I decided to waste time to find a one liner to do this task for me.
Granted, it’s not really wasted — I enjoy tinkering and learning with the shell. Like any instrument, all practice counts. It’s hard to argue this is as much of a waste of time than the manual route.
I used uvx to launch pipreqs to compile
a reqiurements.txt, then used tr and sed to format this list into a
uv add command that I could copy and paste to solve this issue. This replaces
the existing requirements.txt, but I don’t care about that when migrating my
project.
uvx pipreqs . --force --mode no-pin > /dev/null 2>&1 \
&& ( cat requirements.txt | tr '\n' ' ' | sed 's/^\(.*\)/uv add \1\n/' ) \
&& rm requirements.txt#pipreqs #automation #software-engineering #migration #dependency-management #uv #python #shell-scripting #programming
Reply to this post by email blZake@proZbableodyssey.blog (remove Z characters) ↪