Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Python global install #64

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 51 additions & 5 deletions global/install/skm_global_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ APP_PATH=`cd "$APP_PATH"; pwd`

SKM_PATH=`cd "$APP_PATH/../.."; pwd`

PYTHON_VERSION=`python3 -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(major + "." + minor);'`

source "${SKM_PATH}/tools/set_sk_env_vars.sh"

echo "Attempting to install the SplashKit C++ libraries to /usr/local/lib/splashkit"
Expand All @@ -23,15 +25,43 @@ if [ "$SK_OS" = "macos" ]; then
LIB_FILE="${SKM_PATH}/lib/macos/libSplashKit.dylib"
LIB_DEST="/usr/local/lib"
INC_DEST="/usr/local/include"

# macOS Python3 global install
if command -v python3 &> /dev/null; then
if command -v brew &> /dev/null; then
PYTHON_LIB="/opt/homebrew/lib/python${PYTHON_VERSION}/site-packages"
else
echo "Homebrew is not installed. Install homebrew and python3 using homebrew and run this script again"
fi
else
echo "Python is not installed. Install python3 using homebrew and run this script again."
fi

elif [ "$SK_OS" = "linux" ]; then
LIB_FILE="${SKM_PATH}/lib/linux/libSplashKit.so"
LIB_DEST="/usr/local/lib"
INC_DEST="/usr/local/include"

# Linux/WSL Python3 global install
if command -v python3 &> /dev/null; then
PYTHON_LIB="/usr/lib/python${PYTHON_VERSION}"
else
echo "Python is not installed. Install python3 and run this script again."
fi

elif [ "$SK_OS" = "win64" ]; then
LIB_FILE="${SKM_PATH}/lib/win64/SplashKit.dll"
WIN_OUT_DIR="${WINDIR}/System32"
LIB_DEST="/mingw64/lib"
INC_DEST="/mingw64/include"

# Windows (mingw64) Python3 global install
if command -v python3 &> /dev/null; then
PYTHON_LIB="/mingw64/lib/python${PYTHON_VERSION}"
else
echo "Python is not installed. Install python3 and run this script again."
fi

else
echo "Unable to detect operating system..."
exit 1
Expand All @@ -56,11 +86,19 @@ if [ ! -d "${INC_DEST}/splashkit" ]; then
fi

echo "Copying files to "${LIB_DEST}""

$PRIVILEGED cp -f "$LIB_FILE" "$LIB_DEST"
if [ ! $? -eq 0 ]; then
echo "Failed to copy SplashKit library to $LIB_DEST"
exit 1
# Copy all library files for mingw/msys2
if [ "$SK_OS" = "win64" ]; then
$PRIVILEGED cp "${SKM_PATH}/lib/win64/"* "$LIB_DEST"
if [ ! $? -eq 0 ]; then
echo "Failed to copy SplashKit library files to $LIB_DEST"
exit 1
fi
else
$PRIVILEGED cp -f "$LIB_FILE" "$LIB_DEST"
if [ ! $? -eq 0 ]; then
echo "Failed to copy SplashKit library to $LIB_DEST"
exit 1
fi
fi

echo "Copying files to ${INC_DEST}/splashkit"
Expand All @@ -76,6 +114,14 @@ if [ ! $? -eq 0 ]; then
exit 1
fi

# Copy splashkit python file to global location
echo "Copying splashkit.py to "${PYTHON_LIB}""
$PRIVILEGED cp "${SKM_PATH}/python3/splashkit.py" "${PYTHON_LIB}"
if [ ! $? -eq 0 ]; then
echo "Failed to copy splashkit.py to ${PYTHON_LIB}"
exit 1
fi

# We cant install but it should be on the path anyway...
#
# # If $WIN_OUT_DIR is set, we are on Windows and need to copy the dll to the System32 or System64 directory
Expand Down
34 changes: 19 additions & 15 deletions install-scripts/skm-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,25 @@ fi
export PATH="$INSTALL_PATH:$PATH"

