#!/bin/sh

set -eux

if [ -e /usr/lib/$(py3versions -d)/EXTERNALLY-MANAGED ]; then
    echo "Removing EXTERNALLY-MANAGED marker to test behaviour"
    rm /usr/lib/$(py3versions -d)/EXTERNALLY-MANAGED
fi

export HOME=$AUTOPKGTEST_TMP
export PATH=$PATH:$HOME/.local/bin

if [ -n "${AUTOPKGTEST_NORMAL_USER:-}" ]; then
    user=$AUTOPKGTEST_NORMAL_USER
elif [ $(id -u) = 0 ]; then
    adduser --quiet --system --group --no-create-home testing
    user=testing
else
    user=""
    runuser=""
fi
if [ -n "$user" ]; then
    mkdir $HOME/.local
    chown -R $user $HOME
    runuser="runuser -p -u $user --"
fi

$runuser python3 -m pip install world
$runuser python3 -m pip list --format=columns
$runuser python3 -m pip show world
ls -ld $HOME/.local/lib/python3.*/site-packages/world-*.dist-info
$runuser python3 -m pip uninstall -y world
$runuser python3 -m pip list --format=columns
$runuser python3 -m pip list --outdated
