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

espanso will only use system-installed interpreters #1950

Open
Rustplicant opened this issue Apr 16, 2024 · 6 comments
Open

espanso will only use system-installed interpreters #1950

Rustplicant opened this issue Apr 16, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@Rustplicant
Copy link

Rustplicant commented Apr 16, 2024

Description

Hi there, is there a way to make espanso use a different Python version installed in the system?
I'm using pyenv in both macOS and Linux to set latest Python version globally, and espanso stubbornly keeps using system-installed version.
In my use case, setting absolute path in the script extension is really not preferred, as I'm syncing the match folder and its content between Windows, macOS, and Linux systems.

EDIT:
It seems that this also affects shell extension, as I have PowerShell 7.4 installed in my Windows machine.
In Windows, possible values for the shell parameter are cmd, powershell, wsl. Defining powershell will simply use the out-of-the-box PowerShell version 5.1.
Defining pwsh as value will simply output this error:

[WARN] extension 'shell' on var: 'varPwsh' reported an error: invalid shell: `pwsh` is not a valid one

Is there a way to define absolute path of the interpreter as variables, perhaps in default.yml, so one can maintain consistent matches files across different platforms?

@Rustplicant Rustplicant added the bug Something isn't working label Apr 16, 2024
@Rustplicant Rustplicant changed the title espanso will only use system-installed Python version espanso will only use system-installed interpreters Apr 17, 2024
@smeech
Copy link
Collaborator

smeech commented Apr 17, 2024

I think Pwsh as a shell is coming to Windows. I have it working on Linux, and it appears in the dev branch code alongside the other Windows alternatives.

A workaround for Python for now may be to define a global variable for the interpreter path, depending on the OS. E.g.:

global_vars:
  - name: python # Linux
    type: echo
    params:
      echo: /usr/bin/python

for use in expansions:

  - trigger: :test
    replace: "{{output}}"          
    vars:
      - name: output
        type: script
        params:
          args: ["{{python}}", -c, print("something")]

or

          args: ["{{python}}", /path/to/your/script.py]

for example. But, I can see, one still has to use the absolute path, so that may not help.
Do you need multiple versions of Python on your system?
I suppose you could add pyenv to Windows too, and read it into a global_var using a script on all OSs, with something like:

import os; print(os.path.join(os.getenv("PYENV_ROOT"), "shims", "python"))

?

@Rustplicant
Copy link
Author

Thanks for the reply, smeech!

Using global variable is indeed my current workaround. Was just wondering if we can set it up outside the matches entirely, as I'm syncing the matches files between platforms.
Your proposed solution using script and read it into global_vars might just be able to solve this issue, I'll look into this.
Thanks again!

@smeech
Copy link
Collaborator

smeech commented Apr 18, 2024

Ideally one would be able to use filter_os: app-specific configurations, but as only one app-specific configuration can be active at any time it would involve rewriting all you're already using to combine them with filter_os:.

@AucaCoyan AucaCoyan added enhancement New feature or request and removed bug Something isn't working labels Apr 25, 2024
@AucaCoyan
Copy link
Member

Mmmmmmm. This hack works, but is the definitive solution we want?
It's difficult to achieve a perfect solution here. Python have normally a lot of interpreters, and compiling its own python version is a common task in the ecosystem. What could be done in order to make this easier for users?
One possible solution would be add a line in config.yml called python_interpreter or so. I'm not seeing very good having to specify the python interpreter on each match and passing it to the engine.
What do you think? and another more difficult question: how do we manage libraries? (venvs)

@smeech
Copy link
Collaborator

smeech commented Apr 25, 2024

It's not ideal, but it's for a fairly narrow use-case, where someone wants to use a different version than the system standard version, without hard-coding the path (in order to use it across OSs). Unless this is easy to implement, it's unlikely to happen.

@AucaCoyan
Copy link
Member

AucaCoyan commented Apr 25, 2024

Yeah, I would be happy with this hack, but it's not recommended to use the OS default python, especially in Linux environments.
Probably I'm over estimating the importance of this issue, but to use the OS python is something I try very hard not to do.

I'm happy with agreeing a solution and move it to the prioritization queue (the project board). It will be done when it's ready 🚀

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

No branches or pull requests

3 participants