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

Skip PoetryExecutor if poetry is not found #175

Merged
merged 3 commits into from
Nov 4, 2023

Conversation

kzrnm
Copy link
Contributor

@kzrnm kzrnm commented Oct 17, 2023

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 kzrnm changed the base branch from main to development October 17, 2023 10:19
@kzrnm kzrnm changed the base branch from development to main October 17, 2023 11:17
@kzrnm kzrnm changed the base branch from main to development October 17, 2023 11:22
Copy link
Owner

@nat-n nat-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @kzrnm , I'm curious to know more about your use case for this? Though I guess this behaviour makes sense if you have a project with a poetry managed local venv, but just don't have poetry somewhere discoverable for whatever reason.

Though I think falling back to the simple executor could be surprising.

poethepoet/executor/poetry.py Outdated Show resolved Hide resolved
poethepoet/executor/base.py Outdated Show resolved Hide resolved
@kzrnm
Copy link
Contributor Author

kzrnm commented Oct 18, 2023

# 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.

Popen(
(self._poetry_cmd(), "env", "info", "-p"),
stdout=PIPE,
cwd=self.context.config.project_dir,
env=clean_env,
)

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;

Copy link
Owner

@nat-n nat-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. I'm happy to merge this once we work out what's going on with the tests.

Although maybe it could still be improved:

I wonder if it would be a good idea to log a warning when poe fallback to the SimpleExecutor in a poetry governed project because the poetry executable can't be found.

Alternatively I wonder if it would be better still if poe were to specifically check for poetry at $APPDATA/pypoetry/venv/Scripts/poetry if running on windows and poetry doesn't show up on the path?

@kzrnm
Copy link
Contributor Author

kzrnm commented Nov 4, 2023

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

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

@nat-n nat-n merged commit ed26886 into nat-n:development Nov 4, 2023
16 checks passed
@kzrnm kzrnm deleted the fix/poetry branch November 4, 2023 10:25
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

Successfully merging this pull request may close these issues.

2 participants