Skip to content

Commit

Permalink
Python virtual environment for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
rbarreror committed Nov 24, 2020
1 parent 78cedc0 commit b08b1a6
Show file tree
Hide file tree
Showing 31 changed files with 173 additions and 12 deletions.
19 changes: 17 additions & 2 deletions desktopApp/TurboPutative.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
#!/bin/bash
#!/usr/bin/env bash

# Get script current directory
SRC_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# Check if virtual environment is created
if ! [ -f "$SRC_HOME/env/log.info" ]
then
bash "$SRC_HOME/install/install_linux.sh"
fi

# Electron path
ELECTRON="$SRC_HOME/electron-v11.0.3-linux-x64/electron"

# Execute electron with app
"$SRC_HOME/node_modules/electron/dist/electron" "$SRC_HOME/app"
"$ELECTRON" "$SRC_HOME/app"

# If user closed before finishing process, kill processes
if [ $? -eq 99 ]
then
kill -9 $(ps -o pid= | grep -v -E "($$|$PPID)" ) > /dev/null 2>&1
fi
12 changes: 7 additions & 5 deletions desktopApp/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const fs = require('fs');
const os = require('os');
const { spawn, spawnSync, exec } = require('child_process');
const { spawn, spawnSync, execSync } = require('child_process');
const { finished } = require('stream');

