nat-n / poethepoet

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

poe crash when spawning tasks using "pipx run poetry run" and "poetry" is not in the PATH #99

Closed darkvertex closed 1 year ago

darkvertex commented 1 year ago

I think there's a little bug in how the poetry executable is detected or something.

My pyproject.toml has this block:

[tool.poe.tasks]
server = "uvicorn app:app --reload --port 8500 --host 0.0.0.0"

If I run pipx run poetry shell then run poe run server, it works.

If I try to run pipx run poetry run poe run server then it fails:

> pipx run poetry run poe server

Poe => uvicorn app:app --reload --port 8500 --host 0.0.0.0
Traceback (most recent call last):
  File "/home/alan/repos/redacted/backend/.venv/bin/poe", line 8, in <module>
    sys.exit(main())
  File "/home/alan/repos/redacted/backend/.venv/lib/python3.9/site-packages/poethepoet/__init__.py", line 32, in main
    result = app(cli_args=sys.argv[1:])
  File "/home/alan/repos/redacted/backend/.venv/lib/python3.9/site-packages/poethepoet/app.py", line 66, in __call__
    return self.run_task() or 0
  File "/home/alan/repos/redacted/backend/.venv/lib/python3.9/site-packages/poethepoet/app.py", line 97, in run_task
    return self.task.run(context=context, extra_args=self.ui["task"][1:])
  File "/home/alan/repos/redacted/backend/.venv/lib/python3.9/site-packages/poethepoet/task/base.py", line 239, in run
    return self._handle_run(
  File "/home/alan/repos/redacted/backend/.venv/lib/python3.9/site-packages/poethepoet/task/cmd.py", line 50, in _handle_run
    return context.get_executor(self.invocation, env, self.options).execute(
  File "/home/alan/repos/redacted/backend/.venv/lib/python3.9/site-packages/poethepoet/executor/poetry.py", line 50, in execute
    return self._execute_cmd(
  File "/home/alan/repos/redacted/backend/.venv/lib/python3.9/site-packages/poethepoet/executor/base.py", line 154, in _execute_cmd
    return self._exec_via_subproc(cmd, input=input, env=env, shell=shell)
  File "/home/alan/repos/redacted/backend/.venv/lib/python3.9/site-packages/poethepoet/executor/base.py", line 206, in _exec_via_subproc
    proc = Popen(cmd, **popen_kwargs)
  File "/home/alan/pyenv/versions/3.9.12-rockylinux8/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/alan/pyenv/versions/3.9.12-rockylinux8/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'poetry'
nat-n commented 1 year ago

hi @darkvertex,

That's an interesting use case. I am able to reproduce this, but only if poetry is not actually installed in the environment.

From playing around with this a bit it appears that when running pipx run poetry run poe if poetry is not actually installed by any means other than the temporary venv used by pipx run, then it is not on the path, and there's nothing set on the environment (by either pipx or poetry) to make the venv containing poetry discoverable.

In this situation I don't know what poe could do better to discover the location of the poetry that is calling it (short of replicating the logic from pipx to speculatively search for a temporary venv for poetry — though I dunno about that).

I'm open to suggestions if you find something I've missed, but I think installing poetry via pipx install or the poetry install script is probably the best solution. Is there some reason you wouldn't want to do that?

Closing this as won't fix (unless further evidence points to a reasonable fix).