Run tasks relative to `tasks.py`
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Reproduce the invoke serve-docs and invoke --list commands from the project root and from docs or src, using the tasks.py example and its ctx.run() call. Read the task runner's handling of the current working directory and ctx.cd(). Done means tasks can consistently run relative to tasks.py, or the task can reliably determine that location.
Written by the indexing model from the issue text.
Description
Is there a way to have a consistent initial working directory when running tasks?
In my tasks.py file, I have a task to serve sphinx documentation with sphinx-autobuild:
from invoke import task, Context
@task
def serve_docs(ctx: Context):
ctx.run("sphinx-autobuild ./docs/source/ ./docs/build/html --watch ./src/")
If I run this task from the project root (where tasks.py is) using invoke serve-docs, then it works fine. However, if I change directory into docs or src or any other directory in my project and run the same command invoke serve-docs, it fails since this command only works from the project root.
I expected that tasks always run with the project root as the initial working directory, which can be changed in the tasks with ctx.cd(), but it seems the initial working directory is the current working directory in the command line. I find that more confusing than helpful, especially since invoke --list still works and displays all the available tasks even if I am not in the project root near the tasks.py file. Since invoke --list works from any subdirectory of the project and I can also run tasks from any subdirectory, I would expect that the tasks will be ran with the same working directory so I get consistent results regardless of where I run the task from.
Is there a configuration option to make tasks run relative to tasks.py regardless of where I execute invoke from. If not, is there a way to make the task itself aware of the location tasks.py so I can execute commands relative to it?
- Dominant language
- Python
- Stars
- 4.8k
- Forks
- 412
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pyinvoke/invoke
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100