// Global variables
Expand Down Expand Up @@ -64,6 +64,8 @@ app.on('window-all-closed', () => {

if (process.platform == "win32") {
spawnSync("TASKKILL", ["/F", "/T", "/PID", batch.pid]);
} else if (process.platform == "linux") {
app.exit(99)
}
}
}
Expand Down Expand Up @@ -107,7 +109,7 @@ ipcMain.on('go-back', (e, workflow) => {
ipcMain.on('run-workflow', (e, workflow) => {
// Run workflow and send waiting page

console.log(workflow);
// console.log(workflow);
var loadURL = win.loadURL(loader);

// Define workflow jobID
Expand Down Expand Up @@ -182,7 +184,7 @@ ipcMain.on('see-results', (e, workflow) => {
});

bash.stderr.on(`data`, (data) => {
console.error(`stderr: ${data}`);
console.error(`stdout: ${data}`);
});

bash.on('close', (code) => {
Expand Down Expand Up @@ -250,8 +252,8 @@ function runWorkflow (osType, modulesString, infile_user, workflowPath, infile_f
batch = spawn('CMD', ['/C', script, modulesString, infile_user, workflowPath, infile_feature_info, nCores]);
}

console.log(script);
console.log("PID: ", batch.pid);
// console.log(script);
// console.log("PID: ", batch.pid);

batch.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
Expand Down
14 changes: 9 additions & 5 deletions desktopApp/app/src/integrator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
SRC_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# PYTHON ENGINE
PYTHON="$SRC_HOME/python/bin/python3"
# PYTHON="$SRC_HOME/python/bin/python3"
PYTHON="$SRC_HOME/../../env/bin/python"
#PYTHON=python

PY_MODULES="$SRC_HOME/pyModules"

# INPUT VARIABLES
WORKFLOW="$1"
Expand All @@ -30,7 +34,7 @@ do
if [ $MOD_NUM == '1' ]
then
echo Running Tagger >> "$JOB_DIR/WF.log"
$PYTHON "$PWD/app/PPUMA/pyModules/Tagger.py" -i "$INFILE" -c "$JOB_DIR/Tagger.ini" -od "$JOB_DIR" -cpu $CPU
$PYTHON "$PY_MODULES/Tagger.py" -i "$INFILE" -c "$JOB_DIR/Tagger.ini" -od "$JOB_DIR" -cpu $CPU

# Handle errors
STATUS_CODE=$?
Expand All @@ -46,7 +50,7 @@ do
if [ $MOD_NUM == '2' ]
then
echo Running REname >> "$JOB_DIR/WF.log"
$PYTHON "$PWD/app/PPUMA/pyModules/Mod.py" -i "$INFILE" -pr "$JOB_DIR/REname.ini" -od "$JOB_DIR" -re "$JOB_DIR/regex.ini" -cpu $CPU
$PYTHON "$PY_MODULES/REname.py" -i "$INFILE" -pr "$JOB_DIR/REname.ini" -od "$JOB_DIR" -re "$JOB_DIR/regex.ini" -cpu $CPU

# Handle errors
STATUS_CODE=$?
Expand All @@ -62,7 +66,7 @@ do
if [ $MOD_NUM == '3' ]
then
echo Running RowMerger >> "$JOB_DIR/WF.log"
$PYTHON "$PWD/app/PPUMA/pyModules/Table.py" -i "$INFILE" -c "$JOB_DIR/rowMerger.ini" -od "$JOB_DIR"
$PYTHON "$PY_MODULES/RowMerger.py" -i "$INFILE" -c "$JOB_DIR/rowMerger.ini" -od "$JOB_DIR"

# Handle errors
STATUS_CODE=$?
Expand All @@ -77,7 +81,7 @@ do
if [ $MOD_NUM == '4' ]
then
echo Running TableMerger >> "$JOB_DIR/WF.log"
$PYTHON "$PWD/app/PPUMA/pyModules/FeatureInfo.py" -id "$INFILE" -c "$JOB_DIR/tableMerger.ini" -if "$FEATURE_INFO_INFILE" -od "$JOB_DIR"
$PYTHON "$PY_MODULES/TableMerger.py" -id "$INFILE" -c "$JOB_DIR/tableMerger.ini" -if "$FEATURE_INFO_INFILE" -od "$JOB_DIR"

# Handle errors
STATUS_CODE=$?
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
140 changes: 140 additions & 0 deletions desktopApp/install/install_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#!/usr/bin/env bash


###################
# Local functions #
###################

function checkPython {
"$PYTHON" --version > /dev/null 2>&1

if [ $? -eq 0 ]
then
# if python is in path, check version
local PY_VERSION="$("$PYTHON" --version)"
checkVersion "$PY_VERSION"

else
# if python is not in path, ask user to give it
getPython
fi
}


function checkVersion {
# get version
local VERSION=$(grep -E -o "Python\s[0-9]" <(echo "$1"))
local SUB_VERSION=$(grep -E -o "Python\s[0-9]\.[0-9]" <(echo "$1") | grep -E -o "[0-9]$")

if [ "$VERSION" != "Python 3" ]
then
echo "** ERROR: Using $VERSION instead of Python 3"
getPython
fi

if ! [ "$SUB_VERSION" -ge "6" ]
then
echo "** ERROR: Using $VERSION.$SUB_VERSION instead of Python 3.6 or greater"
getPython
fi

createVENV

}


function getPython {
echo "** Python not found"
read -p "** Enter full path to Python (or q to exit): " PYTHON

if [ $PYTHON -eq "q" ]
then
endInstall

else
checkPython
fi
}


function createVENV {

echo "** Creating virtual environment"
rm -rf "$SRC_HOME/../env"
"$PYTHON" -m venv "$SRC_HOME/../env"

if ! [ $? -eq 0 ]
then
echo "** ERROR: An error occurred while creating virtual environment"
rm -rf "$SRC_HOME/../env"
endInstall
fi

local PYTHON_ENV="$SRC_HOME/../env/bin/python"
local PIP_ENV="$SRC_HOME/../env/bin/pip"

echo "** Updating pip"
"$PYTHON_ENV" -m pip install --upgrade pip

if ! [ $? -eq 0 ]
then
echo "** ERROR: An error occurred while updating pip"
rm -rf "$SRC_HOME/../env"
endInstall
fi

echo "** Installing modules"
"$PIP_ENV" install numpy pandas xlrd xlwt --no-warn-script-location
if ! [ $? -eq 0 ]
then
echo "** ERROR: An error occurred while installing modules"
rm -rf "$SRC_HOME/../env"
endInstall
fi

echo "$(date) - INFO: Python Virtual Environment for TurboPutative created" > "$SRC_HOME/../env/log.info"
checkVENV
}


function checkVENV {

if [ -f "$SRC_HOME/../env/log.info" ]
then
# if it exists, exit...
envCreated
fi

}


function envCreated {
echo "** Python virtual environment created"
endInstall
}


function endInstall {
echo "** Installation process finished"
exit
}

##############
# Start main #
##############

echo "**"
echo "** CREATING PYTHON VIRTUAL ENVIRONMENT"
echo "**"

# Define SRC_HOME
SRC_HOME="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"

# Default python
PYTHON="python"

# Check if env folder already exists
checkVENV

# Start checking default python
checkPython

0 comments on commit b08b1a6

Please sign in to comment.