Skip to content

Commit 8f92e89

Browse files
ayax79Jack Wright
andauthored
Re-introduce nu_expand_path for polars open/save (nushell#16900)
## Release notes summary - What our users need to know Fixes a regression that causes absolute paths to be required when opening files with the polars plugin. Co-authored-by: Jack Wright <[email protected]>
1 parent 524146f commit 8f92e89

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

crates/nu_plugin_polars/src/dataframe/command/core/open.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn command(
154154
let spanned_file: Spanned<String> = call.req(0)?;
155155
debug!("file: {}", spanned_file.item);
156156

157-
let resource = Resource::new(plugin, &spanned_file)?;
157+
let resource = Resource::new(plugin, engine, &spanned_file)?;
158158
let type_option: Option<(String, Span)> = call
159159
.get_flag("type")?
160160
.map(|t: Spanned<String>| (t.item, t.span))

crates/nu_plugin_polars/src/dataframe/command/core/resource.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use std::path::PathBuf;
22

33
use crate::{PolarsPlugin, cloud::build_cloud_options};
4+
use nu_path::expand_path_with;
5+
use nu_plugin::EngineInterface;
46
use nu_protocol::{ShellError, Span, Spanned};
57
use polars::{
68
io::cloud::CloudOptions,
7-
prelude::{PlPath, SinkTarget},
9+
prelude::{PlPath, PlPathRef, SinkTarget},
810
};
911

1012
#[derive(Clone)]
@@ -29,11 +31,12 @@ impl std::fmt::Debug for Resource {
2931
impl Resource {
3032
pub(crate) fn new(
3133
plugin: &PolarsPlugin,
34+
engine: &EngineInterface,
3235
spanned_path: &Spanned<String>,
3336
) -> Result<Self, ShellError> {
3437
let path = PlPath::from_str(&spanned_path.item);
3538

36-
let cloud_options: Option<CloudOptions> = if path.is_cloud_url() {
39+
let (path, cloud_options): (PlPath, Option<CloudOptions>) = if path.is_cloud_url() {
3740
let options = build_cloud_options(plugin, &path)?;
3841
if options.is_none() {
3942
return Err(ShellError::GenericError {
@@ -47,9 +50,10 @@ impl Resource {
4750
inner: vec![],
4851
});
4952
}
50-
options
53+
(path, options)
5154
} else {
52-
None
55+
let new_path = expand_path_with(&spanned_path.item, engine.get_current_dir()?, true);
56+
(PlPathRef::from_local_path(&new_path).into_owned(), None)
5357
};
5458

5559
Ok(Self {

crates/nu_plugin_polars/src/dataframe/command/core/save/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ impl PluginCommand for SaveDF {
138138

139139
fn command(
140140
plugin: &PolarsPlugin,
141-
_engine: &EngineInterface,
141+
engine: &EngineInterface,
142142
call: &EvaluatedCall,
143143
polars_object: PolarsPluginObject,
144144
spanned_file: Spanned<String>,
145145
) -> Result<PipelineData, ShellError> {
146-
let resource = Resource::new(plugin, &spanned_file)?;
146+
let resource = Resource::new(plugin, engine, &spanned_file)?;
147147
let type_option: Option<(String, Span)> = call
148148
.get_flag("type")?
149149
.map(|t: Spanned<String>| (t.item, t.span))

0 commit comments

Comments
 (0)