Skip to content

Commit

Permalink
Merge pull request #162 from MetaCell/feature/PSYNEU-140
Browse files Browse the repository at this point in the history
PSYNEU-140 - Install MAC symlink on user directory to avoid Permissions Denied errors. Adds Desktop Icon as part of script installation #145
  • Loading branch information
ddelpiano authored Oct 7, 2024
2 parents b42a2eb + bca0005 commit 4895a29
Show file tree
Hide file tree
Showing 17 changed files with 314 additions and 58 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ yalc.lock
#prettier config
.prettierrc.json

.idea
.idea

package/.eggs
Binary file added package/.linux_installer.sh.swp
Binary file not shown.
70 changes: 44 additions & 26 deletions package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,72 @@
Download bash script to install [here](https://raw.githubusercontent.com/MetaCell/PsyNeuLinkView/feature/PSYNEU-140/package/linux_installer.sh).
It's recommended to download it in your home directory.

On terminal, go to your root directory
On terminal, go to your home directory
```
cd ~
```

Change file permissions to allow user to run it
```
chmod + x linux_installer.sh
```

And run installer
```
bash -i linux_installer.sh
./linux_installer.sh
```

After installation is done:

If conda environment is already active, run
```
psyneulinkviewer
```

If conda environment is not active, then run :
```
source ~/.profile
conda activate psyneulinkview
psyneulinkviewer
```

The application should open up after succesfully installing psyneulinkviewer.
The application should open up succesfully after this. An icon will be visible on the Desktop as well.

# Installing on MAC

Download bash script to install [here](https://raw.githubusercontent.com/MetaCell/PsyNeuLinkView/feature/PSYNEU-140/package/mac_installer.sh).
It's recommended to download it in your home directory.

On terminal, go to your root directory
On terminal, go to your home directory
```
cd ~
```

Give user permissions to file
```
chmod +x mac_installer.sh
```

And run installer
```
bash -i mac_installer.sh
./mac_installer.sh
```

After installation is done:

If conda environment is already active, run
```
open ~/psyneulinkviewer-darwin-x64/psyneulinkviewer.app/
```

The application should open up after succesfully installing psyneulinkviewer.
If conda environment is not active, then run :
```
source ~/.bash_profile
conda activate psyneulinkview
open ~/psyneulinkviewer-darwin-x64/psyneulinkviewer.app/
```

The application should open up succesfully after this. A desktop icon should be visible as well.

# Installation process inside script

Expand All @@ -54,27 +91,8 @@ source ~/.profile
source ~/.bash_profile
```

Then, the conda environment created is activated with command below:
```
conda activate psyneulinkview
```

Finally, the last step of the script opens the psyneulinkviewer application:
Then, a desktop file is created on the Desktop which allows users to open the application this way

On linux:
```
psyneulinkviewer
```

On Mac:
```
open /usr/local/bin/psyneulinkviewer-darwin-x64/psyneulinkviewer.app
```

The psyneulinkviewer application is installed on user directory:
```
/usr/local/bin/
```

# Psyneulinkviewer Requirements

Expand Down
Binary file removed package/dist/psyneulinkviewer-0.3.0.tar.gz
Binary file not shown.
Binary file added package/dist/psyneulinkviewer-0.4.8.tar.gz
Binary file not shown.
48 changes: 46 additions & 2 deletions package/linux_installer.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
#!/usr/bin/env bash -l
pip install -vv psyneulinkviewer && source ~/.profile && conda activate psyneulinkview && psyneulinkviewer
#!/bin/bash
pip install -vv psyneulinkviewer --break-system-packages --use-pep517 && . ~/.profile && sudo chown root:root /usr/local/bin/psyneulinkviewer-linux-x64/chrome-sandbox && sudo chmod 4755 /usr/local/bin/psyneulinkviewer-linux-x64/chrome-sandbox

# Variables
APP_NAME="PsyneulinkViewer" # Name of the application
SYMLINK_PATH="psyneulinkviewer" # Symlink to the application you want to launch
CONDA_ENV=$PSYNEULINK_ENV # Conda environment to activate if none is active
ICON_PATH="/usr/local/bin/psyneulinkviewer-linux-x64/resources/app/build/logo.png" # Path to the custom icon
DESKTOP_FILE="$HOME/Desktop/$APP_NAME.desktop" # Path where the desktop shortcut will be created

# Function to check if a conda environment is already active
is_conda_active() {
if [[ -n "$CONDA_DEFAULT_ENV" ]]; then
echo "Conda environment '$CONDA_DEFAULT_ENV' is already active."
return 0
else
echo "No active conda environment found. Activating '$CONDA_ENV'..."
return 1
fi
}

# Creating the .desktop file for the application
echo "[Desktop Entry]" > "$DESKTOP_FILE"
echo "Version=1.0" >> "$DESKTOP_FILE"
echo "Name=$APP_NAME" >> "$DESKTOP_FILE"

# Create the Exec command: Check if conda environment is active, if not activate the specified one
echo "Exec=bash -c '. ~/miniconda3/etc/profile.d/conda.sh && \
conda activate $CONDA_ENV && \
$SYMLINK_PATH'" >> "$DESKTOP_FILE"

# Set the custom icon
echo "Icon=$ICON_PATH" >> "$DESKTOP_FILE"
echo "Type=Application" >> "$DESKTOP_FILE"
echo "Terminal=false" >> "$DESKTOP_FILE"
echo "Categories=Application;" >> "$DESKTOP_FILE"

APP_DESKTOP="$HOME/.local/share/applications/$APP_NAME.desktop"

cp "$DESKTOP_FILE" "$APP_DESKTOP"
# Make the .desktop file executable
chmod +x "$DESKTOP_FILE"
rm "$DESKTOP_FILE"
chmod +x "$APP_DESKTOP"

echo "Application shortcut created at $APP_DESKTOP"
76 changes: 74 additions & 2 deletions package/mac_installer.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,74 @@
#!/usr/bin/env bash -l
pip install -vv psyneulinkviewer --break-system-packages && source ~/.bash_profile && conda activate psyneulinkview && open /usr/local/bin/psyneulinkviewer-darwin-x64/psyneulinkviewer.app/
#!/bin/bash
pip install -vv psyneulinkviewer --break-system-packages --use-pep517 && source ~/.bashrc_profile

# Variables - adjust these for your setup
APP_PATH="$HOME/psyneulinkviewer-darwin-x64/psyneulinkviewer.app/" # Replace with the full path to the application
CONDA_ENV=$PSYNEULINK_ENV # Replace with your Conda environment name
ICON_PATH="$HOME/psyneulinkviewer-darwin-x64/psyneulinkviewer.app/Contents/Resources/electron.icns" # Replace with the full path to your custom icon (should be in .icns format)
SHORTCUT_NAME="PsyneulinkViewer" # Name for the desktop shortcut

# Define paths
DESKTOP_PATH="$HOME/Desktop"
APP_SHORTCUT_PATH="$DESKTOP_PATH/$SHORTCUT_NAME.app"
COMMAND_FILE_PATH="$APP_SHORTCUT_PATH/Contents/MacOS/$SHORTCUT_NAME"
ICON_FILE_PATH="$APP_SHORTCUT_PATH/Contents/Resources/$SHORTCUT_NAME.icns"

# Create .app structure
mkdir -p "$APP_SHORTCUT_PATH/Contents/MacOS"
mkdir -p "$APP_SHORTCUT_PATH/Contents/Resources"

# Function to check if a conda environment is active
is_conda_active() {
# Check if the CONDA_DEFAULT_ENV variable is set, meaning a conda environment is active
if [ -z "$CONDA_DEFAULT_ENV" ]; then
return 1 # No active conda environment
else
return 0 # A conda environment is already active
fi
}

# Write the .command file that launches the app with conda environment
cat <<EOL > "$COMMAND_FILE_PATH"
#!/bin/bash
source ~/.bashrc_profile
source ~/miniconda3/etc/profile.d/conda.sh
conda activate $CONDA_ENV
open "$APP_PATH"
EOL

# Make the script executable
chmod +x "$COMMAND_FILE_PATH"

# Copy the custom icon
cp "$ICON_PATH" "$ICON_FILE_PATH"

# Create Info.plist for the app
cat <<EOL > "$APP_SHORTCUT_PATH/Contents/Info.plist"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>$SHORTCUT_NAME</string>
<key>CFBundleIconFile</key>
<string>$SHORTCUT_NAME</string>
<key>CFBundleIdentifier</key>
<string>com.example.$SHORTCUT_NAME</string>
<key>CFBundleName</key>
<string>$SHORTCUT_NAME</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
</dict>
</plist>
EOL

# Set the correct file permissions for the .app
chmod -R 755 "$APP_SHORTCUT_PATH"

# Touch the app to refresh Finder so it displays the correct icon
touch "$APP_SHORTCUT_PATH"

echo "Shortcut created at $DESKTOP_PATH/$SHORTCUT_NAME.app"

11 changes: 11 additions & 0 deletions package/psyneulinkviewer.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Metadata-Version: 2.1
Name: psyneulinkviewer
Version: 0.4.8
Home-page: https://github.com/metacell/psyneulinkviewer
Author: metacell
Author-email: dev@metacell.us
Requires-Python: >=3.7
License-File: LICENSE
Requires-Dist: requests
Requires-Dist: wget
Requires-Dist: packaging<=24.0
14 changes: 14 additions & 0 deletions package/psyneulinkviewer.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
LICENSE
README.md
setup.py
psyneulinkviewer/__init__.py
psyneulinkviewer/conda.py
psyneulinkviewer/configuration.py
psyneulinkviewer/node.py
psyneulinkviewer/rosetta.py
psyneulinkviewer/start.py
psyneulinkviewer.egg-info/PKG-INFO
psyneulinkviewer.egg-info/SOURCES.txt
psyneulinkviewer.egg-info/dependency_links.txt
psyneulinkviewer.egg-info/requires.txt
psyneulinkviewer.egg-info/top_level.txt
1 change: 1 addition & 0 deletions package/psyneulinkviewer.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions package/psyneulinkviewer.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
requests
wget
packaging<=24.0
1 change: 1 addition & 0 deletions package/psyneulinkviewer.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
psyneulinkviewer
10 changes: 4 additions & 6 deletions package/psyneulinkviewer/conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def create_env():
logging.info("Conda environment found %s", env_name)
except Exception as error:
logging.info("Conda environment not found")
env_name = None

if env_name is None:
command = get_conda_installed_path() + configuration.create_env
Expand All @@ -51,7 +52,7 @@ def shell_source(script):
def install_conda():
import wget
if platform.system() == 'Linux':
bash_file = wget.download(configuration.linux_conda_bash, out="tmp")
bash_file = wget.download(configuration.linux_conda_bash)
elif platform.system() == 'Darwin':
bash_file = wget.download(configuration.mac_conda_bash)

Expand Down Expand Up @@ -138,11 +139,7 @@ def detect_activated_conda() :
logging.info("Conda environment not detected active : %s", env_name)
env_name = None
else:
if env_name == configuration.env_name:
logging.info("Conda environment detected active : %s", env_name)
else:
logging.info("Active environment not matching : %s", configuration.env_name)
env_name = None
logging.info("Conda environment detected active : %s", env_name)
except Exception as error:
logging.info("Environment not found active: %s ", error)

Expand All @@ -159,6 +156,7 @@ def detect_activated_conda_location() :
if env_location:
env_location = re.search('(?<=base environment : )(/[a-zA-Z0-9\./]*[\s]?)', env_location)
env_location = env_location.group(0)
env_location = env_location.strip()
except Exception as error:
logging.info("Environment not found active: %s ", error)

Expand Down
5 changes: 3 additions & 2 deletions package/psyneulinkviewer/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

releases_url = 'https://api.github.com/repos/MetaCell/PsyNeuLinkView/releases'
application_url = "psyneulinkviewer-linux-x64/psyneulinkviewer"
application_url_mac = "psyneulinkviewer-linux-x64/psyneulinkviewer.app"

application_url_mac = "psyneulinkviewer-darwin-x64/psyneulinkviewer.app"
installation_folder_name = "/psyneulinkviewer-linux-x64"
installation_folder_name_mac = "/psyneulinkviewer-darwin-x64"

#Symlink
symlink = "/usr/local/bin/psyneulinkviewer"
Expand Down
12 changes: 8 additions & 4 deletions package/psyneulinkviewer/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ def check_node_installation():
logging.error("Exiting, node must be installed to continue...")
sys.exit()
from packaging.version import Version
if Version(node_version) > Version(configuration.node_required_version):
logging.info("Node version exists and valid, %s", node_version)
else:
if node_version is None:
logging.error("Node version not up to date, update required")
install_node()
install_node()
else:
if Version(node_version) > Version(configuration.node_required_version):
logging.info("Node version exists and valid, %s", node_version)
else:
logging.error("Node version not up to date, update required")
install_node()
Loading

0 comments on commit 4895a29

Please sign in to comment.