Skip to content

Commit

Permalink
Merge branch 'main' of github.com:FlipperPA/pyromania into main
Browse files Browse the repository at this point in the history
  • Loading branch information
FlipperPA committed Mar 2, 2023
2 parents 36794bb + fb1a1f8 commit c838ec9
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ curl -sS https://raw.githubusercontent.com/FlipperPA/pyromania/main/install.sh |
* `pyro`: Lists the venvs currently managed by pyromania.
* `pyro my_venv`: Activate a venv called `my_venv`, or creates it if it doesn't exist.
* `pyro my_venv --delete`: Deletes a venv called `my_venv`.
* `pyro my_venv --venv`: Changes to to the venv's directory.
* `pyro my_venv --packages`: Changes to to the venv's site-packages directory.

## Settings

Expand Down
26 changes: 19 additions & 7 deletions install-sudo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@ if grep -q "# Start Pyromania" /etc/bashrc; then
echo "It appears Pyromania is already installed for all users. Remove it from"
echo "/etc/bashrc if you need to reinstall."
echo ""
echo "You can update to the latest script version with this command:"
echo "You can update to the latest script version with these commands:"
echo "sudo curl -sS -o /etc/bashrc-pyro.sh https://raw.githubusercontent.com/FlipperPA/pyromania/main/pyro.sh"
echo "source /etc/bashrc"
else
sudo curl -sS -o /etc/bashrc-pyro.sh https://raw.githubusercontent.com/FlipperPA/pyromania/main/pyro.sh
sudo chmod 644 /etc/bashrc-pyro.sh

sudo echo "" >> /etc/bashrc
sudo echo "# Start Pyromania upon login for venv management." >> /etc/bashrc
sudo echo "source /etc/bashrc-pyro.sh" >> /etc/bashrc
sudo echo "export VENV_PYTHON=`which python3`" >> /etc/bashrc
sudo echo "# End Pyromania configuration." >> /etc/bashrc
echo "Looking for python3 in the path..."
PYTHON3="$(sudo which python3)"

sudo sh -c "cat >> /etc/bashrc <<EOT
echo "Pyromania has been installed! Type 'pyro' for help getting started."
# Start Pyromania upon login for venv management.
source /etc/bashrc-pyro.sh
export VENV_PYTHON=${PYTHON3}
# End Pyromania configuration.
EOT"
if ! which python3 ; then
echo "WARNING!"
echo "'python3' could not be found in the system path. You should edit /etc/bashrc"
echo "and set 'VENV_PYTHON' to the path of your preferred Python 3 binary."
echo ""
fi
echo "Pyromania has been installed! Type 'pyro --help' for help getting started."

source /etc/bashrc
fi
8 changes: 7 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ else
echo "export VENV_PYTHON=`which python3`" >> ~/.bashrc
echo "# End Pyromania configuration." >> ~/.bashrc

echo "Pyromania has been installed! Type 'pyro' for help getting started."
if ! which python3asdf ; then
echo "WARNING!"
echo "'python3' could not be found in the system path. You should edit ~/.bashrc"
echo "and set 'VENV_PYTHON' to the path of your preferred Python 3 binary."
echo ""
fi
echo "Pyromania has been installed! Type 'pyro --help' for help getting started."

source ~/.bashrc
fi
70 changes: 42 additions & 28 deletions pyro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,35 +70,46 @@ function pyro_add_to_list() {
}

