0
Purpose
For each subdirectory in directory that contains a setup.py
, run pip uninstall -y <directory name>
and pip install .
Windows solution
> for /D %f in (.\*) do (cd "%cd%\%f" && set s=%f && set j=%s:~3% && pip uninstall %j% && pip install .)
EDIT: Looks like pip uninstall/reinstall can be done with:
(for %F in ("%cd%") do pip uninstall -y "%~nxF") & pip install .
Linux solution
#!/usr/bin/env bash
DIR="${DIR:-$PWD}
VENV="${VENV:-.venv}"
REQUIREMENTS="${REQUIREMENTS:-'requirements.txt'}";
if [ ! -d "$VENV/bin" ]; then
echo Cannot find "$VENV/bin"
exit 2;
fi
source "$VENV/bin/activate"
for f in "${DIR[@]}"; do
if [ -f "$f/setup.py" ]; then
builtin cd "$f";
pip uninstall -y "${PWD##*/}";
if [ -f "$REQUIREMENTS" ]; then
pip install -r "$REQUIREMENTS"
fi
pip install .;
builtin cd ..;
fi;
done
As you can see, my Linux solution is much more versatile. Actually my Windows solution doesn't work.
The Windows solution is squashing the strings so things aren't deterministic between runs. Seems to be some weird parameter expansion going on. How am I meant to do it in CMD?
Are you open to Powershell? Have a play around with:
get-childitem -ErrorAction SilentlyContinue -recurse "C:\folder\" -filter setup.py | foreach {write-host "pip uninstall -y " $_.directory.fullname; "pip install ."}
as a starting point if you are? – HelpingHand – 2017-02-26T13:10:40.237"The Windows solution is squashing the strings so things aren't deterministic between runs" Please explain what you mean by this. – DavidPostill – 2017-02-26T13:35:14.640