forked from extern/nushell
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:
parent
2f0cb044a5
commit
aaf5684f9c
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2721,6 +2721,7 @@ dependencies = [
|
|||||||
"itertools",
|
"itertools",
|
||||||
"log",
|
"log",
|
||||||
"miette 5.1.1",
|
"miette 5.1.1",
|
||||||
|
"nu-engine",
|
||||||
"nu-path",
|
"nu-path",
|
||||||
"nu-plugin",
|
"nu-plugin",
|
||||||
"nu-protocol",
|
"nu-protocol",
|
||||||
|
@ -15,6 +15,7 @@ serde_json = "1.0"
|
|||||||
nu-path = {path = "../nu-path", version = "0.66.3" }
|
nu-path = {path = "../nu-path", version = "0.66.3" }
|
||||||
nu-protocol = { path = "../nu-protocol", version = "0.66.3" }
|
nu-protocol = { path = "../nu-protocol", version = "0.66.3" }
|
||||||
nu-plugin = { path = "../nu-plugin", optional = true, version = "0.66.3" }
|
nu-plugin = { path = "../nu-plugin", optional = true, version = "0.66.3" }
|
||||||
|
nu-engine = { path = "../nu-engine", version = "0.66.3" }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
@ -2623,7 +2623,8 @@ pub fn parse_register(
|
|||||||
expand_aliases_denylist: &[usize],
|
expand_aliases_denylist: &[usize],
|
||||||
) -> (Pipeline, Option<ParseError>) {
|
) -> (Pipeline, Option<ParseError>) {
|
||||||
use nu_plugin::{get_signature, EncodingType, PluginDeclaration};
|
use nu_plugin::{get_signature, EncodingType, PluginDeclaration};
|
||||||
use nu_protocol::Signature;
|
use nu_protocol::{engine::Stack, Signature};
|
||||||
|
|
||||||
let cwd = working_set.get_cwd();
|
let cwd = working_set.get_cwd();
|
||||||
|
|
||||||
// Checking that the function is used with the correct name
|
// Checking that the function is used with the correct name
|
||||||
@ -2784,6 +2785,11 @@ pub fn parse_register(
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 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 stack = Stack::new();
|
||||||
|
let current_envs =
|
||||||
|
nu_engine::env::env_to_strings(working_set.permanent_state, &stack).unwrap_or_default();
|
||||||
let error = match signature {
|
let error = match signature {
|
||||||
Some(signature) => arguments.and_then(|(path, encoding)| {
|
Some(signature) => arguments.and_then(|(path, encoding)| {
|
||||||
signature.map(|signature| {
|
signature.map(|signature| {
|
||||||
@ -2793,7 +2799,7 @@ pub fn parse_register(
|
|||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
None => arguments.and_then(|(path, encoding)| {
|
None => arguments.and_then(|(path, encoding)| {
|
||||||
get_signature(path.as_path(), &encoding, &shell)
|
get_signature(path.as_path(), &encoding, &shell, ¤t_envs)
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
ParseError::LabeledError(
|
ParseError::LabeledError(
|
||||||
"Error getting signatures".into(),
|
"Error getting signatures".into(),
|
||||||
|
@ -61,6 +61,10 @@ impl Command for PluginDeclaration {
|
|||||||
// Create PipelineData
|
// Create PipelineData
|
||||||
let source_file = Path::new(&self.filename);
|
let source_file = Path::new(&self.filename);
|
||||||
let mut plugin_cmd = create_command(source_file, &self.shell);
|
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 mut child = plugin_cmd.spawn().map_err(|err| {
|
||||||
let decl = engine_state.get_decl(call.decl_id);
|
let decl = engine_state.get_decl(call.decl_id);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
mod declaration;
|
mod declaration;
|
||||||
pub use declaration::PluginDeclaration;
|
pub use declaration::PluginDeclaration;
|
||||||
use nu_engine::documentation::get_flags_section;
|
use nu_engine::documentation::get_flags_section;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::protocol::{CallInput, LabeledError, PluginCall, PluginData, PluginResponse};
|
use crate::protocol::{CallInput, LabeledError, PluginCall, PluginData, PluginResponse};
|
||||||
use crate::EncodingType;
|
use crate::EncodingType;
|
||||||
@ -117,9 +118,11 @@ pub fn get_signature(
|
|||||||
path: &Path,
|
path: &Path,
|
||||||
encoding: &EncodingType,
|
encoding: &EncodingType,
|
||||||
shell: &Option<PathBuf>,
|
shell: &Option<PathBuf>,
|
||||||
|
current_envs: &HashMap<String, String>,
|
||||||
) -> Result<Vec<Signature>, ShellError> {
|
) -> Result<Vec<Signature>, ShellError> {
|
||||||
let mut plugin_cmd = create_command(path, shell);
|
let mut plugin_cmd = create_command(path, shell);
|
||||||
|
|
||||||
|
plugin_cmd.envs(current_envs);
|
||||||
let mut child = plugin_cmd.spawn().map_err(|err| {
|
let mut child = plugin_cmd.spawn().map_err(|err| {
|
||||||
ShellError::PluginFailedToLoad(format!("Error spawning child process: {}", err))
|
ShellError::PluginFailedToLoad(format!("Error spawning child process: {}", err))
|
||||||
})?;
|
})?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user