Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tasks: pickup outgoing task dependencies #1573

Merged
merged 13 commits into from
Nov 25, 2024
60 changes: 54 additions & 6 deletions devenv-tasks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ impl Tasks {
}
}

for (dep_idx, idx) in edges_to_add {
self.graph.add_edge(dep_idx, idx, ());
for (from, to) in edges_to_add {
self.graph.update_edge(from, to, ());
}

if unresolved.is_empty() {
Expand Down Expand Up @@ -479,10 +479,7 @@ impl Tasks {
node_map.insert(node, new_node);

// Add dependencies to visit
for neighbor in self
.graph
.neighbors_directed(node, petgraph::Direction::Incoming)
{
for neighbor in self.graph.neighbors_undirected(node) {
to_visit.push(neighbor);
}
}
Expand Down Expand Up @@ -1196,6 +1193,57 @@ mod test {
Ok(())
}

#[tokio::test]
async fn test_before_and_after_tasks() -> Result<(), Error> {
let script1 = create_script(
"#!/bin/sh\necho 'Task 1 is running' && sleep 0.5 && echo 'Task 1 completed'",
)?;
let script2 = create_script(
"#!/bin/sh\necho 'Task 2 is running' && sleep 0.5 && echo 'Task 2 completed'",
)?;
let script3 = create_script(
"#!/bin/sh\necho 'Task 3 is running' && sleep 0.5 && echo 'Task 3 completed'",
)?;

let tasks = Tasks::new(
Config::try_from(json!({
"roots": ["myapp:task_1"],
"tasks": [
{
"name": "myapp:task_1",
"command": script1.to_str().unwrap(),
},
{
"name": "myapp:task_3",
"after": ["myapp:task_1"],
sandydoo marked this conversation as resolved.
Show resolved Hide resolved
"command": script3.to_str().unwrap()
},
{
"name": "myapp:task_2",
"before": ["myapp:task_3"],
"after": ["myapp:task_1"],
"command": script2.to_str().unwrap()
},
]
}))
.unwrap(),
)
.await?;
tasks.run().await;

let task_statuses = inspect_tasks(&tasks).await;
let task_statuses = task_statuses.as_slice();
assert_matches!(
task_statuses,
[
(name1, TaskStatus::Completed(TaskCompleted::Success(_, _))),
(name2, TaskStatus::Completed(TaskCompleted::Success(_, _))),
(name3, TaskStatus::Completed(TaskCompleted::Success(_, _)))
] if name1 == "myapp:task_1" && name2 == "myapp:task_2" && name3 == "myapp:task_3"
);
Ok(())
}

#[tokio::test]
async fn test_dependency_failure() -> Result<(), Error> {
let failing_script = create_script("#!/bin/sh\necho 'Failing task' && exit 1")?;
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ list of string



Whether to include the Flutter tools.
Whether to include the React Native tools.



Expand Down
11 changes: 5 additions & 6 deletions src/modules/languages/python.nix
Original file line number Diff line number Diff line change
Expand Up @@ -459,25 +459,24 @@ in
description = "Initialize Python virtual environment";
exec = initVenvScript;
exports = [ "PATH" "VIRTUAL_ENV" ];
after = [ "devenv:enterShell" ];
sandydoo marked this conversation as resolved.
Show resolved Hide resolved
};

"devenv:python:poetry" = lib.mkIf cfg.poetry.install.enable {
description = "Initialize Poetry";
exec = initPoetryScript;
exports = [ "PATH" ] ++ lib.optional cfg.poetry.activate.enable "VIRTUAL_ENV";
after = lib.optional cfg.venv.enable "devenv:python:virtualenv";
after = [ "devenv:enterShell" ];
before = lib.optional cfg.venv.enable "devenv:python:virtualenv";
};

"devenv:python:uv" = lib.mkIf cfg.uv.sync.enable {
description = "Initialize uv sync";
exec = initUvScript;
exports = [ "PATH" ];
after = lib.optional cfg.venv.enable "devenv:python:virtualenv";
after = [ "devenv:enterShell" ];
before = lib.optional cfg.venv.enable "devenv:python:virtualenv";
};

"devenv:enterShell".after = lib.optional cfg.venv.enable "devenv:python:virtualenv"
++ lib.optional cfg.poetry.install.enable "devenv:python:poetry"
++ lib.optional cfg.uv.sync.enable "devenv:python:uv";
};

enterShell = ''
Expand Down