nat-n / poethepoet

A task runner that works well with poetry.
https://poethepoet.natn.io/
MIT License
1.39k stars 56 forks source link

Skip PoetryExecutor if poetry is not found #175

Closed kzrnm closed 9 months ago

kzrnm commented 10 months ago

poe cannot run PoetryExecutor if poetry is set as an alias instead of $PATH.

I want to skip PoetryExecutor when poetry is not found.

kzrnm commented 10 months ago
# Microsoft.PowerShell_profile.ps1
Set-Alias poetry "${env:APPDATA}\pypoetry\venv\Scripts\poetry.exe"

I use poetry via alias on PowerShell, so that python interpreter cannot find poetry command and raise FileNotFoundError at PoetryExecutor.

https://github.com/nat-n/poethepoet/blob/903ed9af0dd313a6da32f24ec4357101435976d8/poethepoet/executor/poetry.py#L80-L85

SimpleExecutor work properly.

In poetry run, poetry adds its venv directory to the $PATH of the subprocess.

Example

Git bash,

virtualenvs.in-project = true

[tool.poe.tasks.env]
shell = "/usr/bin/env | /usr/bin/grep ^PATH="
$ env PATH="" $APPDATA/pypoetry/venv/Scripts/poetry run poe env
Poe => /usr/bin/env | /usr/bin/grep ^PATH=
PATH=/mingw64/bin:/usr/bin:/c/Users/kzrnm/bin:/z/poethepoet/.venv/Scripts

PowerShell

virtualenvs.in-project = false

[tool.poe.tasks.env]
shell = "(dir Env:PATH).Value"
PS> $env:PATH=""
PS> & "$env:APPDATA/pypoetry/venv/Scripts/poetry" run poe env
Poe => (dir Env:PATH).Value
C:\Program Files\PowerShell\7;C:\Users\kzrnm\AppData\Local\pypoetry\Cache\virtualenvs\poethepoet-zPZo9g_N-py3.9\Scripts;
kzrnm commented 9 months ago

@nat-n I updated fix/poetry to the latest.

i don't know why, but CI have worked.