Skip to content

Commit

Permalink
Pre-commit and start implement >= <=
Browse files Browse the repository at this point in the history
  • Loading branch information
joaander committed May 13, 2024
1 parent 801e616 commit 4627d60
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 68 deletions.
2 changes: 1 addition & 1 deletion doc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
- [Advanced topics]()
- [Submit the same action to different groups/resources]()
- [Use an action to summarize many directories]()

# Reference

- [row](row/index.md)
Expand Down
2 changes: 1 addition & 1 deletion doc/src/workflow/action/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ walltime.per_submission = "04:00:00"
action, which may be set by [from](#from).

> Note: Two (or more) conceptually identical elements in the actions array may have
> the same name. All elements with the same name **must** have identical
> the same name. All elements with the same name **must** have identical
> [`products`](#products) and [`previous_actions`](#previous_actions). All elements
> with the same name **must also** select non-intersecting subsets of directories with
> [`group.include`](group.md#include).
Expand Down
55 changes: 51 additions & 4 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,14 @@ pub(crate) fn evaluate_json_comparison(
) -> Option<bool> {
#[allow(clippy::match_same_arms)]
match (comparison, partial_cmp_json_values(a, b)) {
(Comparison::LessThan, Some(Ordering::Less)) => Some(true),
(Comparison::LessThanOrEqualTo, Some(Ordering::Less | Ordering::Equal)) => Some(true),
(Comparison::EqualTo, Some(Ordering::Equal)) => Some(true),
(Comparison::GreaterThanOrEqualTo, Some(Ordering::Greater | Ordering::Equal)) => Some(true),
(Comparison::GreaterThan, Some(Ordering::Greater)) => Some(true),
(Comparison::LessThan, Some(Ordering::Less)) => Some(true),
(_, None) => None,
(_, _) => Some(false),
}

// TODO: Greater than or equal to
// TODO: Less than or equal to
}

#[cfg(test)]
Expand Down Expand Up @@ -166,6 +165,22 @@ mod tests {
evaluate_json_comparison(&Comparison::EqualTo, &Value::from(5), &Value::from(5)),
Some(true)
);
assert_eq!(
evaluate_json_comparison(
&Comparison::GreaterThanOrEqualTo,
&Value::from(5),
&Value::from(5)
),
Some(true)
);
assert_eq!(
evaluate_json_comparison(
&Comparison::LessThanOrEqualTo,
&Value::from(5),
&Value::from(5)
),
Some(true)
);
assert_eq!(
evaluate_json_comparison(&Comparison::EqualTo, &Value::from(5), &Value::from(10)),
Some(false)
Expand All @@ -174,9 +189,41 @@ mod tests {
evaluate_json_comparison(&Comparison::GreaterThan, &Value::from(5), &Value::from(10)),
Some(false)
);
assert_eq!(
evaluate_json_comparison(
&Comparison::GreaterThanOrEqualTo,
&Value::from(5),
&Value::from(10)
),
Some(false)
);
assert_eq!(
evaluate_json_comparison(
&Comparison::GreaterThanOrEqualTo,
&Value::from(6),
&Value::from(5)
),
Some(true)
);
assert_eq!(
evaluate_json_comparison(&Comparison::LessThan, &Value::from(5), &Value::from(10)),
Some(true)
);
assert_eq!(
evaluate_json_comparison(
&Comparison::LessThanOrEqualTo,
&Value::from(5),
&Value::from(10)
),
Some(true)
);
assert_eq!(
evaluate_json_comparison(
&Comparison::LessThanOrEqualTo,
&Value::from(5),
&Value::from(4)
),
Some(false)
);
}
}
2 changes: 1 addition & 1 deletion src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ previous_actions = ["two"]
);

let mut action = project.workflow.action[1].clone();
let include = &mut action.group.include.as_mut().unwrap();
let include = action.group.include.as_mut().unwrap();
include.push(("/i".into(), Comparison::GreaterThan, Value::from(4)));
assert_eq!(
project
Expand Down
17 changes: 11 additions & 6 deletions src/scheduler/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ export ACTION_NAME="{}"
export ACTION_PROCESSES="{}"
export ACTION_WALLTIME_IN_MINUTES="{}"
"#,
self.cluster_name, self.action.name(), self.total_processes, self.walltime_in_minutes,
self.cluster_name,
self.action.name(),
self.total_processes,
self.walltime_in_minutes,
);

if let Processes::PerDirectory(processes_per_directory) = self.action.resources.processes() {
if let Processes::PerDirectory(processes_per_directory) = self.action.resources.processes()
{
let _ = writeln!(
result,
"export ACTION_PROCESSES_PER_DIRECTORY=\"{processes_per_directory}\"",
Expand Down Expand Up @@ -322,8 +326,8 @@ mod tests {
threads_per_process: Some(4),
gpus_per_process: Some(1),
walltime: Some(Walltime::PerSubmission(
Duration::new(true, 0, 240, 0).expect("Valid duration.")),
),
Duration::new(true, 0, 240, 0).expect("Valid duration."),
)),
};

let action = Action {
Expand Down Expand Up @@ -505,8 +509,9 @@ mod tests {
fn more_variables() {
let (mut action, directories, launchers) = setup();
action.resources.processes = Some(Processes::PerSubmission(10));
action.resources.walltime =
Some(Walltime::PerDirectory(Duration::new(true, 0, 60, 0).expect("Valid duration.")));
action.resources.walltime = Some(Walltime::PerDirectory(
Duration::new(true, 0, 60, 0).expect("Valid duration."),
));
action.resources.threads_per_process = None;
action.resources.gpus_per_process = None;

Expand Down
Loading

0 comments on commit 4627d60

Please sign in to comment.