function pyro_create() {
# venv names can't start with hyphens with pyro
if [[ $1 = -* ]]; then
"ERROR: venv names cannot being with a hyphen ('$1'). Aborting."
exit 0
fi

ACTIVE_NAME=$1
ACTIVE_DIR=`pwd`
ACTIVE_VENV="${VENV_DIR}"

if [ -f "${ACTIVE_DIR}/${ACTIVE_VENV}/bin/activate" ]; then
# If we find a venv that already exists, just add it to the list and activate.
echo "There appears to already be a 'venv' at '${ACTIVE_DIR}/${ACTIVE_VENV}'."
echo "It will be added to Pyromania's managed venv list."
pyro_add_to_list
pyro_activate
# If we find a venv that already exists, just add it to the list and activate.
echo "There appears to already be a 'venv' at '${ACTIVE_DIR}/${ACTIVE_VENV}'."
if [ $2 = "--add" ]; then
echo "It will be added to Pyromania's managed venv list."
pyro_add_to_list
pyro_activate
else
echo "To create an entry for it with Pyromania, you can use the command:"
echo "pyro $ACTIVE_NAME --add"
fi
else
echo "Creating a new venv in directory ${ACTIVE_DIR}/${ACTIVE_VENV}..."
# Create the venv
${VENV_PYTHON} -m venv --copies --prompt ${ACTIVE_NAME} ${ACTIVE_VENV}
pyro_add_to_list

# Create script to run before venv activation
echo "# Commands to be run before venv activation" >> "${ACTIVE_VENV}/pre_activate.sh"

# Create script to run after venv activation, default to current directory
echo "# Commands to be run after venv activation" >> "${ACTIVE_VENV}/post_activate.sh"
echo "cd ${PWD}" >> "${ACTIVE_VENV}/post_activate.sh"

# Activate the new venv
pyro_activate

# Get the latest pip
echo "Upgrading to latest pip & wheel..."
python -m pip install --quiet --upgrade pip wheel
echo "Creating a new venv in directory ${ACTIVE_DIR}/${ACTIVE_VENV}..."
# Create the venv
${VENV_PYTHON} -m venv --copies --prompt ${ACTIVE_NAME} ${ACTIVE_VENV}
pyro_add_to_list
# Create script to run before venv activation
echo "# Commands to be run before venv activation" >> "${ACTIVE_VENV}/pre_activate.sh"

# Create script to run after venv activation, default to current directory
echo "# Commands to be run after venv activation" >> "${ACTIVE_VENV}/post_activate.sh"
echo "cd ${PWD}" >> "${ACTIVE_VENV}/post_activate.sh"

# Activate the new venv
pyro_activate

# Get the latest pip
echo "Upgrading to latest pip & wheel..."
python -m pip install --quiet --upgrade pip wheel
fi
}

Expand Down Expand Up @@ -129,7 +140,7 @@ function pyro_setup() {
VENV_LIST=""
ACTION="--create"

# Default to use venv for the venv directory name
# Default to use venv for fithe venv directory name
if [ -z "${VENV_DIR}" ]; then
VENV_DIR="venv"
fi
Expand All @@ -149,7 +160,7 @@ function pyro_delete() {
rm -rf "${ACTIVE_DIR}/${ACTIVE_VENV}"
else
echo "Directory does not exist: ${ACTIVE_DIR}/${ACTIVE_VENV}"
echo "Removing name from the list of managed venvs since it does not exist."
echo "Removing name from the list of managed venvs since it does not exist."
fi

local IFS=:
Expand All @@ -158,9 +169,12 @@ function pyro_delete() {
set $line

if [ "$1" != "${ACTIVE_NAME}" ]; then
echo "$line" >> ~/.pyromania-new
echo "$line" >> ~/.pyromania-new
fi
done < ~/.pyromania

# Replace the metadata file without the deleted entry.
touch ~/.pyromania-new
mv ~/.pyromania-new ~/.pyromania

unset ACTIVE_NAME
Expand Down Expand Up @@ -193,8 +207,8 @@ function fn_pyro() {
# Action to perform based on parameters.
if [ $1 = "--help" ]; then
pyro_help
elif [ "${ACTION}" = "--create" ]; then
pyro_create $1
elif [ "${ACTION}" = "--create" ] || [ "${ACTION}" = "--add" ]; then
pyro_create $1 $ACTION
elif [ "${ACTIVE_NAME}" != "" ] && [ "${ACTIVE_DIR}" != "" ]; then
if [ "${ACTION}" = "--delete" ] || [ "${ACTION}" = "-d" ]; then
pyro_delete
Expand Down

0 comments on commit c838ec9

Please sign in to comment.