if [[ `uname` = MINGW64* ]] || [[ `uname` = MSYS* ]]; then
#Export to path -- for current terminal
export PATH="$HOME/.splashkit/lib/win64:$PATH"
export PATH="$HOME/.splashkit:$PATH"

#Export path for new terminals
export ORIGINAL_PATH="$HOME/.splashkit/lib/win64:$ORIGINAL_PATH"
export ORIGINAL_PATH="$HOME/.splashkit:$ORIGINAL_PATH"

#Export paths for mingw64 compilers
COMPILER_PATH="/mingw64/bin"
export PATH="$COMPILER_PATH:$PATH"
export ORIGINAL_PATH="$COMPILER_PATH:$ORIGINAL_PATH"

# Set path
setx PATH "$ORIGINAL_PATH"
# List of PATHS added in splashkit install
SK_PATHS=("`cd /mingw64/bin; pwd -W`" "`cd ~/.splashkit; pwd -W`" "`cd ~/.splashkit/lib/win64; pwd -W`")

# Get Windows path and remove splashkit-added path elements
ORIGINAL_WIN_PATH=`powershell.exe -Command "[System.Environment]::GetEnvironmentVariable('PATH','User')"`

# Create string for splashKit paths
SK_PATHS_STR=""
for i in ${!SK_PATHS[@]}; do
SK_PATH="${SK_PATHS[$i]}"
SK_PATH="${SK_PATH////\\}"
SK_PATHS_STR+="$SK_PATH;"
done

# Create string for new windows path with splashkit paths added
NEW_WIN_PATH="$SK_PATHS_STR$ORIGINAL_WIN_PATH"

# Set updated Windows path
powershell.exe -Command "[System.Environment]::SetEnvironmentVariable('PATH',\"$NEW_WIN_PATH\",'User')"
fi

if [[ `uname` = Linux ]]; then
Expand Down
15 changes: 13 additions & 2 deletions python3/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@ else

echo "OVERVIEW: run python3 with SplashKit settings"
echo
echo "USAGE: skm python3 [options] [input]"
echo "USAGE: python3 [options] [input]"
echo
echo "Runs python3 with the required SplashKit settings and any additional options and input files."
echo
echo "Example usage:"
echo "Example usage (${bold}with global install${normal}):"
echo " Run a 'program.py' file using"
echo " ${bold}python3 program.py${normal}"
echo
echo " Run an interactive python3 REPL"
echo " ${bold}python3${normal}"
echo
echo " Output options for python3"
echo " ${bold}python3 --help${normal}"
echo
echo "Example usage (${bold}without global install${normal}):"
echo " Run a 'program.py' file using"
echo " ${bold}skm python3 program.py${normal}"
echo
Expand All @@ -21,5 +31,6 @@ else
echo
echo " Output options for python3"
echo " ${bold}skm python3 --help${normal}"

fi

28 changes: 18 additions & 10 deletions python3/splashkit.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
from ctypes import *
from enum import Enum
from platform import system
import os

search_paths = []

if system() == 'Darwin':
# macOS uses .dylib extension
cdll.LoadLibrary("libSplashKit.dylib")
sklib = CDLL("libsplashkit.dylib")
# macOS uses .dylib extension
search_paths = ["/usr/local/lib/libSplashKit.dylib", os.path.expanduser("~") + "/.splashkit/lib/macos/libSplashKit.dylib"]
elif system() == 'Linux':
# Linux uses .so extension
cdll.LoadLibrary("libSplashKit.so")
sklib = CDLL("libSplashKit.so")
# Linux uses .so extension
search_paths = ["/usr/local/lib/libSplashKit.so", os.path.expanduser("~") + "/.splashkit/lib/linux/libSplashKit.so"]
else:
# Windows uses .dll extension:
cdll.LoadLibrary("libSplashKit.dll")
sklib = CDLL("libsplashkit.dll")
# Windows uses .dll extension
search_paths = ["C:/msys64/mingw64/lib/SplashKit.dll", "C:/msys64/home/" + os.getlogin() + "/.splashkit/lib/win64/SplashKit.dll"]

