taskipy icon indicating copy to clipboard operation
taskipy copied to clipboard

Add option `cwd` to running tasks

Open diogo-rossi opened this issue 1 year ago • 12 comments

TL;DR:

Implements #81


Following the suggestion of @illBeRoy:

  1. Be able to define CWD globally via:
[tool.taskipy.settings]
cwd = "."
  1. Be able to define it per command:
[tool.taskipy.tasks]
lint = { cmd = "pylint", cwd = '.' }

Where:

  1. If CWD is defined both globally and per a specific task, the one on the task takes precedence
  2. 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

diogo-rossi avatar Jul 04 '24 01:07 diogo-rossi

I'm still writing tests. They will be ready very soon!

diogo-rossi avatar Jul 14 '24 04:07 diogo-rossi

@illBeRoy Done!

diogo-rossi avatar Jul 15 '24 02:07 diogo-rossi

Thank you! Will try to review asap.

illBeRoy avatar Jul 15 '24 08:07 illBeRoy

seems like some tests are failing. can you please take a look?

illBeRoy avatar Jul 15 '24 08:07 illBeRoy

seems like some tests are failing. can you please take a look?

Ok!

diogo-rossi avatar Jul 15 '24 12:07 diogo-rossi

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:

image

image

image

image

image

diogo-rossi avatar Jul 15 '24 12:07 diogo-rossi

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.

diogo-rossi avatar Jul 15 '24 12:07 diogo-rossi

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 :)

illBeRoy avatar Jul 16 '24 11:07 illBeRoy

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 :)

I'm getting this error:

ModuleNotFoundError: No module named 'tests/test_*'

diogo-rossi avatar Jul 16 '24 13:07 diogo-rossi

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

diogo-rossi avatar Jul 16 '24 13:07 diogo-rossi

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!

illBeRoy avatar Jul 16 '24 18:07 illBeRoy

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 :)

illBeRoy avatar Aug 01 '24 17:08 illBeRoy

Hey team! I would love to use this feature. However I don't think a release has been published with this yet.

stevenschmatz avatar Oct 20 '24 15:10 stevenschmatz

(For now I'm just using the package from git directly):

uv add git+https://github.com/taskipy/taskipy

stevenschmatz avatar Oct 20 '24 15:10 stevenschmatz

Hi @stevenschmatz ! We just released version 1.14.0 including this feature. You can move back to the official pypi version now :)

illBeRoy avatar Oct 23 '24 13:10 illBeRoy