pglombardo / pwpush-cli

Password Pusher Command Line Utility
MIT License
14 stars 4 forks source link

Helper script, to automatically set up a virtual_env #899

Open hboetes opened 3 months ago

hboetes commented 3 months ago

I'm not such a fan of pip, because dependencies often overwrite or destroy other applications. Therefor, I've created a universal helper script which automatically sets up a virtual env. Feel free to add it to the repo.

#!/bin/sh
# COPYRIGHT (C) 2021 Nicotine+ Team
#
# GNU GENERAL PUBLIC LICENSE
#    Version 3, 29 June 2007
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

name=pwpush
# Uncomment if you want to run unstable
# installname=git+https://github.com/pglombardo/pwpush-cli.git

# EXPORT PYTHONWARNINGS=default
export PYTHONWARNINGS=ignore

####
# Code
####

[[ -z $installname ]] && installname=$name

isinpath() {
    command -v $1 > /dev/null 2>&1
}
EXIT=false

for dependency in python virtualenv; do
    if ! isinpath $dependency; then
        echo "Please install $dependency" >&2
        EXIT=true
    fi
done

if [ "$EXIT" == true ]; then
    exit 1
fi

if [ ! -f ~/.virtualenv/$name/bin/activate ]; then
    virtualenv ~/.virtualenv/$name
    $HOME/.virtualenv/$name/bin/python -m pip install --upgrade pip
fi

source ~/.virtualenv/$name/bin/activate

if [ "$1" == update ] || [ "$1" == upgrade ] || [ ! -x $HOME/.virtualenv/$name/bin/$name ]; then
    # Also update pip. To prevent warnings.
    pip install --upgrade pip
    pip install --upgrade "$installname"
    exit $?
fi

"$HOME/.virtualenv/$name/bin/python" -W ignore::DeprecationWarning "$HOME/.virtualenv/$name/bin/$name" "$@" # > $name.log 2>&1
github-actions[bot] commented 3 months ago

Hello @hboetes, thanks for contributing to the Password Pusher community! We will respond as soon as possible.

pglombardo commented 3 months ago

Thanks @hboetes! Someone in the community may find this useful.