# find path to use -> format above is: ["global/path", ".splashkit/path"]
for path in search_paths:
if (os.path.isfile(path)):
# load the library
cdll.LoadLibrary(path)
sklib = CDLL(path)
break

class _sklib_string(Structure):
_fields_ = [
Expand Down Expand Up @@ -1223,7 +1231,7 @@ def __skadapter__update_from_vector_bool(v, __skreturn):

sklib.__sklib__free__sklib_vector_bool(v)
def __skadapter__to_sklib_string(s):
return _sklib_string(s)
return _sklib_string(s.replace('\r',''))

sklib.__sklib__free__sklib_string.argtypes = [ _sklib_string ]
sklib.__sklib__free__sklib_string.restype = None
Expand Down
158 changes: 157 additions & 1 deletion uninstall/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,160 @@ APP_PATH=`cd "$APP_PATH"; pwd`
HOME_PATH=~
INSTALL_PATH="${HOME_PATH}/.splashkit"

rm -rf ${INSTALL_PATH}
SKM_PATH=`cd "$APP_PATH/.."; pwd`

source "${SKM_PATH}/tools/set_sk_env_vars.sh"

echo "Attempting to uninstall SplashKit libraries"
echo "This may require root access, please enter your password when prompted."
echo

if [ "$IS_WINDOWS" = true ]; then
PRIVILEGED=""
else
PRIVILEGED="sudo"
fi

PYTHON_VERSION=`python3 -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(major + "." + minor);'`

# Get directories for each OS
echo "Detecting operating system..."
if [ "$SK_OS" = "macos" ]; then
LIB_FILE="/usr/local/lib/libSplashKit.dylib"
LIB_DEST="/usr/local/lib"
INC_DEST="/usr/local/include"

# macOS Python3 global install
if command -v python3 &> /dev/null && command -v brew &> /dev/null; then
PYTHON_LIB="/opt/homebrew/lib/python${PYTHON_VERSION}/site-packages"
fi

elif [ "$SK_OS" = "linux" ]; then
LIB_FILE="/usr/local/lib/libSplashKit.so"
LIB_DEST="/usr/local/lib"
INC_DEST="/usr/local/include"

# Linux/WSL Python3 global install
if command -v python3 &> /dev/null; then
PYTHON_LIB="/usr/lib/python${PYTHON_VERSION}"
fi

elif [ "$SK_OS" = "win64" ]; then
LIB_FILE="/mingw64/lib/SplashKit.dll"
LIB_SRC="${SKM_PATH}/lib/win64"
LIB_DEST="/mingw64/lib"
INC_DEST="/mingw64/include"

# Windows (mingw64) Python3 global install
if command -v python3 &> /dev/null; then
PYTHON_LIB="/mingw64/lib/python${PYTHON_VERSION}"
fi

else
echo "Unable to detect operating system..."
exit 1
fi

# Remove global library include files in splashkit folder (and folder itself)
if [ -d "${INC_DEST}/splashkit" ]; then
echo "Remove directory ${INC_DEST}/splashkit"
$PRIVILEGED rm -rf "${INC_DEST}/splashkit"
if [ ! $? -eq 0 ]; then
echo "Failed to remove directory ${INC_DEST}/splashkit"
exit 1
fi
fi

# Remove splashkit header file
if [ -f "${INC_DEST}/splashkit.h" ]; then
echo "Removing splashkit header file from "${LIB_DEST}""
$PRIVILEGED rm -f "${INC_DEST}/splashkit.h"
if [ ! $? -eq 0 ]; then
echo "Failed to remove SplashKit header from ${INC_DEST}"
exit 1
fi
fi

# Remove splashkit library file
if [ -f "${LIB_FILE}" ]; then
if [ "$SK_OS" = "win64" ]; then
# Remove all splashkit related library files for mingw/msys2
echo "Removing splashkit files from "${LIB_DEST}""
cd $LIB_SRC
find . -type f -exec rm -rf $LIB_DEST/{} \;
if [ ! $? -eq 0 ]; then
echo "Failed to remove SplashKit library files from $LIB_DEST"
exit 1
fi
else
# Remove splashkit library file on macos and linux
echo "Removing splashkit file from "${LIB_DEST}""
$PRIVILEGED rm -f "$LIB_FILE"
if [ ! $? -eq 0 ]; then
echo "Failed to remove SplashKit library from $LIB_DEST"
exit 1
fi
fi
fi

# Remove splashkit python file from global location if python3 is installed
if [ -f "${PYTHON_LIB}/splashkit.py" ]; then
echo "Removing splashkit.py to "${PYTHON_LIB}""
$PRIVILEGED rm -f "${PYTHON_LIB}/splashkit.py"
if [ ! $? -eq 0 ]; then
echo "Failed to remove splashkit.py from ${PYTHON_LIB}"
exit 1
fi
fi

bold=$(tput bold)
normal=$(tput sgr0)

# Remove splashkit path from .bashrc if using bash
if [[ ${SHELL} = "/bin/bash" ]] || [ ${SHELL} = "/usr/bin/bash" -a `uname` = Linux ] ; then
echo "Removing ${bold}export PATH=\"$INSTALL_PATH:\$PATH\"${normal} from ~/.bashrc"
if [ $SK_OS = "macos" ]; then
sed -i '' "\|export PATH=\"$INSTALL_PATH:\$PATH\"|d" ~/.bashrc
else
sed -i "\|export PATH=\"$INSTALL_PATH:\$PATH\"|d" ~/.bashrc
fi
echo "Removing ${bold}export PATH=\"$INSTALL_PATH:\$PATH\"${normal} from ~/.bash_profile"
if [ $SK_OS = "macos" ]; then
sed -i '' "\|export PATH=\"$INSTALL_PATH:\$PATH\"|d" ~/.bash_profile
else
sed -i "\|export PATH=\"$INSTALL_PATH:\$PATH\"|d" ~/.bash_profile
fi
fi

# Remove splashkit path from .zshrc if using zsh
if [[ ${SHELL} = "/bin/zsh" ]] || [[ ${SHELL} = "/usr/bin/zsh" ]]; then
echo "Removing ${bold}export PATH=\"$INSTALL_PATH:\$PATH\"${normal} from ~/.zshrc"
if [ $SK_OS = "macos" ]; then
sed -i '' "\|export PATH=\"$INSTALL_PATH:\$PATH\"|d" ~/.zshrc
else
sed -i "\|export PATH=\"$INSTALL_PATH:\$PATH\"|d" ~/.zshrc
fi
fi

# Remove splashkit paths from Windows User PATH if using Windows(MSYS2)
if [ $SK_OS = "win64" ]; then
# List of PATHS added in splashkit install
SK_PATHS=("`cd /mingw64/bin; pwd -W`" "`cd ~/.splashkit; pwd -W`" "`cd ~/.splashkit/lib/win64; pwd -W`")

# Update paths in SK_PATHS to replace / with \
for i in ${!SK_PATHS[@]}; do
SK_PATH="${SK_PATHS[$i]}"
SK_PATH="${SK_PATH////\\}"
SK_PATHS[$i]=$SK_PATH
done

# Get Windows path and remove splashkit-added path elements
ORIGINAL_WIN_PATH=`powershell.exe -Command "([System.Environment]::GetEnvironmentVariable('PATH','User').Split(';') | Where-Object { (\\$_ -ne '${SK_PATHS[0]}' -and \\$_ -ne '${SK_PATHS[1]}' -and \\$_ -ne '${SK_PATHS[2]}') }) -join ';'"`

# Set updated Windows path
powershell.exe -Command "[System.Environment]::SetEnvironmentVariable('PATH',\"$ORIGINAL_WIN_PATH\",'User')"
fi

# Remove .splashkit folder
echo "Removing .splashkit folder from "${INSTALL_PATH}""
rm -rf ${INSTALL_PATH}