#!/usr/bin/env bash
#
# pip-uses - parse output of `pip show` to determine which Python packages use a
# specified package.
#
# wish list:
# - optionally list usage dependencies recursively
# - operate on more than one argument

TARGET="$1"

if [ -z "${TARGET}" ]; then
  echo "
usage: $0 <package>
"
  exit 1
fi

for package in $(pip list | awk '{ print $1 }'); do
  # True if the pip information for this package contains the name of the TARGET
  # package under the "Requires:" section
  if pip show "${package}" | grep -q "^Requires:.*${TARGET}"; then
    echo "${package}"
  fi
done
