Add option `cwd` to running tasks
TL;DR:
Implements #81
Following the suggestion of @illBeRoy:
- Be able to define CWD globally via:
[tool.taskipy.settings] cwd = "."
- Be able to define it per command:
[tool.taskipy.tasks] lint = { cmd = "pylint", cwd = '.' }Where:
- If CWD is defined both globally and per a specific task, the one on the task takes precedence
- CWD allows for relative paths
Tested running tasks from folder ./vscode with the following tasks:
[tool.taskipy.tasks]
pwdroot = { cmd = "python -c \"import os; print(os.getcwd())\"" , cwd = "."}
pwdtest = { cmd = "python -c \"import os; print(os.getcwd())\"" , cwd = "./tests"}
pwddocs = { cmd = "python -c \"import os; print(os.getcwd())\"" , cwd = "./docs"}
pwderro = { cmd = "python -c \"import os; print(os.getcwd())\"" , cwd = "./non_existent_folder"}
pwdabs = { cmd = "python -c \"import os; print(os.getcwd())\"" , cwd = "C:/Users"}
Which results are:
❯ task pwdroot
C:\Users\user\Repos\taskipy
❯ task pwdtest
C:\Users\user\Repos\taskipy\tests
❯ task pwddocs
C:\Users\user\Repos\taskipy\docs
❯ task pwderro
C:\Users\user\Repos\taskipy\.vscode
❯ task pwdabs
C:\Users
I'm still writing tests. They will be ready very soon!
@illBeRoy Done!
Thank you! Will try to review asap.
seems like some tests are failing. can you please take a look?
seems like some tests are failing. can you please take a look?
Ok!
seems like some tests are failing. can you please take a look?
Sorry, but I took a look in the tests: I only introduced 3 tests in a test case, and they seem to be passing:
Oh, I just saw the failing test: it is related to the error message, which has changed.
self.assertSubstr('tasks must be strings, or dicts that contain { cmd, cwd, help, use_vars }', stdout)
I'll fix that.
It seems like lint check is failing now. It's mostly over whitespaces so seems like this could be easily fixed.
Once you're done, you can try running poetry run task test locally and see that everything works as expected :)
It seems like lint check is failing now. It's mostly over whitespaces so seems like this could be easily fixed. Once you're done, you can try running
poetry run task testlocally and see that everything works as expected :)
I'm getting this error:
ModuleNotFoundError: No module named 'tests/test_*'
Ok, I just fixed the spaces issue and run local tests manually with task lint_pylint and task lint_mypy, the results are bellow.
OBS:
I could not use task lint because it was not recognized by my shell.
(Maybe because I'm on Windows, with a PowerShell terminal?).
Anyway, the task test command (or poetry run task test command) also did not worked, as said before. It is giving error when importing the module:
❯ task test
tests/test_* (unittest.loader._FailedTest.tests/test_*) ... ERROR
======================================================================
ERROR: tests/test_* (unittest.loader._FailedTest.tests/test_*)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests/test_*
Traceback (most recent call last):
File "[...]\Lib\unittest\loader.py", line 137, in loadTestsFromName
module = __import__(module_name)
^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'tests/test_*'
Is it correct to run the tests with this pattern tests/test_*? I did not find it on the docs.
pylint results
❯ task lint_pylint
************* Module D:\Repos\taskipy\.pylintrc
.pylintrc:1:0: E0015: Unrecognized option found: missing-module-docstring (unrecognized-option)
.pylintrc:1:0: R0022: Useless option value for '--disable', 'R0201' was moved to an optional extension, see https://pylint.readthedocs.io/en/latest/whatsnew/2/2.14/summary.html#removed-checkers. (useless-option-value)
mypy results
❯ task lint_mypy
tests\test_taskipy.py:24: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs [annotation-unchecked]
Success: no issues found in 18 source files
Anyway, the task test command (or poetry run task test command) also did not worked, as said before. It is giving error when importing the module:
Interesting. Maybe this is because in unix systems, globs are resolved before they're passed into the receiving process and on Windows this is not the case.
I'll take a look about best practices with running entire test directories using unittest.
Anyways, seem like the CI is passing! Great job mate :) I'll try to review today \ tomorrow at the latest.
Thanks again for taking the time to contribute!
Hey! Just letting you know that I haven't forgotten about this PR. Just swamped with work. Will try to get it done by Sunday :)
Hey team! I would love to use this feature. However I don't think a release has been published with this yet.
(For now I'm just using the package from git directly):
uv add git+https://github.com/taskipy/taskipy
Hi @stevenschmatz ! We just released version 1.14.0 including this feature. You can move back to the official pypi version now :)