Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Add option to define running work directory #81

Open
Diogo-Rossi opened this issue Jun 16, 2024 · 12 comments
Open

[Feature request] Add option to define running work directory #81

Diogo-Rossi opened this issue Jun 16, 2024 · 12 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@Diogo-Rossi
Copy link

Diogo-Rossi commented Jun 16, 2024

If I have a task depending on a directory, as in the docs:

[tool.taskipy.tasks]
test = "python -m unittest tests/test_*.py"

If I run the command task test in a folder other than the project's root directory (lets say scr/)
it will raise an error, since the folder test/ won't be found.

This feature would allow to define a predefined work directory for the task.

It could be relative to the pyproject.toml's directory, maybe?

[tool.taskipy.settings]
cwd = "."

Is it feasible?

Thank you very much for this tool!

@kamajus3
Copy link
Contributor

If I have a task depending on a directory, as in the docs:

[tool.taskipy.tasks]
test = "python -m unittest tests/test_*.py"

If I run the command task test in a folder other than the project's root directory (lets say scr/) it will raise an error, since the folder test/ won't be found.

This feature would allow to define a predefined work directory for the task.

It could be relative to the pyproject.toml's directory, maybe?

[tool.taskipy.settings]
cwd = "."

Is it feasible?

Thank you very much for this tool!

I'm unsure about this feature because it can often be indispensable. Frequently, we need to use Taskipy in various directories such as scripts, src, tests, docs, etc. This largely depends on the project. For instance, if you aim to avoid repeating the same directory multiple times, you can utilize variables.

For example:

[tool.taskipy.variables]
path = "path/to/my_module"

[tool.taskipy.tasks]
lint = { cmd = "pylint {path}", use_vars = true }
black = { cmd = "black {path}", use_vars = true }

@Diogo-Rossi
Copy link
Author

Diogo-Rossi commented Jun 19, 2024

Thanks for the reply!

The thing is: Can "path/to/my_module" be relative, lets say, to pyproject.toml?

If not, I can not share that setting in a public repo. Am I right?

@kamajus3
Copy link
Contributor

Thanks for the reply!

The thing is: Can "path/to/my_module" be relative, lets say, to pyproject.toml?

If not, I can not share that setting in a public repo. Am I right?

Yeah the path It's always relative to your pyproject.toml file.

I mean where you declare the pyproject.toml file will be always your work directory.

@Diogo-Rossi
Copy link
Author

Yeah the path It's always relative to your pyproject.toml file.

I mean where you declare the pyproject.toml file will be always your work directory.

Sorry but, can you clarify? That is not what is happening here:

./
│ -  pyproject.toml
│
├───src/
└───tests/
        - myFile.txt
  1. I have this file myFile.txt which content is "Hello"

  2. And I have a pyproject.toml with the task:

[tool.taskipy.tasks]
test = "cat tests/myfile.txt"

It works ok when I'm in the root dir:

❯ task test
Hello!

But not when I in src, for instance:

❯ cd src
❯ task test
cat: ./tests/myfile.txt: No such file or directory

@kamajus3
Copy link
Contributor

@illBeRoy

@illBeRoy
Copy link
Collaborator

Hey @Diogo-Rossi ! That is actually a valid point and I think this would make a nice feature.

Based on your proposal, I think that following would make a great addition to taskipy:

  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

What do you think? Would you like to contribute this feature?

@Diogo-Rossi
Copy link
Author

@illBeRoy Thanks for considering!

What do you think? Would you like to contribute this feature?

I actually think that will be easy, because you already foresaw an argument cwd in this function:

taskipy/taskipy/cli.py

Lines 16 to 17 in 024933d

def run(args: List[str], cwd: Union[str, Path, None] = None) -> int:
"""Run the taskipy CLI programmatically.


But I found some issues in installing dependencies for the project.

By running poetry install (with and without the .lock file) I ended up with the following error:

  at ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\installation\chef.py:164 in _prepare
      160│
      161│                 error = ChefBuildError("\n\n".join(message_parts))
      162│
      163│             if error is not None:
    → 164│                 raise error from None
      165│
      166│             return path
      167│
      168│     def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:

Note: This error originates from the build backend, and is likely not a problem with poetry but with wrapt (1.13.3) not supporting PEP 517 builds. You can verify this by running 'pip 
wheel --no-cache-dir --use-pep517 "wrapt (==1.13.3)"'.

Do you know what am I doing wrong?

@illBeRoy
Copy link
Collaborator

I believe there's an issue with python 3.12 and one of the dev dependencies. I'll look into this

@illBeRoy
Copy link
Collaborator

seems like we needed to update pylint. I'm fixing this on #82

@illBeRoy
Copy link
Collaborator

solved. please pull master and try reinstalling

@illBeRoy illBeRoy self-assigned this Jun 24, 2024
@illBeRoy illBeRoy added the good first issue Good for newcomers label Jun 24, 2024
@Diogo-Rossi
Copy link
Author

It's working now, thanks @illBeRoy!

I'll work on the feature

@Diogo-Rossi
Copy link
Author

I ended up using another approach, since the run functions calls an internal object to manipulate tasks.
I created a new method:
https://github.com/taskipy/taskipy/pull/83/files#diff-10fcc779fd0cc5d4e11ffea1157dcd3bb4a7282fe8ae915d26b4227ef9181c4fR198-R210

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants