when spawned process during register plugin, pass env to child process (#6261)

* when spawned process during register plugin, pass env to child process

* tweak comment

* tweak comment

* remove trailing whitespace

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
This commit is contained in:
WindSoilder
2022-08-08 20:26:49 +08:00
committed by GitHub
parent 2f0cb044a5
commit aaf5684f9c
5 changed files with 17 additions and 2 deletions

View File

@ -61,6 +61,10 @@ impl Command for PluginDeclaration {
// Create PipelineData
let source_file = Path::new(&self.filename);
let mut plugin_cmd = create_command(source_file, &self.shell);
// We need the current environment variables for `python` based plugins
// Or we'll likely have a problem when a plugin is implemented in a virtual Python environment.
let current_envs = nu_engine::env::env_to_strings(engine_state, stack).unwrap_or_default();
plugin_cmd.envs(current_envs);
let mut child = plugin_cmd.spawn().map_err(|err| {
let decl = engine_state.get_decl(call.decl_id);

View File

@ -1,6 +1,7 @@
mod declaration;
pub use declaration::PluginDeclaration;
use nu_engine::documentation::get_flags_section;
use std::collections::HashMap;
use crate::protocol::{CallInput, LabeledError, PluginCall, PluginData, PluginResponse};
use crate::EncodingType;
@ -117,9 +118,11 @@ pub fn get_signature(
path: &Path,
encoding: &EncodingType,
shell: &Option<PathBuf>,
current_envs: &HashMap<String, String>,
) -> Result<Vec<Signature>, ShellError> {
let mut plugin_cmd = create_command(path, shell);
plugin_cmd.envs(current_envs);
let mut child = plugin_cmd.spawn().map_err(|err| {
ShellError::PluginFailedToLoad(format!("Error spawning child process: {}", err))
})?;