0

Invoke seems to be clever enough that I can be in any subdirectory and call an invoke task. However I'm wondering how to ensure that the tasks run the same way without a lot of path massaging.

So for example, my structure is

code/
code/server/
code/tasks/build.py

I usually run inv build.test from the code/ directory which then does the following:

    with c.cd('server/'):
        c.run('python manage.py test')

However if I'm in code/server/ I can also run inv build.run and while it's nice that it finds the task definition, obviously it fails because it can't cd server/.

Is there a clean way to handle this other than splicing paths together?

  • 1
    I would look at info in this link, and use the full directory path for the build.py file and then "cd /../server" https://stackoverflow.com/questions/50499/how-do-i-get-the-path-and-name-of-the-file-that-is-currently-executing – Kory Gill Dec 09 '21 at 01:17
  • @KoryGill thanks. So invoke has kind of a root location and I'm not sure how to access that. So if I'm in `code/server`, I'm looking for a command to return `code/` which is the "root directory" (looking for a command that returns it in a non hardcoded way) but `__file__` returns `code/server/build.py` and `os.cwd` returns `code/server/` neither of which is the invoke __root__. – Shimona Carvalho Dec 09 '21 at 19:57
  • from the `__file__` path, don't you know that code/ is always 2 directories up? like "__file__/../.." – Kory Gill Dec 09 '21 at 21:21
  • Yeah, that's what I've done, but I was hoping the `invoke` package had something specific because it does provide settings to change that root so I was hoping they'd exposed it in their package in some way. This works for now though, and i'm asking in their github as well. – Shimona Carvalho Dec 09 '21 at 23:50

0 Answers0