Skip to content

Commit

Permalink
change deps format from list to dict
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-jianliang committed Sep 23, 2023
1 parent 57ab443 commit 0d6bed1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
12 changes: 5 additions & 7 deletions src/components/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,22 @@ pub struct Component {
}

impl Component {
pub fn from_py(py_obj: &PyAny) -> Result<ComponentID, PyErr> {
let name = py_obj.get_item("name")?.extract::<String>()?;
pub fn from_py(name: String, py_obj: &PyAny) -> Result<ComponentID, PyErr> {
let type_ = py_obj.get_item("type")?.extract::<String>()?;
let target_dir = py_obj.get_item("target_dir")?.extract::<String>()?;

let comp = match type_.as_str() {
"solution" => Component {
name,
name: name.clone(),
type_: ComponentType::Solution,
target_dir: target_dir.into(),
target_dir: name.into(),
parent_id: None,
children: Vec::new(),
impl_: Box::new(GitDependency::from_py(py_obj)?),
},
"git" => Component {
name,
name: name.clone(),
type_: ComponentType::GitDependency,
target_dir: target_dir.into(),
target_dir: name.into(),
parent_id: None,
children: Vec::new(),
impl_: Box::new(GitDependency::from_py(py_obj)?),
Expand Down
9 changes: 5 additions & 4 deletions src/utils/parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pyo3::prelude::*;
use pyo3::types::PyList;
use pyo3::types::PyDict;
use std::path::PathBuf;

use crate::components::component::{Component, ComponentID};
Expand All @@ -24,12 +24,13 @@ pub fn parse_components<'a>(
}
};

let py_objs: &PyList = module.getattr(var_name).unwrap().downcast().unwrap();
let py_objs: &PyDict = module.getattr(var_name).unwrap().downcast().unwrap();

let mut components = vec![];

for obj in py_objs.iter() {
let comp = Component::from_py(obj)?;
for (key, obj) in py_objs.iter() {
let name: String = key.to_string();
let comp = Component::from_py(name, obj)?;
components.push(comp);
}
log::debug!("Loaded components:\n{:#?}", components);
Expand Down

0 comments on commit 0d6bed1

Please sign in to comment.