From 5d39ab1d6091241fb228a379da64a84436138f59 Mon Sep 17 00:00:00 2001 From: yum Date: Mon, 6 Mar 2023 02:48:00 -0800 Subject: Silence virtual env setup PATH warnings Twofold approach: * All spawned processes have the desired path (new codepath) * Setup command silences the warning (old codepath) --- GUI/GUI/GUI/Frame.cpp | 1 + GUI/GUI/GUI/PythonWrapper.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/GUI/GUI/GUI/Frame.cpp b/GUI/GUI/GUI/Frame.cpp index f32f658..47fe624 100644 --- a/GUI/GUI/GUI/Frame.cpp +++ b/GUI/GUI/GUI/Frame.cpp @@ -1498,6 +1498,7 @@ void Frame::OnSetupPython(wxCommandEvent& event) "-m pip", "install", "-r Resources/Scripts/requirements.txt", + "--no-warn-script-location", }, std::move(cb)); if (!p) { Log(transcribe_out_, "Failed to launch environment setup thread!\n"); diff --git a/GUI/GUI/GUI/PythonWrapper.cpp b/GUI/GUI/GUI/PythonWrapper.cpp index c4b2b55..148692a 100644 --- a/GUI/GUI/GUI/PythonWrapper.cpp +++ b/GUI/GUI/GUI/PythonWrapper.cpp @@ -265,6 +265,20 @@ bool PythonWrapper::InvokeCommandWithArgs(const std::string& cmd, if (env.find(git_path.string()) == std::string::npos) { env += ";" + git_path.string(); + // Add updated PATH to current process's environment + if (!SetEnvironmentVariableA("PATH", env.c_str())) { + std::ostringstream err_oss; + err_oss << "Error while executing python command \"" << cmd_oss.str() + << "\": Failed to add git to PATH: " << GetWin32ErrMsg() << std::endl; + out_cb("", err_oss.str()); + return false; + } + } + std::filesystem::path py_bin = (std::filesystem::current_path() / + "Resources\Python\Scripts").lexically_normal(); + if (env.find(py_bin.string()) == std::string::npos) { + env += ";" + py_bin.string(); + // Add updated PATH to current process's environment if (!SetEnvironmentVariableA("PATH", env.c_str())) { std::ostringstream err_oss; -- cgit v1.2.3