From 7cfecafdbd84c0f25b8a6c09a4cef72616968917 Mon Sep 17 00:00:00 2001 From: Diogo Date: Fri, 23 Aug 2024 17:59:31 -0300 Subject: Add option `cwd` to running tasks (#83) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🎨 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 * 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 --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'README.md') 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: -- cgit v1.2.3