27c255c
#!/bin/sh -eux
27c255c
# This script requires root privileges and you should never run it on your own machine
27c255c
test $EUID -eq 0
27c255c
27c255c
PYTHON_VERSION=$(/usr/bin/python3 -c 'import sys; print("{}.{}".format(*sys.version_info))')
27c255c
RPM_SITELIB="/usr/lib/python${PYTHON_VERSION}/site-packages"
27c255c
LOCAL_SITELIB="/usr/local/lib/python${PYTHON_VERSION}/site-packages"
27c255c
USER_SITELIB="/home/fedora-test-user/.local/lib/python${PYTHON_VERSION}/site-packages"
27c255c
27c255c
# First, let's install older Pello with pip as if it was installed by RPM
27c255c
# This is an approximation, but it usually works
27c255c
RPM_BUILD_ROOT=/ /usr/bin/pip install 'Pello==1.0.1'
27c255c
27c255c
# Now, we'll upgrade it with regular pip
27c255c
/usr/bin/pip install --upgrade 'Pello==1.0.2'
27c255c
27c255c
# pip should see it
27c255c
/usr/bin/pip freeze | grep '^Pello==1\.0\.2$'
27c255c
27c255c
# Both installations should still exist
27c255c
test -d "${RPM_SITELIB}/Pello-1.0.1-py${PYTHON_VERSION}.egg-info" || test -d "${RPM_SITELIB}/Pello-1.0.1.dist-info"
27c255c
test -d "${LOCAL_SITELIB}/Pello-1.0.2.dist-info"
27c255c
27c255c
# Let's ditch the local one
27c255c
/usr/bin/pip uninstall --yes Pello
27c255c
27c255c
# It should only remove one of them
27c255c
test -d "${RPM_SITELIB}/Pello-1.0.1-py${PYTHON_VERSION}.egg-info" || test -d "${RPM_SITELIB}/Pello-1.0.1.dist-info"
27c255c
! test -d "${LOCAL_SITELIB}/Pello-1.0.2.dist-info"
27c255c
27c255c
# And pip should still see the RPM-installed one
27c255c
/usr/bin/pip freeze | grep '^Pello==1\.0\.1$'
27c255c
27c255c
# Again, but as regular user
27c255c
useradd fedora-test-user
27c255c
su fedora-test-user -c '/usr/bin/pip install "Pello==1.0.2"'
27c255c
test -d "${USER_SITELIB}/Pello-1.0.2.dist-info"
27c255c
su fedora-test-user -c '/usr/bin/pip freeze' | grep '^Pello==1\.0\.2$'
27c255c
su fedora-test-user -c '/usr/bin/pip uninstall --yes Pello'
27c255c
su fedora-test-user -c '/usr/bin/pip freeze' | grep '^Pello==1\.0\.1$'