Skip to content

Commit

Permalink
feat(metagen): python client file upload (#931)
Browse files Browse the repository at this point in the history
<!--
Pull requests are squashed and merged using:
- their title as the commit message
- their description as the commit body

Having a good title and description is important for the users to get
readable changelog.
-->

<!-- 1. Explain WHAT the change is about -->

- Closes
[MET-769](https://linear.app/metatypedev/issue/MET-769/add-file-upload-support-for-python-metagen-client)

<!-- 3. Explain HOW users should update their code -->

#### Migration notes

---

- [x] The change comes with new or modified tests
- [ ] Hard-to-understand functions have explanatory comments
- [ ] End-user documentation is updated to reflect the change
  • Loading branch information
luckasRanarison authored Dec 1, 2024
1 parent 822437b commit 0081436
Show file tree
Hide file tree
Showing 11 changed files with 1,612 additions and 212 deletions.
3 changes: 2 additions & 1 deletion src/metagen/src/client_py/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class QueryGraph(QueryGraphBase):
{{"{node_name}": NodeDescs.{meta_method}}},
"$q"
)[0]
return {node_type}(node.node_name, node.instance_name, node.args, node.sub_nodes)
return {node_type}(node.node_name, node.instance_name, node.args, node.sub_nodes, node.files)
"#
)?;
}
Expand Down Expand Up @@ -280,6 +280,7 @@ fn render_node_metas(
Rc::new(node_metas::PyNodeMetasRenderer {
name_mapper,
named_types: named_types.clone(),
input_files: manifest.input_files.clone(),
}),
);
for &id in &manifest.node_metas {
Expand Down
33 changes: 30 additions & 3 deletions src/metagen/src/client_py/node_metas.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0

use std::fmt::Write;
use std::{collections::HashMap, fmt::Write, ops::Not};

use common::typegraph::*;

use super::utils::normalize_type_title;
use crate::{interlude::*, shared::types::*};
use crate::{
interlude::*,
shared::{files::TypePath, types::*},
};

pub struct PyNodeMetasRenderer {
pub name_mapper: Rc<super::NameMapper>,
pub named_types: Rc<std::sync::Mutex<IndexSet<u32>>>,
pub input_files: Rc<HashMap<u32, Vec<TypePath>>>,
}

impl PyNodeMetasRenderer {
Expand Down Expand Up @@ -52,6 +56,7 @@ impl PyNodeMetasRenderer {
ty_name: &str,
return_node: &str,
argument_fields: Option<IndexMap<String, Rc<str>>>,
input_files: Option<String>,
) -> std::fmt::Result {
write!(
dest,
Expand Down Expand Up @@ -84,6 +89,13 @@ impl PyNodeMetasRenderer {
}},"#
)?;
}
if let Some(input_files) = input_files {
write!(
dest,
r#"
input_files={input_files},"#
)?;
}
write!(
dest,
r#"
Expand Down Expand Up @@ -172,7 +184,22 @@ impl RenderType for PyNodeMetasRenderer {
};
let node_name = &base.title;
let ty_name = normalize_type_title(node_name).to_pascal_case();
self.render_for_func(renderer, &ty_name, &return_ty_name, props)?;
let input_files = self
.input_files
.get(&cursor.id)
.map(|files| {
files
.iter()
.map(|path| path.to_vec_str())
.collect::<Vec<_>>()
})
.and_then(|files| {
files
.is_empty()
.not()
.then_some(serde_json::to_string(&files).unwrap())
});
self.render_for_func(renderer, &ty_name, &return_ty_name, props, input_files)?;
ty_name
}
TypeNode::Object { data, base } => {
Expand Down
Loading

0 comments on commit 0081436

Please sign in to comment.