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

interactive clients tend not to launch in poe #64

Open
gangofnuns opened this issue May 8, 2022 · 7 comments
Open

interactive clients tend not to launch in poe #64

gangofnuns opened this issue May 8, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@gangofnuns
Copy link

Hello --

I've been using poe to launch a few console tools written in shell recently.
It works!

However, I've noticed that when I run interactive tools like mysql or psql clients,
it fails to launch them, even in simple scenarios.

Is this a known issue? Curious if there might be a workaround.

Thanks for the tools! Cheers --

@ThatXliner
Copy link
Contributor

Maybe we could use pexpect for spawning stuff. It’s used by Poetry for the poetry shell command1. Here’s an example of pexpect: https://github.com/pexpect/pexpect/blob/master/examples/python.py

Footnotes

  1. https://github.com/python-poetry/poetry/blob/4838c9fe9645c62353be569a96765c693f03f1a3/src/poetry/utils/shell.py#L71

@gangofnuns
Copy link
Author

gangofnuns commented May 8, 2022 via email

@nat-n
Copy link
Owner

nat-n commented May 8, 2022

Hi @gangofnuns, thanks for the feedback.

I've encountered similar issues with this myself, but haven't quite gotten to the bottom of it.

What I know is that the following does give you an interactive REPL as expected:

[tool.poe.tasks.repl]
cmd = "python"

and the same works for script tasks:

# tasks.py

def repl():
    while True:
        print(eval(input(">>> ")))
# pyproject.toml

[tool.poe.tasks.repl]
script = "tasks:repl"

But it doesn't work for shell tasks:

[tool.poe.tasks.repl]
shell = "tasks:repl"

This is because shell tasks work by passing the task content into the shell executable via stdin – which is the most reliable cross shell/platform method I'm aware of, but does rule out directly interacting with processes inside the child shell via the terminal.

Are you encountering this issue specifically with shell tasks or is there something about some other tool that works differently with cmd tasks as well?

@ThatXliner I guess pexpect works by using a background thread to manage communication with the shell subprocess? I wouldn't rule out adopting it as an option for shell tasks specifically, though it's quite heavy weight and a bit complex, so I'm a little hesitant. I'd like to better understand the use cases and how this stuff works before committing to such an approach.

@nat-n nat-n added the enhancement New feature or request label May 18, 2022
@johnraz
Copy link

johnraz commented Jun 15, 2022

I worked around this issue by using cmd instead of shell and wrapping up things in bash -c.

eg:

  [tool.poe.tasks.interactive_command]
  cmd = "bash -c interactive-command"

@gangofnuns
Copy link
Author

gangofnuns commented Jun 15, 2022 via email

@dbohdan
Copy link

dbohdan commented Sep 30, 2023

You can also use an expression task and subprocess.

[tool.poe.tasks.interactive]
# Do not raise an exception if the command fails,
# just pass on its exit code.
expr = '''
  sys.exit(subprocess.run(
      ["vim", "pyproject.toml"]
  ).returncode)
'''
imports = ["subprocess", "sys"]

@jduprey
Copy link

jduprey commented Nov 15, 2023

I had the same issue - shell= a shell script that ran aws s3 sync in dryrun then asks if you wish to proceed. It would break at the "read -p" of the script.

@johnraz 's solution to:

  [tool.poe.tasks.interactive_command]
  cmd = "bash -c interactive-command"

Worked.

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

6 participants