aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorDiogo <rossi.diogo@gmail.com>2024-08-23 17:59:31 -0300
committerGitHub <noreply@github.com>2024-08-23 23:59:31 +0300
commit7cfecafdbd84c0f25b8a6c09a4cef72616968917 (patch)
treea6ebb99681950915a503366cd4be1fc3c2e2ff0c /README.md
parentUpdate README.md (diff)
downloadtaskipy2-7cfecafdbd84c0f25b8a6c09a4cef72616968917.zip
Add option `cwd` to running tasks (#83)
* 🎨 chore: removing settings that are deprecated Reference: https://github.com/microsoft/vscode-python/wiki/Migration-to-Python-Tools-Extensions#existing-python-tools-extensions * 👷 build: add `.venv` folder to `.gitignore` * ✨ feat: new property 'workdir' for tasks * 🎨 chore: add "cwd" to error messages * ✨ feat: new property `dirpath` of `PyProject` * ✨ feat: new method to get workdir in `TaskRunner` * 🐞 fix: allow for absolute paths * 🐞 fix: the task cwd should takes precedence * 📄 docs: update `README.md` * Update README.md Co-authored-by: Roy Sommer <illBeRoy@users.noreply.github.com> * rename variable `working_dir` into `cwd_as_path` to emphasize what it's really used for suggestion: https://github.com/taskipy/taskipy/pull/83/files#r1676391148 * assert that `cwd` is a string, and throw if it's not * 👷 build: add settings to test in VSCode * 🐞 fix: add task exec when testing on windows * ✅ test: add new `SetCWDTestCase` * ✅ test: fix error message in test case * ✏️ typo: in fixture name * 💄 style: format code * Update settings.json --------- Co-authored-by: Roy Sommer <illBeRoy@users.noreply.github.com>
Diffstat (limited to 'README.md')
-rw-r--r--README.md23
1 files changed, 23 insertions, 0 deletions
diff --git a/README.md b/README.md
index a6d3f7b..a0a739e 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,7 @@
- [String Formatting](#string-formatting)
- [Always Use Variables](#always-use-variables)
- [Recursive Variables](#recursive-variables)
+ - [Working directory](#working-directory)
- [Using Taskipy Without Poetry](#using-taskipy-without-poetry)
- [Installing With PIP](#installing-with-pip)
- [Running Tasks](#running-tasks-1)
@@ -282,6 +283,28 @@ echo = "echo {package_dir}"
In this example, we could run `task echo` and we would then see `src/package`.
+### Working directory
+
+By default, all tasks run from the directory where they are called. This makes possible to change folder and run flexible tasks depending on the current folder.
+
+However, some tasks may need to always run in the same working directory, regardless from where they are called.
+
+If you want tasks to always run relative to a specific path, you can use the `"cwd"` setting to define a current working directory of the task relative to the root of the project (where the `pyproject.toml` file is):
+
+```toml
+[tool.taskipy.tasks]
+echo = { cmd = "python -c \"import os; print(os.getcwd())\"" , cwd = "."}
+```
+
+In this example, running `task echo` will print the directory path of the file `pyproject.toml` regardless of the folder that you call this task.
+
+If you want to define `cwd` globally (setting all tasks to always run from the same working directory) you just need to declare that under taskipy's **settings** table:
+
+```toml
+[tool.taskipy.settings]
+cwd = "."
+```
+
### Using Taskipy Without Poetry
Taskipy was created with poetry projects in mind, but actually only requires a valid `pyproject.toml` file in your project's directory. As a result, you can use it even without poetry: