pydoit / doit

CLI task management & automation tool
http://pydoit.org
MIT License
1.84k stars 175 forks source link

Per Task Working Directory #467

Closed dstadelm closed 3 months ago

dstadelm commented 3 months ago

In some cases it would be desirable to define the working directory of a task. E.g. run cmake in a subdirectory.

What I imagine:

def task_build_sw():
    return {
        "file_dep": ["sw/module/CMakeLists.txt"],
        "actions": ["cmake -S . -B build"],
        "working_dir": ["sw/module"],
}

Alternatives The current example is not to good, as with cmake we could provide the path. But there are other programs that will not work if not called in the supposed directory. For those one can of course change to that directory in the action, but I personally find that cumbersome, because it clutters the actual action.

def task_build_sw():
    return {
        "file_dep": ["sw/module/CMakeLists.txt"],
        "actions": ["cd sw/module; cmake -S . -B build"],
}

This issue is also somewhat a test to see how active the doit project still is, as the last commit is already quite a while. Of course this could be due to impeccable source code šŸ˜

Upvote & Fund

Fund with Polar

schettino72 commented 3 months ago

hey. source code is not impeccable but quite stable. said that there is a release due for some time already... I am trying to find time for that...

This per task "current working directory" should be on FAQ. The problem is that each process can have only ONE current directory. So that is not thread-safe or other (ie. async) mechanism for parallelization.

If you want to do that at your own risk it is easy enough to do user land.

If you explicitly import CmdAction [1], you can use underlying cwd parameter provided by subprocess module.

[1] https://pydoit.org/tasks.html#cmd-action

dstadelm commented 2 months ago

Hey, there! Thank you for your fast response. It is really good to see that the project is alive and kicking!

I just assumed that you use something like popen or similar to run cli commands. There it would be quite easy to pass the cwd. However I think I understand the problem if the action isn't an cmd but a python function. However maybe, as the tasks should be completely independent one could use processes for the task instead of threads. I've once done something similar in a other context using ruby.

I will admit this is all from a very distant observation, without knowing the internals of doit. So please let me apologize if what I am saying is complete nonsense.

I will look at CmdAction, but I think, currently the pain is too small for me to go that route.

Thanks again!