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

Run scripts from the location they are saved in, instead of the destination of the softlink. #66

Open
masasin opened this issue May 19, 2022 · 3 comments

Comments

@masasin
Copy link

masasin commented May 19, 2022

Feature description

When I run python, I use a virtual environment located inside the Tasker folder. However, the Python binaries there are actually softlinks to the system Python. Running them from inside the folder adds the virtual environment's packages to the python path, but running it from outside doesn't give you access to those packages.

Right now, when I need to run from inside a virtual environment, I import sys and add the library path to it. It happened so often that I just made a task that does that and pastes in the rest of the code into an empty file that I then run.

@agnostic-apollo
Copy link
Member

Which version are you using?

Symlink file path is used instead of target path because some utils don't work if target path is used. Will have to add another option to disable the behaviour. I don't really understand your setup from the info provided to suggest alternatives.

https://github.com/termux/termux-tasker/blob/v0.6.0/app/src/main/java/com/termux/tasker/FireReceiver.java#L156

termux/termux-app@cce6dfe

@masasin
Copy link
Author

masasin commented Aug 27, 2022

I'm using 0.6.0.

This is my setup:

Screenshot_20220827-150102_TermuxTasker.jpg

I have python installed system-wide, and I created a venv folder for tasker stuff because I don't want to install e.g. numpy or arrow globally.

If I run it directly (e.g., with -c "print('hello world')"), it does not have access to any of the packages in the venv. If I run it on a file, it's the same problem.

What I ended up doing is this:

Screenshot_20220827-150509_Tasker.jpg

Right before running anything, I add the venv path to the sys path.

Screenshot_20220827-150524_Tasker.jpg

Adding the toggle would make it possible to simplify things by allowing me to run certain things directly, but it works fine in this configuration too, so there's no rush for me.

@agnostic-apollo
Copy link
Member

agnostic-apollo commented Aug 27, 2022

Why not just create wrapper script at ~/.termux/tasker/venv-exec and call that with plugin.

#!/usr/bin/bash

exec env VIRTUAL_ENV=~/.termux/tasker/venv python "$@"

https://stackoverflow.com/questions/48174599/is-there-a-single-line-way-to-run-a-command-in-a-python-venv

p.s I don't have any experience with python virtual environments.

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

No branches or pull requests

3 participants
@masasin @agnostic-apollo and others