|
|
|
|
|
|
|
|
|
|
public class PyrceptionInstaller : EditorWindow |
|
|
|
{ |
|
|
|
private static Process currentProcess = null; |
|
|
|
/// <summary>
|
|
|
|
/// Runs pyrception instance in default browser
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
if(currentProcess != null) |
|
|
|
{ |
|
|
|
currentProcess.Kill(); |
|
|
|
currentProcess = null; |
|
|
|
UnityEngine.Debug.Log("Current Process was set to null"); |
|
|
|
} |
|
|
|
|
|
|
|
string pathToData = PlayerPrefs.GetString(SimulationState.latestOutputDirectoryKey); |
|
|
|
#if UNITY_EDITOR_WIN
|
|
|
|
path = path.Replace("/", "\\"); |
|
|
|
#endif
|
|
|
|
|
|
|
command = $"cd {path}\\DataInsightsEnv\\Scripts\\ && activate && pyrception-utils.exe preview --data=\"{PlayerPrefs.GetString(SimulationState.latestOutputDirectoryKey)}/..\""; |
|
|
|
command = $"cd {path}\\DataInsightsEnv\\Scripts\\ && activate && pyrception-utils.exe preview --data=\"{pathToData}\"/..\""; |
|
|
|
command = $"cd {path}/DataInsightsEnv/bin; activate; ./pyrception-utils preview --data=\"{PlayerPrefs.GetString(SimulationState.latestOutputDirectoryKey)}/..\""; |
|
|
|
command = $"cd {path}/DataInsightsEnv/bin; activate; ./pyrception-utils preview --data=\"{pathToData}/..\""; |
|
|
|
else |
|
|
|
UnityEngine.Debug.Log("You can view a preview of your datasets at: <color=#00aaccff>http://localhost:8501</color>"); |
|
|
|
/// Install pyrception (Assumes python and pip are already installed)
|
|
|
|
/// Install pyrception (Assumes python3 and pip3 are already installed)
|
|
|
|
/// - installs virtualenv if it is not already installed
|
|
|
|
/// - and setups a virtual environment for pyrception
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
int steps = 3; |
|
|
|
|
|
|
|
//Check pip install
|
|
|
|
//==============================CHECK PIP3 IS INSTALLED======================================
|
|
|
|
UnityEngine.Debug.LogError("pip3 must be installed."); |
|
|
|
UnityEngine.Debug.LogError("Python >= 3 and pip3 must be installed."); |
|
|
|
//==============================SETUP PATHS======================================
|
|
|
|
string path = Application.dataPath.Replace("/Assets", ""); |
|
|
|
#if UNITY_EDITOR_WIN
|
|
|
|
path = path.Replace("/", "\\"); |
|
|
|
|
|
|
//==============================INSTALL VIRTUALENV======================================
|
|
|
|
|
|
|
|
ExitCode = 0; |
|
|
|
#if UNITY_EDITOR_WIN
|
|
|
|
ExecuteCMD($"pip3 install virtualenv", ref ExitCode); |
|
|
|
|
|
|
EditorUtility.ClearProgressBar(); |
|
|
|
return; |
|
|
|
} |
|
|
|
EditorUtility.DisplayProgressBar("Setting up Pyrception", "Setting up virtualenv instance...", 1f / steps); |
|
|
|
//get virtualenv actual location
|
|
|
|
/* |
|
|
|
//get virtualenv actual location
|
|
|
|
string virtualenvPath = ExecuteCMD("pip3 show virtualenv | " + |
|
|
|
#if UNITY_EDITOR_WIN
|
|
|
|
"findstr" + |
|
|
|
#elif (UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX)
|
|
|
|
"grep" + |
|
|
|
#endif
|
|
|
|
" Location:", ref ExitCode, redirectOutput: true); |
|
|
|
if (ExitCode != 0) { |
|
|
|
EditorUtility.ClearProgressBar(); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
virtualenvPath = virtualenvPath.Replace("Location: ", "").Trim(); |
|
|
|
|
|
|
|
|
|
|
|
//==============================CREATE VIRTUALENV NAMED DataInsightsEnv======================================
|
|
|
|
EditorUtility.DisplayProgressBar("Setting up Pyrception", "Setting up virtualenv instance...", 1f / steps); |
|
|
|
virtualenvPath += "\\..\\Scripts"; |
|
|
|
ExecuteCMD($"{virtualenvPath}\\virtualenv.exe -p python3 \"{path}\\DataInsightsEnv\"", ref ExitCode); |
|
|
|
ExecuteCMD($"virtualenv -p python3 \"{path}\\DataInsightsEnv\"", ref ExitCode); |
|
|
|
virtualenvPath += "/../bin"; |
|
|
|
ExecuteCMD($"{virtualenvPath}/virtualenv -p python3 \"{path}/DataInsightsEnv\"", ref ExitCode); |
|
|
|
#endif
|
|
|
|
if (ExitCode != 0) { |
|
|
|
EditorUtility.ClearProgressBar(); |
|
|
|
return; |
|
|
|
} |
|
|
|
*/ |
|
|
|
#if (UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR_WIN
|
|
|
|
ExecuteCMD($"virtualenv -p python3 \"{path}\\DataInsightsEnv\"", ref ExitCode); |
|
|
|
#elif (UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX)
|
|
|
|
ExecuteCMD("export PYTHONPATH=\"${PYTHONPATH}:"+$"{path}/virtualenvDI\";"+$"\"{virtualenvPath}/virtualenv\" -p python3 \"{path}/DataInsightsEnv\"", ref ExitCode); |
|
|
|
#endif
|
|
|
|
if (ExitCode != 0) { |
|
|
|
|
|
|
|
|
|
|
//==============================COPY ALL PYRCEPTION FILES FOR INSTALLATION======================================
|
|
|
|
EditorUtility.DisplayProgressBar("Setting up Pyrception", "Getting pyrception files...", 2f / steps); |
|
|
|
|
|
|
|
#if UNITY_EDITOR_WIN
|
|
|
|
|
|
|
|
|
|
|
EditorUtility.DisplayProgressBar("Setting up Pyrception", "Installing pyrception utils...", 2.5f / steps); |
|
|
|
|
|
|
|
//==============================INSTALL PYRCEPTION IN THE VIRTUALENV======================================
|
|
|
|
#if UNITY_EDITOR_WIN
|
|
|
|
ExecuteCMD($"\"{path}\\DataInsightsEnv\\Scripts\\activate\" && cd \"{path}\\DataInsightsEnv\\pyrception-util\" && pip3 --no-cache-dir install -e . && deactivate", ref ExitCode); |
|
|
|
#elif (UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX)
|
|
|
|
|
|
|
info.RedirectStandardError = true && waitForExit; |
|
|
|
|
|
|
|
Process cmd = Process.Start(info); |
|
|
|
|
|
|
|
{ |
|
|
|
currentProcess = cmd; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cmd.WaitForExit(); |
|
|
|
if (redirectOutput) { |
|
|
|