浏览代码

improve error messages and don't depend on PATH for virtualenv

/pyrception-integration
leopoldo-zugasti 4 年前
当前提交
a1db4819
共有 1 个文件被更改,包括 35 次插入15 次删除
  1. 50
      com.unity.perception/Editor/Pyrception/PyrceptionInstaller.cs

50
com.unity.perception/Editor/Pyrception/PyrceptionInstaller.cs


#elif (UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX)
command = $"cd {path}/DataInsightsEnv/Scripts; activate; pyrception-utils preview --data=\"{PlayerPrefs.GetString(SimulationState.latestOutputDirectoryKey)}/..\"";
#endif
int ExitCode = ExecuteCMD(command, false, true);
int ExitCode = 0;
ExecuteCMD(command, ref ExitCode, waitForExit: false, displayWindow: true);
if (ExitCode != 0)
return;
}

//Check pip install
int ExitCode = 0;
ExitCode = ExecuteCMD("pip3");
ExecuteCMD("pip3", ref ExitCode);
UnityEngine.Debug.LogError("pip3 and python >= 3 must be installed.");
UnityEngine.Debug.LogError("pip3 must be installed.");
return;
}
string path = Application.dataPath.Replace("/Assets", "");

EditorUtility.DisplayProgressBar("Setting up Pyrception", "Installing virtualenv...", 0 / steps);
ExitCode = 0;
ExitCode = ExecuteCMD("pip3 install virtualenv");
ExecuteCMD("pip3 install virtualenv", ref ExitCode);
if (ExitCode != 0) {
EditorUtility.ClearProgressBar();
return;

//get virtualenv actual location
string virtualenvPath = ExecuteCMD("pip3 show virtualenv | findstr Location:", ref ExitCode, redirectOutput: true);
virtualenvPath = virtualenvPath.Replace("Location: ", "").Trim();
if (ExitCode != 0) {
EditorUtility.ClearProgressBar();
return;
}
virtualenvPath += "/../Scripts";
ExitCode = ExecuteCMD($"virtualenv -p python3 \"{path}\\DataInsightsEnv\"");
virtualenvPath = virtualenvPath.Replace("/", "\\");
ExecuteCMD($"{virtualenvPath}\\virtualenv -p python3 \"{path}\\DataInsightsEnv\"", ref ExitCode);
ExitCode = ExecuteCMD($"virtualenv -p python3 \"{path}/DataInsightsEnv\"");
ExecuteCMD($"{virtualenvPath}\\virtualenv -p python3 \"{path}/DataInsightsEnv\"", ref ExitCode);
#endif
if (ExitCode != 0) {
EditorUtility.ClearProgressBar();

EditorUtility.DisplayProgressBar("Setting up Pyrception", "Getting pyrception files...", 2f / steps);
#if UNITY_EDITOR_WIN
ExitCode = ExecuteCMD($"XCOPY /E/I/Y \"{pyrceptionPath}\" \"{path}\\DataInsightsEnv\\pyrception-util\"");
ExecuteCMD($"XCOPY /E/I/Y \"{pyrceptionPath}\" \"{path}\\DataInsightsEnv\\pyrception-util\"", ref ExitCode);
ExitCode = ExecuteCMD($"\\cp -r \"{pyrceptionPath}\" \"{path}/DataInsightsEnv/pyrception-util\"");
ExecuteCMD($"\\cp -r \"{pyrceptionPath}\" \"{path}/DataInsightsEnv/pyrception-util\"", ref ExitCode);
#endif
if (ExitCode != 0) {
EditorUtility.ClearProgressBar();

EditorUtility.DisplayProgressBar("Setting up Pyrception", "Installing pyrception utils...", 2.5f / steps);
#if UNITY_EDITOR_WIN
ExitCode = ExecuteCMD($"\"{path}\\DataInsightsEnv\\Scripts\\activate\" && cd \"{path}\\DataInsightsEnv\\pyrception-util\" && pip3 --no-cache-dir install -e . && deactivate");
ExecuteCMD($"\"{path}\\DataInsightsEnv\\Scripts\\activate\" && cd \"{path}\\DataInsightsEnv\\pyrception-util\" && pip3 --no-cache-dir install -e . && deactivate", ref ExitCode);
ExitCode = ExecuteCMD($"source \"{path}/DataInsightsEnv/Scripts/activate\"; cd \"{path}/DataInsightsEnv/pyrception-util\"; pip3 --no-cache-dir install -e .; deactivate");
ExecuteCMD($"source \"{path}/DataInsightsEnv/Scripts/activate\"; cd \"{path}/DataInsightsEnv/pyrception-util\"; pip3 --no-cache-dir install -e .; deactivate", ref ExitCode);
#endif
if (ExitCode != 0) {
EditorUtility.ClearProgressBar();

/// <param name="waitForExit">Should it wait for exit before returning to the editor (i.e. is it not async?)</param>
/// <param name="displayWindow">Should the command window be displayed</param>
/// <returns></returns>
private static int ExecuteCMD(string command, bool waitForExit = true, bool displayWindow = false)
private static string ExecuteCMD(string command, ref int ExitCode, bool waitForExit = true, bool displayWindow = false, bool redirectOutput = false)
string output = "";
#if UNITY_EDITOR_WIN
shell = "cmd.exe";

info.CreateNoWindow = !displayWindow;
info.UseShellExecute = !waitForExit;
info.RedirectStandardOutput = redirectOutput && waitForExit;
info.RedirectStandardError = true && waitForExit;
return 0;
return "";
int ExitCode = 0;
if (redirectOutput) {
output = cmd.StandardOutput.ReadToEnd();
}
UnityEngine.Debug.LogError($"Error - {ExitCode} - Failed to execute: {command}");
UnityEngine.Debug.LogError($"Error - {ExitCode} - Failed to execute: {command} - {cmd.StandardError.ReadToEnd()}");
return ExitCode;
return output;
}
}
正在加载...
取消
保存