Skip to content

Commit

Permalink
fix lint warning
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Dec 27, 2024
1 parent 5dae5fe commit 7acb82b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
23 changes: 9 additions & 14 deletions dev/src/generate/binding_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use crate::generate::parser::Services;
use anyhow::Result;
use askama::Template;
use itertools::Itertools;
use std::fs;
use std::path::PathBuf;
use std::process::Command;
use std::{fs, iter}; // bring trait in scope

use super::parser::{ConfigType, Service};

Expand Down Expand Up @@ -49,7 +49,7 @@ pub fn generate(project_root: PathBuf, services: &Services) -> Result<()> {
.filter(|x| enabled_service(x.0.as_str())),
);

for mut srv in &mut v {
for srv in &mut v {
srv.1.config = srv
.1
.config
Expand All @@ -63,12 +63,6 @@ pub fn generate(project_root: PathBuf, services: &Services) -> Result<()> {

let tmpl = PythonTemplate { services: v };

// for (srv, config) in services.clone().into_iter() {
// for f in config.config {
// f.deprecated.is_some()
// }
// }

let t = tmpl.render().expect("should render template");

let output_file: String = project_root
Expand All @@ -82,7 +76,8 @@ pub fn generate(project_root: PathBuf, services: &Services) -> Result<()> {
Command::new("ruff")
.arg("format")
.arg(output_file)
.output()?;
.output()
.expect("failed to run ruff");

Ok(())
}
Expand All @@ -91,23 +86,23 @@ impl ConfigType {
pub fn python_type(&self) -> String {
match self {
ConfigType::Bool => {
return "_bool".into();
"_bool".into()
}
ConfigType::Duration => {
return "_duration".into();
"_duration".into()
}
ConfigType::I64
| ConfigType::Usize
| ConfigType::U64
| ConfigType::U32
| ConfigType::U16 => {
return "_int".into();
"_int".into()
}
ConfigType::Vec => {
return "_strings".into();
"_strings".into()
}
ConfigType::String => {
return "str".into();
"str".into()
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions dev/src/generate/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl ServiceParser {

let mut config = Vec::with_capacity(config_struct.fields.len());
for field in config_struct.fields {
let field = self.parse_field(field)?;
let field = Self::parse_field(field)?;
config.push(field);
}

Expand All @@ -192,13 +192,13 @@ impl ServiceParser {
}

/// TODO: Add comment parse support.
fn parse_field(&self, field: Field) -> Result<Config> {
fn parse_field(field: Field) -> Result<Config> {
let name = field
.ident
.clone()
.ok_or_else(|| anyhow!("field name is missing for {:?}", &field))?;

let deprecated = self.deprecated_note(&field);
let deprecated = Self::deprecated_note(&field);

let (cfg_type, optional) = match &field.ty {
Type::Path(TypePath { path, .. }) => {
Expand Down Expand Up @@ -246,7 +246,7 @@ impl ServiceParser {
})
}

fn deprecated_note(&self, field: &Field) -> Option<String> {
fn deprecated_note(field: &Field) -> Option<String> {
for attr in &field.attrs {
if !attr.path().is_ident("deprecated") {
continue;
Expand All @@ -261,9 +261,7 @@ impl ServiceParser {
for (index, token) in tokens.iter().enumerate() {
let ident = match token {
proc_macro2::TokenTree::Ident(ident) => ident,
_ => {
continue;
}
_ => continue,
};

if ident == "note" {
Expand All @@ -277,7 +275,7 @@ impl ServiceParser {
}
}

return None;
None
}
}

Expand Down

0 comments on commit 7acb82b

Please sign in to comment.