rye icon indicating copy to clipboard operation
rye copied to clipboard

`IO error: not a terminal` in GitHub Actions from `rye publish`

Open jamesbraza opened this issue 1 year ago • 12 comments

Steps to Reproduce

I have a GitHub Action that looks like so with Python 3.12.4:

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: eifinger/setup-rye@v4
        with:
          enable-cache: true
      - run: rye sync --no-lock
      - run: rye build --sdist --wheel
      - run: rye publish --token ${{ secrets.PYPI_API_TOKEN }}

When I run it, the rye publish step fails with error: IO error: not a terminal

Expected Result

I expected this publish job to work

Actual Result

The below error during rye publish:

Run rye publish --token ***
  rye publish --token ***
  shell: /usr/bin/bash -e {0}
  env:
    RYE_HOME: /opt/hostedtoolcache/setup-rye-2024-03-04/0.37.0/x86_64

error: IO error: not a terminal

Caused by:
    not a terminal

Error: Process completed with exit code 1.

https://github.com/astral-sh/rye/issues/246 seems to have the same error

Version Info

0.37.0 via https://github.com/eifinger/setup-rye

Stacktrace

No response

jamesbraza avatar Jul 22 '24 01:07 jamesbraza

Also cc @eifinger if he has seen this before

jamesbraza avatar Jul 22 '24 02:07 jamesbraza

Also cc @eifinger if he has seen this before

I have not seen this before. I usually use pypi-publish to publish to PyPi.

Can you replace my action with

run: curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash

To make sure the bug is with rye itself instead of eifinger/setup-rye?

eifinger avatar Jul 22 '24 07:07 eifinger

Okay actually I am having a tough time getting the manual install to work. The URL you shared gives a "301 Moved Permanently" error. I am now using:

    steps:
      - uses: actions/checkout@v4
      - run: |
          curl -sSf https://rye.astral.sh/get | RYE_INSTALL_OPTION="--yes" bash
          echo "$HOME/.rye/env" >> $GITHUB_PATH
      - run: rye sync --no-lock

But this still gives line 1: rye: command not found in the last run step. Do you know what I am doing wrong here?

jamesbraza avatar Jul 22 '24 19:07 jamesbraza

Not sure what's going on but it does look like you're being prompted. I doubt it's a bug in the Action.

charliermarsh avatar Jul 22 '24 19:07 charliermarsh

Not clear if twine is prompting you or Rye.

charliermarsh avatar Jul 22 '24 19:07 charliermarsh

Okay gotchu. Can you give any tips on how to discern if twine or Rye is prompting? Sorry I am just not sure how to take the root causing further here without your or @eifinger 's help as I don't know the internals

jamesbraza avatar Jul 22 '24 19:07 jamesbraza

No worries. If you run that sequence of commands locally with (1) an invalid token, and then (2) a valid token, what do you see?

charliermarsh avatar Jul 22 '24 19:07 charliermarsh

Okay, I have figured it out thanks to @charliermarsh's comment:

Not sure what's going on but it does look like you're being prompted.

The fix was specifying --yes to rye publish, to not have Rye prompt the user:

---      - run: rye publish --token ${{ secrets.PYPI_API_TOKEN }}
+++      - run: rye publish --token ${{ secrets.PYPI_API_TOKEN }} --yes

So to follow up, there was nothing wrong with setup-rye (cc @eifinger).

Now for a fix here, is there some way we can make this failure "nicer" towards humans? E.g. is there some way Rye can check if an input terminal is available before prompting then crashing with the current obscure error?

jamesbraza avatar Jul 23 '24 00:07 jamesbraza

Yeah can definitely be improved... Do you have any idea what the prompt was?

charliermarsh avatar Jul 23 '24 00:07 charliermarsh

Yeah the prompt was asking for a password encryption:

? Encrypt with passphrase (optional) ›

I guess it's worth pointing out that we aren't using a password, so maybe this prompt can be eliminated entirely

jamesbraza avatar Jul 23 '24 00:07 jamesbraza

I think it's still relevant because Rye is trying to encrypt whatever plaintext secret (password or token) you provide on disk. But we should either skip that step when you're not attached to a TTY or provide a better error message with a mention of --yes.

charliermarsh avatar Jul 23 '24 00:07 charliermarsh

I follow and that sounds great. Maybe also adjust the prompt from "Encrypt with passphrase" to say what being encrypted, so perhaps "Encrypt token with passphrase" to be more explicit

jamesbraza avatar Jul 23 '24 00:07 jamesbraza