Skip to content

Instantly share code, notes, and snippets.

@yarko
Last active February 7, 2018 17:51
Show Gist options
  • Save yarko/30a1f6add293b48b5d2defd6f6e0a747 to your computer and use it in GitHub Desktop.
Save yarko/30a1f6add293b48b5d2defd6f6e0a747 to your computer and use it in GitHub Desktop.
bash multi-python pip update scripts
#!/usr/local/bin/python3
from sys import stdin
from os import path
excl_f = path.expanduser("~/.config/pipupgrade/exclude")
with open(excl_f, "r") as f:
excl = []
for line in f:
excl.append(line[:-1])
# grab the module name from "pip list -o" output:
mod_name = lambda l: l.split(maxsplit=1)[0]
is_excluded = lambda s: s in excl
for line in stdin:
mod = mod_name(line)
x = is_excluded(mod)
lt = "=>" if x else " "
rt = "\t<= not auto-upgraded" if x else ""
print(f"{lt} {line[:-1]}{rt}")
#!/bin/bash
COL_BLUE="\x1b[34;01m"
COL_RESET="\x1b[39;49;00m"
PYVERS=${PYVERS:-"2.7 3.5 3.6 3.7"}
# note: python time unnoticable, compared to pip network delay
#EXCL="$HOME/.config/pipupgrade/exclude"
for i in ${PYVERS}; do
echo -e $COL_BLUE$(python$i -m pip --version):$COL_RESET
python$i -m pip list -o | _excluded_updates.py
done
#!/bin/bash
COL_BLUE="\x1b[34;01m"
COL_RESET="\x1b[39;49;00m"
# make the default version the last - so script installations
# work appropriatly
PYVERS=${PYVERS:-"2.7 3.5 3.7 3.6"}
# lock out these from batch upgrade:
EXCL="$HOME/.config/pipupgrade/exclude"
for i in ${PYVERS}; do
echo -e $COL_BLUE$(python$i -m pip --version):$COL_RESET
# if arguments passed, then upgrade/install those in all the python versions;
# else grab the outdated list from each python version, and upgrade those;
(( ${#@} > 0 )) && upgradeable="$@" || \
upgradeable="$(python$i -m pip list -o | cut -d ' ' -f1 | fgrep -vf $EXCL)"
if [ -z "$upgradeable" ]; then
continue
fi
# check if we're owner, or need sudo
[ -O $(which python$i) ] && PIP="python$i -m pip" || PIP="sudo -H python$i -m pip"
$PIP install -U ${upgradeable}
done
@yarko
Copy link
Author

yarko commented Aug 4, 2017

A simple hack to keep my "public" (non venv) python libraries up to date.

I use this on Ubuntu 16.04.

I let Ubuntu ppa keep my Python3.5 version up to date.
I build and install myself the other python versions (2.7, 3.6, 3.7dev).

There may be symlinks I've made along the way (e.g. ln -s /usr/local/bin/python3.6 /usr/local/bin/python) to make this all work the way I've wanted. Other than such simple things, this should be ok (let me know if it's not).

I think python2.7 builds w/ altinstall are not polite - they install items which are not version-numbered, so on that rare occaision when I build 2.7, I have to go and manually fix that. This is not a problem with 3.6 and 3.7 builds (which are well-behaved under make altinstall).
It doesn't matter much, because 2.7 increasingly doesn't matter much anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment